I’m trying to create a sensor to log the number of hours my furnace oir AC runs each day. I found some resources and tried following the instructions, but alas, they don’t work.
Regarind the code below, my template sensors (hvac_idle, hvac_cooling, and hvac_heating) all work. I use them in Grafana to visualize when the furnace oir AC are running. Below that I have two dfferent sensors each for the heat and cooling history stats, each are configured differently (just attemts to get it to work).
The sensors are avilable to add to the dashboard but they always remain at “0.0”. I feel like I am missing something easy. Any ideas?
# State sensor - 1 when idle, 0 when "heating" or "cooling"
- platform: template
sensors:
hvac_idle:
value_template: >
{% if state_attr('climate.hallway', 'hvac_action') == "idle" %}
1
{% else %}
0
{% endif %}
# State sensor - 1 when cooling, 0 when "idle" or "heating"
- platform: template
sensors:
hvac_cooling:
value_template: >
{% if state_attr('climate.hallway', 'hvac_action') == "cooling" %}
1
{% else %}
0
{% endif %}
# State sensor - 1 when heating, 0 when "idle" or "cooling"
- platform: template
sensors:
hvac_heating:
value_template: >
{% if state_attr('climate.hallway', 'hvac_action') == "heating" %}
1
{% else %}
0
{% endif %}
# ************ Attempt using "climate.hallway" state ************
# Method A - Record amount of time the "climate.hallway" state is "cooling"
- platform: history_stats
name: Air conditioning run time A
entity_id: climate.hallway
state: "cooling"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
# Method A - Record amount of time the "climate.hallway" state is "heating"
- platform: history_stats
name: Heat run time A
entity_id: climate.hallway
state: "heating"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
# ************ Attempt using "hvac_xxxxxx" state ************
# Method B - Record amount of time the "hvac_cooling" state is "1"
- platform: history_stats
name: Air conditioning run time B
entity_id: hvac_cooling
state: "1"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
# Method B - Record amount of time the "hvac_heating" state is "1"
- platform: history_stats
name: Heat run time B
entity_id: hvac_heating
state: "1"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"