I made a custom component to help me remember to change my AC filter and thought I’d share it. This component’s state will be True when the specified number of days have passed, otherwise False.
- platform: date_reminder
name: AC Filter Change
#Date last done/changed
date: "02-06-2017 00:00"
#When to remind me in days
day_reminder: 60
automation.yaml:
- alias: "Change AC Filter Notification"
initial_state: on
trigger:
platform: state
entity_id: sensor.ac_filter_change
to: 'True'
action:
service: persistent_notification.create
data_template:
message: "It's been {{ states.sensor.ac_filter_change.attributes.days }} days since the AC filter was last changed"
title: "Time To Change AC Filter!"
import appdaemon.appapi as appapi
"""
Notifies the specified notifier on
the days you specify.
"""
class Notify(appapi.AppDaemon):
def initialize(self):
if "countdown_entity" in self.args:
self.listen_state(self.evaluate_notice, self.args["countdown_entity"])
def evaluate_notice(self, entity, attribute, old, new, kwargs):
days_remaining = self.get_state(entity, "days_remaining")
entity_friendly_name = self.get_state(entity, "friendly_name")
if type(self.args["notification_days"]) == int:
notification_days = [self.args["notification_days"]]
else:
notification_days = [int(day) for day in self.args["notification_days"].split(",")]
if days_remaining in notification_days:
self.send_notice()
elif self.args["notify_overdue"] and days_remaining < 0:
self.send_notice()
def send_notice(self):
self.log("Sending notification")
self.call_service("notify/" + self.args["notify"], message = self.args["message"])
self.call_service("persistent_notification/create", message = self.args["message"])
appdaemon.yaml:
Brita Notification:
module: countdown_notify
class: Notify
countdown_entity: sensor.brita_filter_change
notification_days: 0 #A mandatory list of when to notify, can be 1 or more value, eg: 1,2,7,30
notify_overdue: True #An optional argument, if true we will continue to notify after 0
notify: home_assistant #The name of the notify service
message: "It's time to change the Brita filter!"