History Stats resetting at midnight instead of time listed

Hello,

I running now the second time in trouble with the history_stats sensor.

The issue I was having was that the sensor wasn’t resetting exactly at 00:00. It was always a little bit off, starting the new day/week a few seconds in. So the frontend chart_type: bar can’t show the right value for the day/week because it captured the value between 00:00 and when it got reset.

Then I thought about resetting the history_stats before midnight, but the reset is still a bit off after midnight.

There is a old unsolved github issue:

example:

  - platform: history_stats
    name: Fitnessstudio Woche
    entity_id: binary_sensor.fitnessstudio_status
    state: "on"
    type: count
    start: "{{ today_at('00:00') - timedelta(days=now().weekday(), minutes=60) }}"
    end: "{{ now() }}"

Greeting