Background: I like to replace my HVAC filter every 90 days or so… but it usually ends up actually happening way past the “or so”
In my setup, on each day past the “due date” I receive a notification to alert me that it’s time to change the filter. After I change it, I physically press a zigbee smart button that’s attached to my HVAC unit (located just above the filter slot) to restart the countdown. I also use this same method to track the refilling of supplement containers, toothbrushes replacement, contact lens age - this could apply to many different recurring tasks. I’d love to hear about your setups!
I’m using a zigbee-based smart button to restart the countdown after I’ve completed the task - I won’t be covering how to add a smart button to HA in this guide. The smart button in my setup is simply the switch that I use to reset the countdown - you could use any other type of physical input that HA can read, even just a script or otherwise virtual button to perform the reset if you aren’t using smart buttons.
- To set up the HA configuration, first create the following 3 Helpers (Configuration -> Helpers -> Add Helper).
-
Toggle; named “HVAC Filter Clean”.
This toggle/input_boolean is used as a status indicator for Lovelace dashboard. When toggled to the On position in the UI, the filter is clean. You could also use this input_boolean in combination with a custom template to make your dashboard display the words “Clean” and “Dirty” next to filter status (not covered in this guide). -
Number; named “HVAC Filter Days Until Old”, with the unit of measurement configured for Days.
This number/input_number allows you to choose the number of days before the filter expires. Later in this guide you’ll set the Number to the desired number of days before the filter is considered “Dirty”. -
Date and/or Time; named “HVAC Filter Date Last Changed”.
This date/input_datetime gets set to now() when you replace the filter, and is used in combination with the current date to calculate the filter’s age and expiry.
- Next is the fun(?) part - working with datetime calculations within Home Assistant. Most of my time spent on this project was working on these formulas. Add the following to your
configuration.yaml
file:
sensor:
- platform: template
sensors:
hvac_filter_change_date:
friendly_name: 'HVAC Filter Change Date'
value_template: "{{ strptime(states('input_datetime.hvac_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.hvac_filter_days_until_old') | int) }}"
icon_template: mdi:calendar-refresh-outline
hvac_filter_days_left:
friendly_name: 'HVAC Filter Days Left'
value_template: >
{% set hvac_filter_change_date = strptime(states('input_datetime.hvac_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.hvac_filter_days_until_old') | int) %}
{{ (as_timestamp(hvac_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int }}
icon_template: mdi:clock-end
unit_of_measurement: 'Days'
hvac_filter_age:
friendly_name: 'HVAC Filter Age'
value_template: "{{ (( as_timestamp(now()) - (states.input_datetime.hvac_filter_date_last_changed.attributes.timestamp)) | int /60/1440) | round(0) }}"
icon_template: mdi:clock-start
unit_of_measurement: 'Days'
-
Restart Home Assistant so that your newly created sensors are available.
-
Create a new Automation (Configuration -> Automations -> Add Automation) named “Status: HVAC Filter Changed”. This Automation is responsible for setting the status back to “Clean” and also setting the “date last changed” to today. This is the automation that will be executed when you press your physical smart button to restart the countdown process. Configure this Automation as follows (or if you’re comfortable with pasting the YAML, I’ve provided it at the bottom of this step):
-
Add a Trigger of type “State”. Choose the entity that you want to use as your smart button, the one you’ll physically press after you’ve changed the filter - in my case, it is:
sensor.hvac_filter_smart_button_action
. In the “To” field, mine is configured for “release” (note this is case sensitive). -
Add an Action of type “Call Service”. The Service to call is
input_boolean.turn_on
, and the entity to target isinput_boolean.hvac_filter_clean
. -
Add one more Action but don’t choose a type - for this one, we’ll need to use the raw YAML editor in order to allow us to access the data_template capability. Click the three vertical dots on the upper right of the new Action card and then click Edit in YAML. Paste the following code:
service: input_datetime.set_datetime data_template: date: '{{ now().strftime(''%Y-%m-%d'') }}' target: entity_id: input_datetime.hvac_filter_date_last_changed
-
Click Save
Full YAML:
alias: 'Status: HVAC Filter Changed'
description: ''
trigger:
- platform: state
to: release
entity_id: sensor.hvac_filter_smart_button_action
condition: []
action:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.hvac_filter_clean
- service: input_datetime.set_datetime
data_template:
date: '{{ now().strftime(''%Y-%m-%d'') }}'
target:
entity_id: input_datetime.hvac_filter_date_last_changed
mode: single
- Create a new Automation (Configuration -> Automations -> Add Automation) named “Notify: HVAC Filter”. This Automation is responsible for changing the filter status to “Dirty” and also notifying you that it’s time to replace the filter. This is the automation that will be executed when the countdown process hits 0 days. Configure this Automation as follows (or if you’re comfortable with pasting the YAML, I’ve provided it at the bottom of this step):
-
Add a Trigger of type “State”. Choose the entity
sensor.hvac_filter_days_left
. In the “To” field, enter “0” (number zero). -
Add an Action of type “Call Service”. The Service to call is
input_boolean.turn_off
, and the entity to target isinput_boolean.hvac_filter_clean
. -
Add another Action of type “Call Service”. The Service to call is
notify.YOUR_NOTIFY_SERVICE
. Configure the notification Title and Message as you see fit. -
Click Save
Full YAML:
alias: 'Notify: HVAC Filter'
description: ''
trigger:
- platform: state
entity_id: sensor.hvac_filter_days_left
to: '0'
condition: []
action:
- service: notify.YOUR_NOTIFY_SERVICE
data:
title: HVAC Filter
message: 'HVAC Filter needs replaced. '
- service: input_boolean.turn_off
target:
entity_id: input_boolean.hvac_filter_clean
mode: single
-
On your desired Lovelace Dashboard, add a new Entities List card containing the following 6 entities:
input_boolean.hvac_filter_clean input_datetime.hvac_filter_date_last_changed input_number.hvac_filter_days_until_old sensor.hvac_filter_change_date sensor.hvac_filter_age sensor.hvac_filter_days_left
-
Set “HVAC Filter Days Until Old” to your desired number of days to replace.
-
Replace your filter and then press your smart button or other monitored input device.
Regards,
Chris