Platform: history_stats wrong times

I set up an operating hours counter with “platform: history_stats”. It doesn’t work reliably. There are always huge jumps in time in the statistics.


  - platform: history_stats
    unique_id: 75fb97599f11408aaf2ce50476533e1f
    name: AbsRuntime Chlorinator
    entity_id: switch.bre_a1t_114
    state: "on"
    type: time
    start: 2024-07-19 10:40:00
    end: "{{ now() }}"

This is fatal for an operating hour counter.
Why do these time jumps occur?
Can the statistics be corrected?

The drops are normal, expected behavior for this integration. History Stats is based on the values stored in the Recorder which by default stores 10 days worth of data. As the data is purged, the value of your time type History stats will drop by however many hours were from the purged time period.

The jump is a bit unusual. I would only expect to see something like that if you altered the sensor configuration.

Many thanks for the quick response.
Now I understand correctly, “platform: history_stats” is not suitable for my purpose “operating hours counter over longer periods of time (months, years)”
How can you implement something like this in HA?

If you create a sensor for hours today then you could use a utility meter to sum it all up for an all time total. Make sure to set Periodically resetting to true. you can also use it to create year/month,… totals.

In this context I have another question.
I have a history stats sensor with many previous daily run times.
Like this:


Can you create a sensor (template?) in HA that sums up all daily running times from a certain start time?

I think you could use utility meter for that too, assuming it accepts the source entity type. It was designed for energy, gas, water, etc. but the principle is the same.