WTH can't I access the stored statistics data in my automations and templates?

To the best of my knowledge, the statistics data that home assistant is collecting as statistics (for entities that have a state_class can’t be used in automation/templates/etc.

If I want to do a comparison (value increasing/decreasing, change from an hour ago, yesterday’s high/low/average) I either need to create new entities and store additional duplicated information in the database, or use some external SQL.

It would be handy if some of that data was available as entity attributes, or at least there was a way to query it from templates/automations.

Note that from apex-graph-card I use the following to directly call the websocket command for statistics:

I agree that something less quirky would be better, especially in templates (where connecting to websockets is a no-go).

1 Like

Thanks I’ll look at your solution – looks like it is client side JavaScript? That will be useful for doing more visual stuff with statistics.

However as you point out, not a good way to do things inside of automations/scripts/templates.

Note that it works because apexcharts-card passes the hass object to data generators. Depending on the API a frontend card gives you, you may not have enough access to play with.

Was also looking for this.
I want to send out a notification if the precious max value of a sensor was exceeded, preferably without having to create new entities.