I have a sensor from my water heater that provides a rolling 90 day total value. For the first 90 days, I could just use the ‘Change’ state on that sensor value to get my daily energy usage.
However, on day 91, the total value would remain close to flat or some days would show negative.
How can I properly track the daily usage given that the only value provided is a 90day total?
My thought was to take the current number and add the value from 90 days ago to get the proper total lifetime usage, but I do not know how to properly query that. Is there a standard way with statistics or long-term statistics to do get the daily value without doing something crazy?
For a visual representation, see the issue logged, here:
Example:
Day 1 value = 5
Day 90 value = 100
Day 91 value = 98
On Day 91, the value should be 3 because Day 1 is no longer included in the total. With ‘change’ I’m seeing -2 as expected given the values.
There’s no way to do this without knowing the value 90 days ago. You could do this with an sql sensor to query what that value was. Unless you keep 90 days of history (which you probably shouldn’t; the default is 10), you’d have to look up the value in the long term statistics table instead of the states table.
I’m no SQL query expert so maybe someone else can come along and help you with that query if you can’t figure it out.
The only other method I can think of is to create a trigger-based template sensor that stores the rolling 90 days’ worth of values in its attributes.
There isn’t anything native inside HA, you’ll have to use something external depending on what database you are using. If you’re on the native sqlite database there is an SQLiteWeb add-on, if you’re using mariaDB there is myPHPAdmin add-on. If you’re not running HAOS and can’t use add-ons, both those are available as docker containers also. There are other options out there as well.