Strange sensor increments history_stats after midnight

To calculate how long per day a switch remains on, I’m using this history_stats sensor for a while without problem.

sensor:
  - platform: history_stats
    name: Termo ON today
    entity_id: switch.shelly1a
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

Today I have a strange behavior: at midnight (my time zone is CET, UTC+01:00) the sensor reset but continued to increment even if the switch was off

These are the values from history

switch.shelly1a,on,2024-12-16T22:05:03.279Z
switch.shelly1a,off,2024-12-16T23:00:00.354Z
switch.shelly1a,on,2024-12-17T05:24:17.183Z

sensor.termo_on_today,5.66,2024-12-16T22:59:03.551Z
sensor.termo_on_today,0.0,2024-12-16T23:00:00.493Z
sensor.termo_on_today,0.02,2024-12-16T23:01:00.551Z
sensor.termo_on_today,0.03,2024-12-16T23:02:00.552Z
sensor.termo_on_today,0.05,2024-12-16T23:03:00.551Z

What could have happened?