My starting point is a (total_increasing) counter entity, which counts the heating cycles of my heat pump, and so is monotonically increasing. The counter increases by between 0 to 12 a day.
I now want an entity that shows be by how much the counter has increased over the past 24h. That sounds simple, but the devil seems to be in the detail.
My immediate idea was to use the statistics integration and I tried change
, distance_absolute
, and max
minus min
. But the statistics integration does not appear to be suited for this as it seems to take a sample pool of all the saved states for the 24h period. And therefore, if the counter increased by only one over the past 24h, and only one state gets saved, the statistics integration will report the value of that one state as both min and max, and hence the result of eg a change
or distance_absolute
statistics sensor is zero.
And as a result, much of the time (but not all the time! I guess because sometimes a state gets saved while the counter has not increased) an entity based on the statistics integration would report a value that is off by one.
(See also this thread, where that was effectively confirmed to me)
But now I am a bit at a loss at how to solve this using built-in functionality. Statistics is not an option for the above reason. History Stats does not offer functionality that works for this. My suspicion is that I am overlooking some simple approach, and would appreciate any help / suggestions.
(In Openhab, from where I am current migrating my smart home to HA, this is a one-liner in DSL or Javascript rules. I have now also managed to build what I want using pyscript and feeding that into an input_number, by using SQL alchemy to query the short_term_statistics database. But that feels like using a sledgehammer to crack a nut.)