Binary_sensor active ON duration: history_stats issue or misconfig?

Hello All,

I’m trying to get active (heating) time for my water-boiler. I defined a binary_sensor which is ON when water-boiler power consumption is above 10W, which works perfectly fine: today I get 110mn 3sec looking at historical data of this sensor.

Now I try to calculate the total duration with a template sensor, and I get 1.48 hours which is about 88,8 minutes. I should have 1.83 hours for 110 minutes.

I’ve read the doc and lot’s of related topics but can’t find what I’m doing wrong.
Thanks for your help.

Here is my code and informations.

Binary sensor definition

binary_sensor:
  - platform: template
    sensors:
      ecs_en_chauffe:
        unique_id: ecs_en_chauffe
        value_template: >
          {{ states('sensor.powr3_ecs_energy_power')|float(0) >= 10 }}

Template sensor definition

sensor:
- platform: history_stats
  name: "ECS Temps de chauffe Quotidien"
  entity_id: binary_sensor.ecs_en_chauffe
  state: "on"
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

Binary sensor activation time screenshot

Developper tool view

I didn’t check this myself, but what happens when you change it into this:

sensor:
- platform: history_stats
  name: "ECS Temps de chauffe Quotidien"
  entity_id: binary_sensor.ecs_en_chauffe
  state: "on"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"

This is following the History Stats docs.

I do the update and get the same result.

I add a new sensor, of type “count” to get how many time the water-boiler starts, which works well: I get 2 starts.

- platform: history_stats
  name: "ECS nombre activation chauffe Quotidien"
  entity_id: binary_sensor.ecs_en_chauffe
  state: "on"
  type: count
  start: '{{ now().replace(hour=0, minute=0, second=0) }}'
  end: '{{ now() }}'