Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphs for sensors #30

Open
abroooo opened this issue Nov 18, 2022 · 10 comments
Open

Graphs for sensors #30

abroooo opened this issue Nov 18, 2022 · 10 comments

Comments

@abroooo
Copy link
Contributor

abroooo commented Nov 18, 2022

Is your feature request related to a problem? Please describe.
Sensors currently only show numeric values.

Describe the solution you'd like
By pressing the sensor menu item it could show a graph over the last x min/hours

Describe alternatives you've considered
Instead of drawing it could be a solution to receive a png (from HA) and display that. I wouldn't prefer showing pngs because it would require external configuration and I'm not sure it's possible with our device.

Additional context
I investigated a bit and it;s it pretty doable to show a graph. The tricky part is getting the data to show. Natively esphome only supports collecting values over a period of time and show them in a graph. But I would like to see a graph for a sensor even if I just turned on the remote (or return it from deep sleep). Maybe this could be resolved by having ha send an array of values on demand but it would mean external configuration. AFAIK ha doesn't support that natively.

@landonr
Copy link
Owner

landonr commented Nov 18, 2022

i tried the esphome png library and its super slow. I don't know if theres any alternatives for jpg or bmp esphome/esphome#3255

you can get history from REST so we can try that. Decoding the REST might make the device lag for a second but it could work
https://developers.home-assistant.io/docs/api/rest/

we might need to make our own graph by drawing points because the esphome graph just takes in a sensor

@abroooo
Copy link
Contributor Author

abroooo commented Nov 19, 2022

Oh the ha rest api, nice idea - havent thought of that to be honest 👍
I don't think we need to implement our own graph. esphome::display::DisplayBuffer::graph() takes a pointer to an esphome::graph::Graph object. We can build this object ourselves.

[edit] fix typo

@abroooo
Copy link
Contributor Author

abroooo commented Nov 22, 2022

I played a bit with esphome's httprequest (only via yaml not in code) but so far I couldn't get it to work with ha. It seems it doesn't like Bearer Authentication. I haven't looked into the esphome code though.

This works fine: curl -X GET -H "Authorization: Bearer <token>" -H "Content-Type: application/json" "http://<ip>:8123/api/history/period/2022-11-22T10:00:00+00:00?filter_entity_id=sensor.my_sensor"

but this fails with 401 - not authorized:

       - http_request.get:
           url: 'http://<ip>:8123/api/history/period/2022-11-22T10:00:00+00:00?filter_entity_id=sensor.my_sensor'
           headers:
             Authorization: 'Bearer <token>'
             Content-Type: application/json
           verify_ssl: false
           on_response:
             then:
               - logger.log:
                   format: 'Response status: %d'
                   args:
                    - status_code

I'll play some more and when I get it to work I'm really curious to see the performance parsing a that json 😆

@landonr
Copy link
Owner

landonr commented Nov 22, 2022

are you using a long lived access token? https://developers.home-assistant.io/docs/auth_api/#making-authenticated-requests

@abroooo
Copy link
Contributor Author

abroooo commented Nov 22, 2022

Yes I am

@abroooo
Copy link
Contributor Author

abroooo commented Nov 23, 2022

After poking through the esphome code to no avail I found the error - it was the token 🤦‍♂️ I somehow missed a character. After fixing the token it works fine....

@landonr
Copy link
Owner

landonr commented Nov 24, 2022

nice! pics

@abroooo
Copy link
Contributor Author

abroooo commented Nov 25, 2022

yeah I'm pretty much at the beginning so there aren't any pics yet - sorry 😞

I think I'll approach it like this:

  • parse json into array
  • build esphome::graph::HistoryData object
  • build esphome::graph::GraphTrace object
  • build esphome::graph::Graph object
  • show esphome::graph::Graph obect via esphome::display::DisplayBuffer:Graph

@landonr
Copy link
Owner

landonr commented Jan 24, 2023

this is really interesting
esphome/esphome#3255 (comment)
this person loads a graph as a png created from https://weewx.com/
I think loading the json from history and drawing the graph on the device is the right move, but this is an interesting approach/hack

@abroooo
Copy link
Contributor Author

abroooo commented Jan 26, 2023

oh yeah that's nice indeed. I agree, pulling the data from HA and visualizing it on device is the way to go.
btw. it will take me some more time as life keeps me pretty busy atm 😐

@abroooo abroooo mentioned this issue Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants