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