I want to create a sensor that counts the overall time my generic_thermostat spends in heating mode. I found the hvac_action attribute, which changes between off, idle and heating. I would like to count the time it spends in heating, because I want to create an utility meter out of this.
You probably want to use the history_stats integration to do this, I do something very similar to monitor how long my boiler relay (binary_sensor.13_129802_active) is on:
However I think you’ll need to create a template sensor first, to represent your thermostat’s hvac_action value as a binary sensor, and then the history stats sensor will refer to this.
It resets every day (that’s what the template in the start defines). I have a statistics graph on my dashboard that shows the last 7 days’ values:
chart_type: bar
period: day
type: statistics-graph
entities:
- sensor.boiler_ch_time
stat_types:
- max
days_to_show: 7
hide_legend: true
title: CH Time
I think the utility meter helper might be able to handle values that reset, but a utility meter is your end goal, there’s probably a more efficient way to achieve this than having lots of extra intermediate entities, but it’s beyond my knowledge I’m afraid.