History stats - unusual increase in time


I use a history stats to track the time, for how long it has been running. All was working fine, until at some point, the time just boosted for 400000 hours.

My code for stats:

- platform: history_stats
  name: Fridge Working Hours
  entity_id: input_boolean.fridge_running
  state: "on"
  type: time
  #start: "{{ now().replace(hour=19, minute=0, second=0) }}"
  start: "{{ 0 }}"
  end: "{{ now() }}"

Jump for 400000 hours.

Normal operation afterwards (as it was before).

Any ideas, what could be wrong?

Would say you have a dubious entry in stats records. You can fix this in Dev Tools - Statistics by editing the offending entry on the entity.

In Dev Tools not all sensors can be edited, so I solved the issue installing SQLite Web add-in and changing 3 tables, states, statistics and statistics_short_term.

Still not sure why this issue happened.

1 Like

Did you ever find the cause of this? I have a history stat based on my HVAC runtime that is doing something similar.

Hello @tusi,
I have the same problem as you do.
I am using HA’s default SQlite DB and after some HA core upgrade and restart my long-term HVAC stat changed from 29 to 473066 (heating TOTAL ON in hrs).

Basically my graph now looks exactly the same as yours in your post here: After rebooting Home Assistant, history gets corrupted - #7 by tusi

How did you change the data, how did you know how? I started SQLite Web add-in to browse the data but I do not know what rows to update/insert or delete. Where did you learn the data structure please?

I have the same problem. Is there anybody who solved the cause of the problem?

There are several issues raised against history_stats, including this, but there doesn’t appear to be anyone available to analyse and fix.