I have information overload reading all of the posts here, on Reddit, and on a blog. So I have a hard time figuring out what I need to do for my goal which is to track the number of hours the HVAC fan has been ‘on’, a reset for fan on time, and how many days passed since last filter change, as well as the date the filter was last replaced. I want all of that in an entities card but want a way to prevent accidentally running the reset script.
The posts and blog that I have looked at are
The first one by Tediore is the closest to what I want so I used his as a guide to make my own package with the automation, sensors, script, and helpers.
This is what I have so far -
automation:
# Add previous day's runtime to input_number each night
- alias: Store HVAC runtime nightly
initial_state: 'on'
trigger:
- platform: time
at: '00:00:01'
action:
- service: homeassistant.update_entity
entity_id:
- sensor.fan_time_today
- sensor.fan_time_yesterday
- service: input_number.set_value
entity_id: input_number.hvac_runtime
data_template:
value: "{{ ((states('sensor.furnace_filter_life') | float) + (states('sensor.fan_time_yesterday') | float)) | round(1) }}"
sensor:
# Fan time today
- platform: history_stats
name: Fan time today
entity_id: sensor.hvac_fan
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
# Fan time yesterday (for use in storing runtime each night)
- platform: history_stats
name: Fan time yesterday
entity_id: sensor.hvac_fan
state: 'on'
type: time
duration:
hours: 24
end: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
# Fan time current day before filter change script is called
- platform: history_stats
name: Fan time before last filter change
entity_id: sensor.hvac_fan
state: 'on'
type: time
start: "{{ as_timestamp(now().replace(hour=0).replace(minute=0).replace(second=0)) }}"
end: "{{ as_timestamp(states('input_text.furnace_filter')) }}"
- platform: template
sensors:
# Created to use HVAC action state attribute in the history stats sensors
hvac_fan:
friendly_name: HVAC Fan
value_template: "{{ state_attr('climate.thermostat','fan') }}"
# Used to display current total runtime in frontend
furnace_filter_life:
friendly_name: "Filter runtime"
value_template: >
{% set active = states('sensor.fan_time_today') | float %}
{% set runtime = states('input_number.hvac_runtime') | float %}
{{ (runtime + active) | round(1) }}
unit_of_measurement: 'h'
icon: mdi:air-filter
script:
# Reset filter change date and set total runtime to zero
furnace_filter_date:
alias: Furnace filter change date
sequence:
- service: input_text.set_value
entity_id: input_text.furnace_filter
data_template:
value: '{{ now() }}'
- service: homeassistant.update_entity
entity_id:
- sensor.fan_time_before_last_filter_change
- service: input_number.set_value
entity_id: input_number.hvac_runtime
data_template:
value: >
{% set active = states('sensor.fan_time_before_last_filter_change') | float %}
{{ 0 - active }}
input_text:
# Store furnace filter change date
furnace_filter:
name: Furnace filter change date
input_number:
# Used to store runtime nightly to reduce reliance on history
hvac_runtime:
name: Runtime
icon: mdi:clock-outline
mode: box
min: -500
max: 500
unit_of_measurement: 'h'
He made his package with input_text. Not sure if I should leave it as input_text
. If I should change the package to input_datetime
how do I do that so that all related integrations continue to work?
I want a sensor for the input_text.furnace_filter so that the date and time doesn’t have an underline in the entities card. How does that need to be written into a template? I found a thread at Show Input Datetime as value not as input but I am not sure if the first example is all I need and that is for input_datetime
and not input_text