WTH Can't I get to long-term statistics from templates?

Long-term statistics for multiple entities are being stored, yet there is no method to access them from templates. Being able to access from templates would allow one setting up sensors for comparisons, differences, etc. or access them from the UI (for example in combination with HTML Jinja2 Template card).

I think there are few dimensions to this:

  1. we could have a long term statistics graph card, that takes a formula as an input, and calculates the result when loaded (this would be the first and easiest step I presume)
  2. we could have a scheduled service that would calculate the history and long term statistics for a template sensor after the template has been updated when there is available CPU time. This would also help with debugging template sensors.

My WTH that should probably be merged.

Ideally there would be:

  • less of a distinction between history data and long term statistics data.
  • a long term statistics explorer view, or better yet merge that into the history view and use the date tangle to seamlessly select from history or long term statistics
  • the ability to write smart automations that could take action if unusual or out-of-range events occur. For example if my energy usage from day to day changes by more then 10% take some action.

Totally agree with ehendrix, we have

states(entity_id)

, I would expect to have

history_states(entity_id, date)

. This would avoid intermediate sql sensors.

1 Like

Another duh, here. I’m perplexed.

Templates aren’t async, so making function calls like this aren’t possible. Our best bet at getting this into a template would be a responding service call.

2 Likes