Beginner - Sensor Timer for heating on

Hi,
I am new to Home Assistant but so far think it is a brilliant tool with great community support.

I have an Evohome heating system that I have managed to integrate without too much problems.

However, I now want to get a sensor that shows the total time that the heating has been on.

So far I am attempting to do this through grouping all the individual room heating controls in to one group.

I have then tried to use a history stats template to see how long the overall has been on.

template:
  - binary_sensor:
      - name: LivingRoom
        state: >
          {% if state_attr('climate.living_room','current_temperature')<state_attr('climate.living_room','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: Bathroom
        state: >
          {% if state_attr('climate.Bathroom','current_temperature')<state_attr('climate.Bathroom','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: Kitchen
        state: >
          {% if state_attr('climate.Kitchen','current_temperature')<state_attr('climate.Kitchen','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: MainBedroom
        state: >
          {% if state_attr('climate.lorcan','current_temperature')<state_attr('climate.lorcan','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: Oisin
        state: >
          {% if state_attr('climate.oisin','current_temperature')<state_attr('climate.oisin','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: Fiadh
        state: >
          {% if state_attr('climate.fiadh','current_temperature')<state_attr('climate.fiadh','temperature') %}
            On
          {% else %}
            Off
          {% endif %}
      - name: Office
        state: >
          {% if state_attr('climate.guest_bedroo','current_temperature')<state_attr('climate.guest_bedroo','temperature') %}
            On
          {% else %}
            Off
          {% endif %} 

sensor:
  - platform: history_stats
    name: Heating Time
    entity_id: binary_sensor.heatingonoff
    state: "On"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

I know it is probably something very stupid that I am doing but spent the last few days trying to figure out how to get this working.

The state of a binary sensor is either “on” or “off”… not “On” or “Off”. As it is, your History stats state value will never be true, so the sensor will alway return 0 hours.

sensor:
  - platform: history_stats
    name: Heating Time
    entity_id: binary_sensor.heatingonoff
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

FWIW, in these cases you don’t need to specify an output for your binary sensors since you :

- name: Office
  state: >
    {{ state_attr('climate.guest_bedroo','current_temperature') 
     < state_attr('climate.guest_bedroo','temperature') }}
  availability: >
    {{ state_attr('climate.guest_bedroo','temperature') is not none }}

If available, it would be better to track the hvac_action attribute of your themostat or add some other condition to your templates beyond just the comparison of temperatures. There can be cases where the room’s temperature is below the temperature set point, but you will want the heating to be off; for example the window is open or no one is home.

Thanks so much, that is working perfectly now.

I knew it would be me doing something stupid :slight_smile: