Combine (or total) multiple history_stats sensors into one?

With a lot of help from the forums, i finally got my history_stats working to track the time the AC units are heating and/or cooling. the issue is that I have two of them (upstairs and downstairs). i’ve created history_stats for each of them as below:

  - platform: history_stats
    name: Thermostat Heating Today Upstairs
    entity_id: sensor.hvac_activity_upstairs
    state: 'heating'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

  - platform: history_stats
    name: Thermostat Cooling Today Upstairs
    entity_id: sensor.hvac_activity_upstairs
    state: 'cooling'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

  - platform: history_stats
    name: Thermostat Heating Today Downstairs
    entity_id: sensor.hvac_activity_downstairs
    state: 'heating'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

  - platform: history_stats
    name: Thermostat Cooling Today Downstairs
    entity_id: sensor.hvac_activity_downstairs
    state: 'cooling'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

But now i would like to have another history_stat this is a sum of both of the cooling and one for both the heating so i can track the total time across both units. i thought about adding creating another sensor that monitors both units, but that would not be correct when both units are on t the same time. Any way to sum these?

You could create a template binary sensor that tracks both cooling and heating. Use that in a history stats sensor.

i hadn’t thought about combining heating and cooling into one sensor. My idea was more about total heating time across both units, so the sum of upstairs and downstairs time heating and then another for total cooling time across both.

your idea is definitely doable since each AC unit can only be at one mode at any time (i,.e. it’s either cooling or heating, but not both). i will definitely try total on time, but would like to see if there is a way to split that into total cooling and total heating. As always, thanks for the help!

Would you count both in heating mode as double the time?

If so you would need to create template sensors that add the history stats sensors.

1 Like

i guess the history_stats are entities after all…

{{ states('sensor.thermostat_heating_today_downstairs') | float + states('sensor.thermostat_heating_today_upstairs') | float }}

does exactly what i need…

1 Like