Medication Reminder

Here’s a little package I put together to make sure I remember to give my son his morning medication, it’s setup to alert my wife and myself before we would normally leave for school if the input_boolean.meds_taken has not been activated.

DISCLAIMER: It should be obvious, but don’t rely on this 100% to make sure your kid, grandparent, spouse, dog, neighbors dog, guy down the street (you get the picture) with a critical heart condition gets their medication. I’ve surely not thought of all the edge cases, nor do iOS notifications get delivered 100% of the time. Use at your own risk.

The first bit is adding the actionable notification to the ios component. After you do this, make sure you go into the app settings -> notification settings and tap update push settings. I spent a week tearing my hair out as to why the action buttons were not showing up.

ios:
  push:
    categories:
      - name: Meds Not Taken
        identifier: 'MEDS_NOT_TAKEN'
        actions:
          - identifier: 'MARK_MEDS_TAKEN'
            title: 'Mark meds as taken'
            activationMode: 'background'
            authenticationRequired: no
            destructive: yes
            behavior: 'default'

Now onto the main part. There are two input_boolean’s, meds_taken manages the state of if the medication has been taken and meds_reminder is so you can turn it off in the event my son is at someone else house and I can’t really do anything about it.

The automations handle resetting meds_taken after two hours (one could in theory expand upon this to have multiple time that medication should be administered), sending out a notification if the meds have not been taken and handling the notification action that comes back. I added a condition to the meds not taken automation that it has to be before 09:00 to prevent alerts when the server restarts, and by that time I’m at work so there’s not much that can be done about it. The group is there to put it all in one card on the default page.

input_boolean:
  meds_taken:
    name: Meds have been taken
    initial: 'off'
    icon: mdi:pill
  meds_reminder:
    name: Meds reminder enabled
    initial: 'on'

group:
  meds_reminder:
    entities:
      - input_boolean.meds_taken
      - input_boolean.meds_reminder

automation:
  - alias: Reset meds taken
    trigger:
      platform: state
      entity_id: input_boolean.meds_taken
      to: 'on'
      for:
        hours: 2
    action:
      service: input_boolean.turn_off
  
  - alias: Mark meds as taken from notification
    trigger:
      platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: 'MARK_MEDS_TAKEN'
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.meds_taken

  - alias: Meds have not been taken weekday
    trigger:
      platform: time
      after: '07:24:00'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.meds_taken
          state: 'off'
        - condition: state
          entity_id: input_boolean.meds_reminder
          state: 'on'
        - condition: time
          before: '09:00:00'
          weekday:
            - mon
            - tue
            - wed
            - thu
            - fri
    action:
      - service: notify.ios_christas_iphone
        data:
          title: "Morning Meds"
          message: "Tucker's morning meds have not been taken!"
          data:
            push:
              category: 'MEDS_NOT_TAKEN'
      - service: notify.ios_ryans_iphone
        data:
          title: "Morning Meds"
          message: "Tucker's morning meds have not been taken!"
          data:
            push:
              category: 'MEDS_NOT_TAKEN'

