home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.88k stars 30.96k forks source link

malfunction of Statistics integration of Home Assistant #130341

Open robert-sebl opened 1 week ago

robert-sebl commented 1 week ago

The problem

when having upgraded to core ver. 2024.11.1, Supervisor 2024.11.2 "Statistics" integration started to misbehave. I use "total"/"sum" State Characterisitc for calculating energy consumption over past 24 hours of my heat pump. Fot that I use "Max age" set to 24:00:00. Before the upgrade results were trustable. Now the numbers generated by Statistics seem to grow with time not as cumulation of values of changed states of the sensor I use as the input entity. It looks as if the output value increment were triggered not by input entity state_change but by every state report of the respective input entity. Please, please help. thank you below is my current SW status. Core 2024.11.1 Supervisor 2024.11.2 Operating System 13.2 Frontend 20241106.2

What version of Home Assistant Core has the issue?

2024.11.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Statistics

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

unfug-at-github commented 14 hours ago

You are right that the statistics functions are now using every reported value no matter whether it changes or not.

I guess you should be using average_step instead. Alternatively you can also use the Riemann integral component.

Using the sum doesn't seem to be the right function for that purpose. In principle you can also use the sum if you want, but then you would have to know how often the values were actually reported and calculate based on that. That would be a rather error-prone solution when you think about issues due to error scenarios / lost events etc.