Step 1: Create a template sensor that will monitor the state of a climate component
Example for generic thermostat component that drives a generic switch:
- platform: template
sensors:
hvac_status:
friendly_name: "AC status"
value_template: >-
{%- if is_state('climate.central_ac', 'off') %}
off
{% elif is_state('climate.central_ac', 'cool') and is_state('switch.hvac_cool_switch', 'off') %}
idle
{% else %}
on
{%- endif %}
icon_template: >-
{% if is_state('sensor.hvac_status',"idle") %}
mdi:power-on
{% elif is_state('sensor.hvac_status',"on") %}
mdi:snowflake
{% else %}
mdi:octagon
{% endif %}
Example for a Zwave thermostat that reports state via hvac_action
attribute of a climate entity
sensor:
- platform: template
sensors:
linear_status:
friendly_name: "Furnace Status"
value_template: >-
{%- if is_state('climate.linear_heat', 'off') %}
off
{% elif is_state_attr('climate.linear_heat', 'hvac_action', 'idle') or
is_state_attr('climate.linear_heat', 'hvac_action', 'fan') %}
idle
{% elif is_state_attr('climate.linear_heat', 'hvac_action', 'cooling') %}
cool
{% elif is_state_attr('climate.linear_heat', 'hvac_action', 'heating') %}
heat
{% else %}
unknown
{%- endif %}
icon_template: >-
{% if is_state('sensor.linear_status',"idle") %}
mdi:power-on
{% elif is_state('sensor.linear_status',"cool") %}
mdi:snowflake
{% elif is_state('sensor.linear_status',"heat") %}
mdi:fire
{% else %}
mdi:octagon
{% endif %}
Step 2: Create History Stats sensors.
Example for the zwave thermostat above
- platform: history_stats
name: Heat ON time
entity_id: sensor.linear_status
state: 'heat'
type: time
end: '{{ now() }}'
duration:
hours: 24
#sensor 8:
- platform: history_stats
name: Heat ON duty cycle
entity_id: sensor.linear_status
state: 'heat'
type: ratio
end: '{{ now() }}'
duration:
hours: 24
- platform: history_stats
name: Heat ON count
entity_id: sensor.linear_status
state: 'heat'
type: count
end: '{{ now() }}'
duration:
hours: 24
Can be done to track usage month to date as well. The value for purge_keep_days in the recorder component must be greater than 31 for this to be accurate.
- platform: history_stats
name: Monthly Heat ON Time
entity_id: sensor.linear_status
state: 'heat'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0).replace(day=1) }}'
end: '{{ now() }}'