This is a pretty neat automation that has worked very well for my family for a while now. I recently made some final tweaks to make it 99% automatic (100% for me, wife has an additional step). I want to share this with everyone, but also curious if anyone sees any ways to make this cleaner. My most recent change probably doubled the amount of code and added a timer - feels really bloated, but should work anyway (haven’t been able to test most recent change - the notifications didn’t change and should still work)
The main purpose of this is to alert us when it is time to take either Morin or Tylenol. We have 2 kids (someone always has an ear infection or fever or something) and occasionally my wife or I will need these meds for a few days or hours. And sometimes we’re taking Motrin - 3hrs later tylenol - 3 hrs later motrin for days on end. This helps keep it straight.
Basically you tap a button (I have buttons on my Android and we have a touchscreen dashboard in the kitchen) which starts a countdown. You can customize the countdown but we have every 6 hours. At the end of the countdown, we get a HASS notification on our phone that the timer ran out and it’s time to take more. Pretty simple.
What makes this more complicated is that the buttons on the dashboard are conditinoal, so I can hide them or show them. If nobody is sick I don’t want this up there all the time. And I waned to automate this. So I added a 60 hour countdown that starts when either Motrin or Tylenol timer changes to idle. This by default will reset to 60 hours if we’re still taking meds, or only taking one. Once this 60 hour countdown ends it will hide the buttons on the dashboard.
Helpers:
- timer.motrin
- timer.tylenol
- input_boolean_motrin_tylenol (used to toggle dashboard buttons on and off)
- timer.motrin_tylenol_off_countdown (60 hour countdown - starts any time timer.motrin or timer.tylenol changes to idle - once this timer goes to idle it turns off the input_boolean to hide the dashboard buttons)
- Widgets on Android
- countdowns directly in config file (needed to display how many hrs/minutes left on dashboard and android widget)
sensor:
- platform: template
sensors:
motrin_countdown:
value_template: >-
{% set f = state_attr('timer.motrin', 'finishes_at') %}
{{ 'Take Now' if f == None else
(as_datetime(f) - now()).total_seconds() | timestamp_custom('%H:%M', false) }}
- platform: template
sensors:
tylenol_countdown:
value_template: >-
{% set f = state_attr('timer.tylenol', 'finishes_at') %}
{{ 'Take Now' if f == None else
(as_datetime(f) - now()).total_seconds() | timestamp_custom('%H:%M', false) }}
Here is the YAML for the entire automation and a brief description of the triggers and what they do.
I have multiple triggers with their own trigger ID’s.
1 & 2) when Motrin or Tylenol timers change to idle
- this sends us a HASS message to take more and starts a 60 hour countdown
3) when Motrin or Tylenol timer changes from idle to active (easiest way is me hitting my android button if its first time, or the dashboard buttons if we’re in the middle of a round. Dashboard butons are a “restart” and my android buttons it’s easy to change the timeframe in the widget if we wan’t something other than 6 horus)
- the button press starts whichever countdown button was hit and also toggles the boolean to show the buttons on the dashboard (if they aren’t already there)
4) When the 60 hour countdown timer ends - assume we don’t need any more pain meds and hide the kitchen dashboard buttons
alias: Motrin / Tylenol
description: Makes tracking Motrin & Tylenol on schedule easy
trigger:
- platform: state
entity_id:
- timer.motrin
from: active
to: idle
id: Motrin
- platform: state
entity_id:
- timer.tylenol
from: active
to: idle
id: Tylenol
- platform: state
entity_id:
- timer.motrin
- timer.tylenol
from: idle
to: active
id: Show Dashboard Buttons
- platform: state
entity_id:
- timer.motrin_tylenol_off_countdown
to: idle
id: Hide Dashboard Buttons
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Motrin
sequence:
- service: notify.all_mobile_apps
data:
message: Time for more Motrin
- service: timer.start
data:
duration: "60:00:00"
target:
entity_id: timer.motrin_tylenol_off_countdown
- conditions:
- condition: trigger
id:
- Tylenol
sequence:
- service: notify.all_mobile_apps
data:
message: Time for more Tylenol
- service: timer.start
data:
duration: "60:00:00"
target:
entity_id: timer.motrin_tylenol_off_countdown
- conditions:
- condition: trigger
id:
- Show Dashboard Buttons
- condition: state
entity_id: input_boolean.motrin_tylenol
state: "off"
sequence:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.motrin_tylenol
- conditions:
- condition: trigger
id:
- Hide Dashboard Buttons
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.motrin_tylenol
mode: single
And the dashboard code using the custom button integration
I can’t remember if Tylenol should be “idle” or take now - but probably doens’t matter. Probably should be take now.
type: conditional
conditions:
- entity: input_boolean.motrin_tylenol
state: 'on'
card:
type: horizontal-stack
cards:
- type: custom:button-card
template: standard-alert
entity: timer.motrin
tap_action:
action: call-service
service: timer.start
service_data:
entity_id: timer.motrin
icon: mdi:pill
show_last_changed: false
size: 30%
aspect_ratio: 2/1
styles:
card:
- background-color: black
state:
- value: active
color: red
- value: idle
color: green
- type: custom:button-card
template: standard-alert
entity: timer.tylenol
tap_action:
action: call-service
service: timer.start
service_data:
entity_id: timer.tylenol
icon: mdi:pill-multiple
show_last_changed: false
size: 30%
aspect_ratio: 2/1
styles:
card:
- background-color: black
state:
- value: active
color: red
- value: idle
color: green
I hope this helps someone. I had the idea for a long time and built a basic automation and tweaked it every time we needed a new round of meds until I got it to where it is now.