Hi, I have my WaterFurnace HVAC system connected to my HA, and one sensor shows what mode the system is in (standby, heating, cooling, fan only, etc). I’d like to know what percentage of time the sensor spends in each mode, and be able to graph that. I think template is the answer, but I can’t quite figure it out. Thanks.
you can use history-stats for this.
So, for example, this tells me how long my heating has been on today:
sensor:
- platform: history_stats
name: Heating today
entity_id: binary_sensor.heating_reported_action
state: "on"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
I think you could try something like this:
sensor:
- platform: history_stats
name: Heating today
entity_id: climate.hvac-name # put your climate.entity here
state: "heating" # or standby, or cooling, or fan only etc etc (from your example)
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
I have a water heater recirc pump and I basically do the same thing showing the percentage of time the pump ran yesterday.
there may be other ways to do it but my chosen method is that I create two sensors - one to show how long the pump ran yesterday (how long it was in the ‘on’ state) and the other to calculate the percentage.
sensor:
- platform: history_stats
name: Recirc Pump Run Time Yesterday
entity_id: switch.water_heater_recirc_pump
state: "on"
type: time
end: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
duration:
hours: 24
- platform: template
sensors:
recirc_pump_run_time_percent:
friendly_name: Recirc Pump Daily Run Time Percentage
value_template: "{{ (((states('sensor.recirc_pump_run_time_yesterday') | float / 24.0) ) * 100) | round(2) }}"
unit_of_measurement: '%'
This is what I did. It worked great, thanks!
Thank you for this!
I’ve just added it to for my weather station’s wind vane.
I’m hoping to get nice graphs over the year with percentage of each day the wind has blown in a direction. Right now it’s nothing as I just restarted to add it in.
Why not just use the ratio
type History Stats sensor?
IDK… Because I’ve not looked into it and didn’t know it was a thing…?..
But I will now.