Runtime sensor increases for no reason

Hello,

I use a simple script to calculate how long my underfloor heating runs daily, weekly and annually in order to calculate the costs incurred.

### Laufzeiterfassung Fussbodenheizung Jährlich
  - platform: history_stats
    name: Heizung Esszimmer Jährliche Laufzeit
    entity_id: sensor.fussbodenheizung_zustand
    state: "heating"
    type: time
    start: "{{ now().replace(month=1, day=1, hour=0, minute=0, second=0) }}"
    end: "{{ now().replace(year=(now().year + 1), month=1, day=1, hour=0, minute=0, second=0) }}"
    unique_id: fbh_esszimmer_laufzeit_jaehrlich

The script works without any problems.
But I have a day on which the total runtime increases by over 5000 hours within one minute for no apparent reason.

This of course destroys all my statistics.

The same sensor with the daily or monthly evaluation does not show this increase.

Does anyone have any idea where this is coming from?
Is there any way I can correct this?

Thank you

What is your recorder purge keep days setting?

Also these are not scripts. They are sensors.

  auto_purge: true
  purge_keep_days: 30

Then you can’t have this:

As you do not have a year’s worth of data in your recorder for the history stats sensor to use.

https://www.home-assistant.io/integrations/history_stats/#duration

Ok, thanks for the tip.
I’ll take a look at that.

But do you think that’s the cause of the problem? If it was missing data, the value should be too low and not jump up by thousands of hours?