Reminder application

Hey all

I have been wanting a fully fledged reminder system in Home Assistant for some time. Alas, as far as I can tell there really is not one. So, I wrote something that does just that! This is an AppDaemon app so you will have to have AppDaemon setup and ready to go. You will also have to create a reminder namespace in your appdaemon.yaml like this:

  namespaces:
    reminder:

The app listens for an event and creates a reminder entity in the reminder namespace so it is preserved through Home Assistant restarts, but also creates the entity in Home Assistant for easy visualization. When the time comes, it sends the notification and then removes the entity. It’s that simple.

Here is the structure of the event, all fields are required even if they are empty:

  - event: set_reminder
    event_data:
      title: '{{ title }}'
      message: '{{ message }}'
      recipient: '{{ recipient }}'
      name: '{{ name }}'
      time: '{{ fire_time }}'

A reminder can be removed by firing another event like this:

  - event: remove_reminder
    event_data:
      entity_id: reminder.test

You can create an automation that will fire the event and use the content of helpers to create the reminder, here is an example:

- alias: Reminder
  trigger:
  - platform: state
    entity_id: input_boolean.reminder
    to: 'on'
  condition: []
  action:
  - variables:
      fire_time: '{{ states(''input_datetime.reminder'') }}'
      message: '{{ states.input_text.reminder.state }}'
      title: ''
      recipient: '{{ states("input_select.reminder_recipient") }}'
      name: '{{ states("input_text.reminder_name") }}'
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.reminder
  - event: set_reminder
    event_data:
      title: '{{ title }}'
      message: '{{ message }}'
      recipient: '{{ recipient }}'
      name: '{{ name }}'
      time: '{{ fire_time }}'

I setup a quick UI that just uses an entity card with the helpers to fill out and uses the automation above. It also uses the custom card autoentities to display the active reminders:

Anyway, here is the AppDaemon code, hopefully you find it useful, and/or can find a way to make it better:

Last thing, the AppDaemon apps.yaml example:

reminder:
  module: reminder
  class: reminder
3 Likes

I’ve been looking for something like this for quite a while. Looks fantastic, can’t wait to try it.

Would be amazing if you could set a reminder Tobe triggered by something other than time as well. E.g. I often want to be reminded about something when it get home, which may or may not be at a specific time.

I’m still new to AppDeamon, but am I missing some steps?

  1. I’ve added the code from reminder.py to a textfile (reminder.py) within config/appdeamon/apps/reminder.py
import hassapi as hass
import datetime

class reminder(hass.Hass):

    def initialize(self):
        self.set_namespace("reminder")
        self.listen_event(self.set_reminder,'set_reminder', namespace='default')
        self.listen_event(self.remove_reminder,'remove_reminder', namespace='default')
        domain = 'reminder'
        reminder_list = list(self.get_state(domain).keys())
        if len(reminder_list) > 0:
            for reminder in reminder_list:
                time = self.parse_datetime(self.get_state(reminder))
                att = self.get_state(reminder, attribute='all')
                dt = datetime.datetime.now()
                if dt.timestamp() > time.timestamp():
                    self.remove_entity(reminder, namespace='default')
                    self.remove_entity(reminder, namespace='reminder')
                else:
                    self.run_at(self.send_reminder, time, entity_id = reminder)
                    self.set_state(**att, namespace='default')
                    self.log('Subscribed to ' + reminder)

    def set_reminder(self, event, data, kwargs):
        """Creates Reminder Entities to Track"""
        if 'name' in data and 'time' in data and 'title' in data and 'recipient' in data and 'message' in data:
            entity_name = 'reminder.' + data['name']
            entity_name = entity_name.replace(" ", "_")
        else:
            self.log('No reminder name defined, exiting')
            return
        self.set_state(entity_name, state=data['time'],  attributes = { 
            "message": data['message'],
            "title": data['title'],
            "recipient": data['recipient']}, namespace='default')
        self.add_entity(entity_name, state=data['time'],  attributes = { 
            "message": data['message'],
            "title": data['title'],
            "recipient": data['recipient']}, namespace='reminder')
        self.restart_app(self.name)

    def send_reminder(self, kwargs):
        """Sends reminder then deletes entity"""
        self.log('send_reminder')
        state=self.get_state(kwargs['entity_id'], attribute="all")
        attributes = state['attributes']
        self.notify(attributes['message'], title = attributes['title'], name = attributes['recipient'], namespace='default')
        self.remove_entity(kwargs['entity_id'], namespace='default')
        self.remove_entity(kwargs['entity_id'], namespace='reminder')

    def remove_reminder (self, event, data, kwargs):
        self.remove_entity(data['entity_id'], namespace='default')
        self.remove_entity(data['entity_id'], namespace='reminder')
        self.restart_app(self.name)
  1. added wihtin the appdeamon.yaml:
appdaemon:
  namespaces:
    reminder:
      writeback: safe
  1. Added the scripts (2) and automation (1)
  2. added all the entities (manually) through helpers (is this correct?)

I have a sort of working UI:

But I can’t remove the reminders, output from appdeamon:

2023-08-21 15:55:00.024272 WARNING reminder: ------------------------------------------------------------
2023-08-21 15:59:01.944078 WARNING HASS: Error Removing Home Assistant entity reminder.reminder_name_test
2023-08-21 15:59:01.944726 WARNING HASS: Code: 405, error: 405: Method Not Allowed
2023-08-21 15:59:01.948333 INFO AppDaemon: Terminating reminder
2023-08-21 15:59:01.950177 INFO AppDaemon: Loading app reminder using class reminder from module reminder
2023-08-21 15:59:01.958212 INFO AppDaemon: Calling initialize() for reminder
2023-08-21 15:59:01.969374 WARNING HASS: Error Removing Home Assistant entity reminder.Reminder_name_test
2023-08-21 15:59:01.970157 WARNING HASS: Code: 405, error: 405: Method Not Allowed
2023-08-21 15:59:04.061533 WARNING HASS: Error Removing Home Assistant entity reminder.reminder_name_test_2
2023-08-21 15:59:04.063490 WARNING HASS: Code: 405, error: 405: Method Not Allowed
2023-08-21 15:59:04.068011 INFO AppDaemon: Terminating reminder
2023-08-21 15:59:04.069835 INFO AppDaemon: Loading app reminder using class reminder from module reminder
2023-08-21 15:59:04.080579 INFO AppDaemon: Calling initialize() for reminder

Also there is no notification on my phone / companion app: FIXED

Any help will be very much appreciated!

I think this has to do with a breaking change in home assistant where app daemon can’t delete things without a unique id. I don’t use this application any more because I migrated to a different solution.

I adapted this issue tracker so that it can handle reminders. All it requires is MQTT and a few custom lovelace cards that are noted in the gist.

2 Likes