Tracking multiple states with history_stats platform

Hi all!

I’m using the history_stats platform to track how long my air conditioner is running each day. I’ve always had it configured to add the time it sees my ac sensor in ‘Cooling’ mode. Now that it’s cold, the ‘Cooling’ mode has turned to ‘Heating’ and my sensor is no longer useful. I would like to make the history_stats sensor count the amount of time my ac is Heating OR Cooling. My current config is below:

sensors.yaml:

- platform: history_stats
  name: ac_runtime_today
  entity_id: sensor.thermostat_state
  state: 'Cooling'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

FWIW, I’ve tried adding an additional “state” statement, but that causes the sensor to error out. I’ve pondered creating a history_stats sensor for heating and cooling mode separately and then adding them together, but that doesn’t seem to work out well. Any advice is appreciated!

Did you ever managed to get this right? I also require to track multiple states as one measurement

No, but I had a thought. We could probably make a sensor for each state, then make a template sensor and simply add the values together with a jinja.

Sounds plausible ,hmmm where are the jinja ninjas… guess i need to start deep diving into jinja

{{ float(states('sensor.ac_runtime_today')) + float(states('sensor.ac_runtime_today_heat')) }}

Sorry for reviving an old thread, but I thought it better than starting a new one when this is the top result on Google.

You can track multiple states in a single history_stat sensor now. The documentation says state needs to be a list | string. Take a look at the test to see how to use it

"platform": "history_stats",
"entity_id": "binary_sensor.test_id",
"state": ["on", "true"], 
"start": "{{ now().replace(hour=0)"".replace(minute=0).replace(second=0) }}",
"duration": "02:00",
"name": "Test",
7 Likes