Reminder Custom Component

I appdaemonized these notification automations:

countdown_notify.py:

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!"
2 Likes