mysmarthome/packages/pill_reminder.yaml

156 lines
5.8 KiB
YAML
Raw Permalink Normal View History

2020-03-14 00:10:10 +00:00
###############################################################################
# @author : Mahasri Kalavala
# @date : 03/05/2020
# @package : Pill Reminder Package
# @description : A package to help you remind pills you need to take
###############################################################################
###############################################################################
# _____ _ _ _ _____ _ _
# | __ (_) | | | __ \ (_) | |
# | |__) || | | | |__) |___ _ __ ___ _ _ __ __| | ___ _ __
# | ___/ | | | | _ // _ \ '_ ` _ \| | '_ \ / _` |/ _ \ '__|
# | | | | | | | | \ \ __/ | | | | | | | | | (_| | __/ |
# |_| |_|_|_| |_| \_\___|_| |_| |_|_|_| |_|\__,_|\___|_|
#
###############################################################################
homeassistant:
input_label:
pill_taken_at:
name: Last Pills Taken At
icon: mdi:pill
input_boolean:
pill_taken:
name: Pill Taken
icon: mdi:pill
pill_voice_notification:
name: Pill Voice Notification
icon: mdi:speaker
timer:
timer_pill_reminder:
duration: "00:30:00"
input_datetime:
pill_reminder_time:
name: Pill Reminder Time
has_date: false
has_time: true
initial: "09:00"
###############################################################################
# _ _ _
# /\ | | | | (_)
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
2020-03-15 23:42:44 +00:00
###############################################################################
2020-03-14 00:10:10 +00:00
automation:
###############################################################################
# Turn On "Pill Taken" Input Boolean when the Pill Box is Opened
# Opening the Pills Box signifies that the pills are taken!
# Make sure the pill box is not accessible to children and only you use it daily
###############################################################################
- alias: Pill Box is Opened
initial_state: true
trigger:
platform: state
entity_id: binary_sensor.door_window_sensor_158d00040ad8ec
to: "on"
from: "off"
action:
- service: input_label.set_value
2022-12-05 00:02:34 +00:00
data:
2020-03-14 00:10:10 +00:00
entity_id: input_label.pill_taken_at
value: "{{ as_timestamp(now()) | timestamp_custom('%m/%d/%Y %I:%M %p') }}"
- delay:
seconds: 15
- service: script.pill_taken
###############################################################################
# Reset at mid night every day.
# When you get up in the morning, you will get a fresh reminder
###############################################################################
- alias: Reset Pill Taken
initial_state: true
trigger:
platform: time
at: "00:00:00"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.pill_taken
###############################################################################
# Checks if the pills were taken - trigger on the pill reminder time
# Also, only remind if not on vacation or away from home
# Right after the notification, start the timer, and keep reminders going
# until acknowledged
###############################################################################
- alias: Check if pills were taken
initial_state: true
trigger:
platform: template
value_template: "{{ states('sensor.time') ==
states('input_datetime.pill_reminder_time')[:-3] }}"
condition:
- condition: template
value_template: "{{ states('input_boolean.pill_taken') == 'off' }}"
- condition: template
value_template: "{{ states('input_boolean.home_mode_away') == 'off' }}"
2020-03-14 00:10:10 +00:00
action:
- service: script.remind_pill
###############################################################################
# Timer Elapsed - Time for a reminder if the pill is not taken yet
###############################################################################
- alias: Pill Reminder Timer Elapsed
initial_state: true
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.timer_pill_reminder
action:
- service_template: script.remind_pill
2022-12-03 16:28:12 +00:00
script:
###############################################################################
# Notifies to take pills, starts timer again!
# Voice notifications at home - only if the option is selected.
###############################################################################
remind_pill:
sequence:
- service: script.notify_family
data:
message: "ALERT: PLEASE TAKE YOUR TABLETS!"
notify_options:
- telegram
- service: timer.start
entity_id: timer.timer_pill_reminder
###############################################################################
# Stops timer, Records that the pills are taken, and notifies!
###############################################################################
pill_taken:
sequence:
- service: timer.cancel
entity_id: timer.timer_pill_reminder
- service: input_boolean.turn_on
entity_id: input_boolean.pill_taken
- service: script.notify_family
2022-12-05 00:02:34 +00:00
data:
2022-12-03 16:28:12 +00:00
message: >
Thank you for taking tablets.
{%- if state_attr('sensor.allergy_index_today', 'rating') != None %}
{{- " Today's pollen level is : " ~ state_attr('sensor.allergy_index_today', 'rating') }}.
{%- endif -%}
notify_options:
- telegram
- tv
- led