Skip to content

Instantly share code, notes, and snippets.

@jcallaghan
Last active May 17, 2022 20:05
Show Gist options
  • Save jcallaghan/7e3b55401f980519e326ac9a85600088 to your computer and use it in GitHub Desktop.
Save jcallaghan/7e3b55401f980519e326ac9a85600088 to your computer and use it in GitHub Desktop.
Example #HomeAssistant automation for tracking my medicine to remind me to order more when low.
alias: 'Family - James - Track Medicine'
id: '4df574c4-bb48-4108-b679-76a47966af92'
description: 'Track medicine and order more when low.'
initial_state: true
mode: 'single'
max_exceeded: silent
trigger:
# Let's keep this simple and assume the medicine was taken each day.
- id: medicine_taken
platform: time
at: '23:45:00'
# Send email to pharmacy requesting more medicine when there is one week of pills left.
- id: order
platform: state
entity_id: counter.james_medicine
to: "8"
# Send a reminder to collect prescription when out-and-about in the local area.
- id: pickup_reminder
platform: zone
entity_id: person.james
zone: !secret zone_local_area
event: enter
# Reset counter when entering pharmacy.
- id: collected
platform: zone
entity_id: person.james
zone: !secret zone_pharmacy
event: enter
# Update counter with text from phone notification action
- id: update_counter
platform: event
event_type: mobile_app_notification_action
event_data:
action: "chore_james_medicine_collected"
action:
- if:
- condition: trigger
id: medicine_taken
then:
- service: counter.deincrement
data:
entity_id: counter.james_medicine
- if:
- condition: trigger
id: order
then:
- service: notify.james
data:
message: "💊 Order placed with pharmacy."
data:
group: "family"
tag: "james_medicine"
push:
interruption-level: time-sensitive
actions:
- action: "CALL"
title: "Call Pharmacy"
uri: !secret pharmacy_phone
icon: "sfsymbols:phone.fill"
- action: "CALL"
title: "Call GP"
uri: !secret doctor_phone
icon: "sfsymbols:phone.fill"
- service: notify.email
data:
target: !secret pharmacy_to
title: !secret pharmacy_subject
message: !secret pharmacy_body
- service: input_boolean.turn_on
data:
entity_id: input_boolean.chore_james_medicine_collection
- if:
- condition: trigger
id: pickup_reminder
- condition: state
entity_id: input_boolean.chore_james_medicine_collection
state: 'on'
then:
- service: notify.james
data:
message: "💊 Remember to pick-up medicine."
data:
group: "family"
tag: "james_medicine"
push:
interruption-level: time-sensitive
actions:
- action: "chore_james_medicine_collected"
title: "Update pills remaining"
icon: "sfsymbols:checkmark"
behavior: textInput
textInputButtonTitle: "Pills remaining"
textInputPlaceholder: "Pills"
- action: "CALL"
title: "Call Pharmacy"
uri: !secret pharmacy_phone
icon: "sfsymbols:phone.fill"
- action: "CALL"
title: "Call GP"
uri: !secret doctor_phone
icon: "sfsymbols:phone.fill"
- if:
- condition: trigger
id: collected
- condition: state
entity_id: input_boolean.chore_james_medicine_collection
state: 'on'
then:
- service: notify.james
data:
message: "💊 Medicine collected."
data:
group: "family"
tag: "james_medicine"
push:
interruption-level: time-sensitive
actions:
- action: "chore_james_medicine_collected"
title: "Update pills remaining"
icon: "sfsymbols:checkmark"
behavior: textInput
textInputButtonTitle: "Pills remaining"
textInputPlaceholder: "Pills"
- action: "CALL"
title: "Call Pharmacy"
uri: !secret pharmacy_phone
icon: "sfsymbols:phone.fill"
- action: "CALL"
title: "Call GP"
uri: !secret doctor_phone
icon: "sfsymbols:phone.fill"
- service: counter.configure
data:
entity_id: counter.james_medicine
value: "{{ states('counter.james_medicine') | int(default=0) + 28 }}"
- if:
- condition: trigger
id: update_counter
then:
- service: counter.configure
data:
entity_id: counter.james_medicine
value: "{{ trigger.event.data.reply_text }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment