I have two history_stats entities which track binary sensors; one for when my boiler burner is on, and one for when my air conditioner is running.
I haven’t used either one while I was away from home, but today when I started them these values were 11.7 hours and 8.5 hours, respectively. They have been counting up correctly since then, but they should have started at zero, since they were off for a couple of weeks until today.
I’m running HA OS 8.2 and HA 2022.7.6. This may have started when I updated from 2022.6, but as I said I only just started using these so I can’t really say for sure it’s related.
Today these two history_stats values are back to normal. So far, for me it’s been a one-time thing; the value was zero for 8 days, then when it started accumulating again it started with a seemingly random value rather than starting with zero. I say random because this was not a previous value. In both cases the values were out of what would be a normal range.
In case anyone else has a similar problem and finds this thread, as I recently did, a quick note about my issue.
I experienced the exact same issue where my history stats sensors reset to 0 at midnight but then jumped to a non-zero number and started to increment from that value. The issue for me was that the entities the history stats sensors were keyed off of had been excluded from my recorder. Ensuring that those entities were part of the recorder solved the issue. My guess is that without state history for those entities, as soon as the state changed and the respective history stats sensors activated, those sensors assumed that the entities had been active since the last reset.
It took me a little trial and error to sort this out, so hopefully if anyone else runs across the issue, this will save them some time.
Good catch! I think you might be on to something with the Recorder exclusion. I certainly exclude a lot.
And, for the record, I’ve seen this a few times again since I posted that the problem was gone. I suspect one reason is that I rarely restart HA any more. Often just once a month, after the point releases have settled down, when I do an update. I imagine I’ll see the problem again when I get some time to do more tinkering, which will lead to more restarts.
If you’re new to this, I think the problem is unlikely to be with the device having been excluded from the recorder. You have to specifically modify the configuration yaml files to exclude device states from being recorded in the homeassistant database. See this link for more information. Unless you’ve done that, I would expect that all your devices are being logged.
Nevertheless, to quickly see if the entity you are using for history stats is being logged in the recorder, just open it up and see if any history is shown. If there is history, I think it’s safe to say it hasn’t been excluded. If there is no history, it has been excluded. Actually confirming what is in your database would require opening up that database, which depends on what database you’re using and where it’s stored.