I’m starting using a history stat sensor to measure my gas consumption. I don’t have a ‘smart meter’ yet, so i thought I could measure the time that the flame of my central heating system is on. I’m aware this is not very accurate, but at least it give me a rough indication.
However, the history stat is acting strange. At some moments you can see the value increase as the flame is on, but sometimes there is a sudden jump in the value. I’m clueless that causes this.
I had a very similar problem (see link to it, below.)
I thought I’d proven that it only happens when the underlying binary sensor data had rolled off of the Recorder database after the purge_keep_days but that doesn’t seem to be your situation. I also can’t be sure when it started happening, since it’s fairly infrequent.
There is certainly something wrong with history_stats. My post didn’t get any response. I hope you have better luck with this one.
I just found out that it happens when I restart home assistant. I had already seen in the history of the binary sensor that it occured when there were 2 ‘off’ signals in a row. Then it occured to me that I might have restarted on these moments. And when I restarted again, it indeed happened again.
Seems like a bug waiting to be fixed.
Thanks, the more examples we can post here the closer we might get to understanding the problem.
I am sure restarting didn’t cause it the last time I saw it. I only restart HA about this time every month, when I do updates. My HA hardware is on a UPS and doesn’t get restarted in between updates even if there’s a power outage. The problem last occurred about 5-6 days ago, when HA had been running for about three weeks.
Of course that’s not to say restarting won’t make it happen again for me. I’ll be updating within the next few days and I’ll watch for this symptom.
I was also reminded (over on that other thread I linked to in post #2, above) that there’s an issue open on Github about this, too:
We probably should all update that thread, so our observations can be considered.
I’m not sure if it’s the same problem. In my case I see that restarting generates an ‘off’ signal and I suspect that the start time is uninitialized, because no ‘on’ signal has been seen yet. So a random time period is added to the sensor.
Thanks for raising that issue in Github again. It’s clear to me there is a bug somewhere.
I’m not so sure yours is a different problem from mine. In my case, at least the last time it happened, the start time was also uninitialized, because it had passed the purge_keep_days in Recorder.
Whether there is one cause or two, it results in a sudden and incorrect jump in the history_stats value, so it’s got to end up in the same place in the code somehow.
This happened to me again. This time it was right after updating the HA OS. Same as the OP. I updated the Github problem that @hneel linked, above, to add a screenshot of this.
For the input sensor, enter the daily history stats sensor (in the example above: sensor.boiler_daily_heating_on). Then … wait a few days.
So far, this has survived multiple restarts:
Boiler heating on was the old long-term history stats sensor which failed after restarts, although only once it had been non-zero for more than 10 days. Interestingly, the daily stats are still prone to changing values after a restart, but only by a small degree so it barely affects the total.
Hello and sorry for digging this old thread but I want to accomplish exactly what you created - calculate how long heater was on during a day, week and month and have the results displayed in a calendar format.