ha-average icon indicating copy to clipboard operation
ha-average copied to clipboard

Support for counting average of long-term statistics sensor

Open kheikola opened this issue 1 year ago • 1 comments

Checklist

  • [X] I have filled out the template to the best of my ability.
  • [X] This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • [X] This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I'm trying to calculate monthly average of electricity spot price, which changes every hour. With following arguments it should work nicely: start: "{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}" end: "{{ now() }}" However, my recorder purge_keep_days is the default 10 days, and increasing that to 31 days would explode the database size. So it means the sensor which I'm calculating monthly average, only contains last 10 days worth of data. As my goal is to calculate average for full month, result starts to fail after day 11.

Describe the solution you'd like

As the sensor from which I'm counting the average has state_class: measurement, it has the long-term statistics. So I can see the sensor history for the full month. However it seems that average does not count for long-term history measurements. So can it be enhanced to calculate average also using long-term statistics data?

Describe alternatives you've considered

Alternative obviously is extending recorder purge_keep_days to 31, but despite recorder exclusions and purge automation for largest sensors, it would still increase my recorder db size dramatically.

Additional context

image

kheikola avatar Feb 14 '24 19:02 kheikola

Have a simliar need. Want to calculate an averagy YtD (Year-to-date). So... will shortly run out of recorder data when not using histroy statistics.

vistalba avatar Apr 21 '24 12:04 vistalba