Up to this point this is fairly basic, and doesn’t add much more to the hundreds of medication tracking apps for your smartphone. The problem with all of those is I often wouldn’t have my phone on me in the mornings when I give him his meds and I’m just barely awake so remembering to go into an app to check something off doesn’t do to good.
So I added an Amazon Dash button that I picked up for $1.99 during the mothers day sale and paired it with dasher (https://github.com/maddox/dasher). Now I have a dash button stuck to the cabinet door where the medication is and when I press the button it calls the home assistant REST API to turn input_boolean.meds_taken to ‘on’. And in the event that the dash button press didn’t register, the actionable notification as we are walking out the door will let us flip that boolean.

Here is the config.json from my local dasher…

{"buttons":[
  {
    "name": "Medication",
    "address": "68:37:e9:58:48:f8",
    "interface": "eth0",
    "timeout": "60000",
    "protocol": "arp",
    "url": "http://192.168.10.118:8123/api/services/input_boolean/turn_on",
    "method": "POST",
    "headers": {"x-ha-access": "XXXXXX"},
    "json": true,
    "body": {"entity_id": "input_boolean.meds_taken"}
  }
]}

I’m still playing with ways to visualize adherence to the medication schedule (e.g. ‘how many times did I miss his medication in the last 30 days’) and I’d also like to play with repeat notifications like the alert component does.

Well there you go, my first automation shared to the world. Any comments or suggestions would be appreciated :slight_smile:

8 Likes

I really like the use case. This is - for me - the reason why HA is heads above the other Home Automation platforms. That you can take a bunch of digital “parts” and link them together in a way that is meaningful to your life, that’s what it’s all about man.

Nice job and thanks for sharing it!

Thanks for sharing this, I really am very grateful - one of those things that didn’t even occur to me as hassable. I’m beginning to love input booleans.

Dash buttons are a bit harder to come by in Australia but the xiaomi wifi buttons are dirt cheap, even a door or motion sensor stuck in a drawer would work. Notify component, plus teamed with a hadashboard display and I’ll be able to eliminate the frequent anxiety inducing doubt this causes and see in an instant what’s what.

Been using a basic alarm function on my phone but this falls down whenever I am not able to respond immediately and cant remember if I remembered a few hours later and worry about double dosing. I’ve been meaning to get one of those pill boxes with day markings but this works heaps better for me.

1 Like

I was fortunate to get an early view of an ios notification that @skalavala was working on. Here is a link to the beginning test package. https://github.com/torn8o/Home-AssistantConfig/blob/master/packages/skal.yaml you will also need this file https://github.com/torn8o/Home-AssistantConfig/blob/master/packages/ios_plug_in_play.yaml The second file has the ios actionable information in it. What I originally received started as a take meds notification with the ability to select yes or no on taking it and if hasn’t taken meds it would set a timer to remind the person

For the post, here is @skalavala updated automation that he built it is for taking out the trash. https://github.com/skalavala/smarthome/blob/master/packages/recycle_trash.yaml
For awesome automatons and examples, you should check his repo

This is great. I’ve. Even meaning to add ios actions to my medicine tracker. One thing you might want to add that I did was send a time stamp to MQTT when you press the dash button. I found seeing the actual date gave me more evidence that I took the medicine and it wasn’t an restart or input Boolean glitch.

I also added TTS and an entry to the logbook when I miss it. I take a once daily pill.

https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/automation/medicine_logger.yaml

1 Like

Ohh, I do like the idea of sending it out to MQTT for verification. I’ve been wanting to do some TTS with this and other automations, I have Echo’s all over the house and have been trying to pair them via bluetooth to my Pi3 to serve as a workaround for pushing voice notifications to an Echo.

Awesome, glad I could provide some inspiration! I’m exactly the same way, I hardly remember anything that goes on in the morning so adding the button has been the key for me.

Does anyone know if there an android equivalent to ios actions?

I’m guessing this basically asks a question via notification and allows an on screen response or reply.

I’m going to need a reminder in place to remind me to install this reminder. Setting up my new server and didn’t do the network backup correctly on my unifi controller, too many other things to fix. After two hours of trying to get my lights working again I had to give up and turn off the toilet light manually at 5am this morning. The shame.

Tasker would be the first thing I would think of. True story: it’s how BRUH Automation got started. Before HA, he ran most of his stuff with Tasker.

Here’s a good tutorial:

1 Like

Yes

Me too! Except I’d rearrange that slightly to say I discovered hass via a BRUH video on building a window/blind/curtain winder thing - on the suggestions I saw a link to one of his hass videos and an hour later I had it installed.

I still use tasker to trigger my outdoor lights when I get home (via hass) but almost everything else is converted to straight hass. And I have join too so something should definitely be possible.

I ended up getting a pill box with days of the week on it - got busy and haven’t been able to integrate this yet, I’ll report back when I work out what my solution is to the response thing.

1 Like