Hey everyone! I wanted to share my recent success with integrating a custom smart sensor into my home automation setup. After some trial and error, I managed to create a system that tracks the days until my HVAC filter needs replacement. Here’s how I did it and the lessons I learned along the way.
First, I created two helper entities: one to track the installation date of the filter and another to set its lifespan in days. This was straightforward using the input_datetime and input_number platforms in Home Assistant. The real challenge came when I tried to combine these values into a single sensor that calculates the remaining days.
Here’s the setup I used:
yaml
input_datetime: air_filter_installed:
name: Air Filter Installed
icon: mdi:air-filter
has_date: true
has_time: false
input_number: air_filter_lifespan:
name: Air Filter Lifespan
initial: 90
min: 0
max: 365
step: 1
mode: box
unit_of_measurement: days
icon: mdi:history
sensor:
- platform: template
sensors:
air_filter_days_remaining:
friendly_name: “Air Filter Days Remaining”
unique_id: “air filter timer”
unit_of_measurement: “days”
icon_template: ‘mdi:calendar-clock’
value_template: >-
{%- set inst = as_timestamp(states(‘input_datetime.air_filter_installed’)) -%}
{%- set dif = states(‘input_number.air_filter_lifespan’) | int * 86400 -%}
{%- set nt = as_timestamp(states(‘sensor.date’)) -%}
{{ (((inst + dif) - nt) / 86400) | round(0) }}
Initially, the sensor showed as unavailable, which was frustrating. After some research, I realized the issue was with how the timestamps were being handled. By ensuring all time calculations were in seconds and properly formatted, the sensor started working like a charm!
Now, I have a fully functional system that reminds me when it’s time to change the HVAC filter. This not only helps me maintain better air quality but also prevents potential system damage from a clogged filter. It’s a small project, but it’s made a big difference in how I manage my home’s maintenance.
I’d love to hear how others are using custom sensors in creative ways! Whether it’s tracking appliance maintenance, monitoring plant watering schedules, or anything else, let’s share our ideas and tips. Happy automating! ![]()