Integral of Binary Sensor

Hi all

I’m looking to understand how long per day my HVAC is heating the house.

I have a binary sensor that is reported out of the thermostat that turns ON for heating, and OFF when idle:

binary_sensor.thermostat_1_state

It doesn’t look like binary sensors can be used within the “integral” helper though. Any pointers on how I can understand the total “ON” time of this sensor?

sensor:
  - platform: history_stats
    name: Heating Hours Today
    entity_id: binary_sensor.heating_on
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

I also have a trigger-based template sensor that mirrors the end-of-day duration:

template:
  - trigger:
      - platform: time
        at: "23:59:00"

    sensor:
      - name: "Heating daily hours"
        unique_id: 0237e0dd-58ca-4a6f-99b0-d1275fb93f1b
        unit_of_measurement: 'hours'
        icon: mdi:timeline_clock
        state: "{{ states('sensor.heating_hours_today')|float(0) }}"

…and I dump that into Influx to give a historical record (last 90 days, apols for US date format):

Outside temp in °C in green on the LH axis, daily heating hours in red on the RH axis.