Custom med tracker functional for interval meds (#156)

Custom med tracker functional for interval meds
This commit is contained in:
2023-10-05 18:51:44 -04:00
committed by GitHub
parent ce188b059e
commit 98276febac
3 changed files with 231 additions and 10 deletions

View File

@ -2221,22 +2221,33 @@
trigger:
- platform: time
at: input_datetime.tony_morning_meds_notify
id: wakeup
id: morning-notify
alias: Morning Notify
- platform: time
at: input_datetime.tony_night_meds_notify
id: sleep
id: night-notify
alias: Night Notify
- platform: state
entity_id: input_boolean.tony_morning_meds_taken
entity_id:
- input_boolean.tony_morning_meds_taken
to: 'on'
id: boolean-morning
alias: Morning Taken
from: 'off'
- platform: state
entity_id: input_boolean.tony_night_meds_taken
to: 'on'
entity_id:
- input_boolean.tony_night_meds_taken
id: boolean-night
alias: Night Taken
from: 'off'
to: 'on'
- platform: state
entity_id: input_boolean.master_bedroom_sleeping
to: 'off'
entity_id:
- input_boolean.master_bedroom_sleeping
id: sleep-off
alias: Sleep Off
from: 'on'
to: 'off'
condition: []
action:
- choose:
@ -2244,31 +2255,37 @@
- condition: and
conditions:
- condition: trigger
id: wakeup
id: morning-notify
- condition: state
entity_id: input_boolean.tony_morning_meds_taken
state: 'off'
alias: Morning Notify
sequence:
- service: script.turn_on
target:
entity_id: script.tony_morning_meds
data: {}
alias: Run morning meds script
- conditions:
- condition: and
conditions:
- condition: trigger
id: sleep
id:
- night-notify
- condition: state
entity_id: input_boolean.tony_night_meds_taken
state: 'off'
alias: Night Notify
sequence:
- service: script.turn_on
target:
entity_id: script.tony_night_meds
data: {}
alias: Run night meds script
- conditions:
- condition: trigger
id: boolean-morning
alias: Morning Taken
sequence:
- service: input_datetime.set_datetime
target:
@ -2278,9 +2295,11 @@
}}
'
alias: Set time morning meds were taken
- conditions:
- condition: trigger
id: boolean-night
alias: Night Taken
sequence:
- service: input_datetime.set_datetime
target:
@ -2290,9 +2309,11 @@
}}
'
alias: Set time night meds were taken
- conditions:
- condition: trigger
id: sleep-off
alias: Sleep Off
sequence:
- service: input_datetime.set_datetime
target:
@ -2302,8 +2323,10 @@
}}
'
alias: Set time to start notifying for morning meds
alias: Routing
mode: parallel
max: 4
max: 10
- id: '1696288939707'
alias: Tony Stream Today
description: ''
@ -2657,3 +2680,51 @@
entity_id: input_select.kallen_morning_briefing_location
alias: Move morning briefing to common areas
mode: single
- id: '1696539209438'
alias: Tony Custom Meds Handler
description: ''
trigger:
- platform: time
at: input_datetime.tony_custom_meds_notify_p1
alias: Notify 1
id: p1-notify
- platform: state
entity_id:
- input_boolean.tony_custom_meds_taken_p1
from: 'off'
to: 'on'
id: p1-taken
alias: Taken 1
condition: []
action:
- variables:
trigger: '{{ trigger.id }}'
num: '{{ trigger[:2] }}'
reason: '{{ trigger.split(''-'')[1] }}'
- if:
- condition: template
value_template: '{% set active = ''input_boolean.tony_custom_meds_tracker_''
+ num %}
{{ is_state(active,''on'') }}'
alias: Check tracker
then:
- if:
- condition: template
value_template: '{{ reason == ''notify'' }}'
alias: Is this a notification
then:
- service: input_boolean.turn_off
data: {}
target:
entity_id: '{{ ''input_boolean.tony_custom_meds_taken_'' + num }}'
alias: Turn off "taken" boolean
alias: Turn off "taken" boolean if this is a notification
- service: script.tony_custom_meds
data:
num: '{{ num }}'
reason: '{{ reason }}'
alias: Run custom meds script
alias: Run custom meds script if tracker is active
mode: parallel
max: 10

View File

@ -10,6 +10,12 @@ input_boolean:
tony_night_meds_taken:
name: Tony Night Meds Taken
icon: mdi:medication
tony_custom_meds_tracker_p1:
name: Tony Custom Meds Tracker P1
icon: mdi:medication
tony_custom_meds_taken_p1:
name: Tony Custom Meds Taken P1
icon: mdi:medication
input_datetime:
tony_streaming_start_time:
@ -37,6 +43,39 @@ input_datetime:
has_date: false
has_time: true
icon: mdi:medication
tony_custom_meds_taken_p1:
name: Tony Custom Meds Taken P1
has_date: true
has_time: true
icon: mdi:medication
tony_custom_meds_notify_p1:
name: Tony Custom Meds Notify P1
has_date: false
has_time: true
icon: mdi:medication
input_number:
tony_custom_meds_interval_p1:
name: Tony Custom Meds Interval P1
min: 0
max: 24
step: 1
icon: mdi:medication
input_text:
tony_custom_med_name_p1:
name: Tony Custom Med Name P1
icon: mdi:medication
input_select:
tony_custom_meds_type_p1:
name: Tony Custom Meds Type P1
options:
- Wakeup
- Bedtime
- Other Time
- Interval
icon: mdi:medication
sensor:
- platform: rest

View File

@ -2015,3 +2015,114 @@ timer_modify:
entity_id: '{{ timer }}'
data:
duration: '{{ modify }}'
tony_custom_meds:
alias: Tony Custom Meds
sequence:
- variables:
reason: '{{ reason }}'
num: '{{ num }}'
active: '{{ ''input_boolean.tony_custom_meds_tracker_'' + num }}'
taken: '{{ ''input_boolean.tony_custom_meds_taken_'' + num }}'
taken_at: '{{ ''input_datetime.tony_custom_meds_taken_'' + num }}'
notify_at: '{{ ''input_datetime.tony_custom_meds_notify_'' + num }}'
type: '{{ states(''input_select.tony_custom_meds_type_'' + num) }}'
name: '{{ states(''input_text.tony_custom_med_name_'' + num) }}'
interval: '{{ states(''input_number.tony_custom_meds_interval_'' + num) }}'
tag: '{{ ''tony-custom-meds-'' + num }}'
alias: Set Variables
- choose:
- conditions:
- condition: template
value_template: '{{ reason == ''notify'' }}'
alias: Notify
sequence:
- service: script.text_notify
data:
who: tony
type: alert
title: '{{ name + '' Tracker'' }}'
message: You need to take your {{ name }}
tag: '{{ tag }}'
alias: Send text notification
- wait_for_trigger:
- platform: state
entity_id:
- person.tony_stork
id: left
alias: Left
from: home
- platform: template
value_template: '{{ is_state(taken,''on'') }}'
alias: Manual
id: manual
timeout: 00:30:00
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: '{{ wait.trigger.id in [''manual'',''left''] }}'
alias: Manual or Left
sequence:
- stop: Automation cancelled
- conditions:
- condition: template
value_template: '{{ wait.trigger == ''none'' or wait.trigger.idx is undefined
}}'
alias: None or undefined
sequence:
- service: script.text_notify
data:
who: tony
type: alert
message: clear_notification
tag: '{{ tag }}'
alias: Clear Notification
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.tony_custom_meds_notify_p1
data:
datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,1)
}}
'
alias: Reset notification time
alias: Choose depending on the wait trigger
- conditions:
- condition: template
value_template: '{{ reason == ''taken'' }}'
alias: Taken
sequence:
- service: input_datetime.set_datetime
target:
entity_id: '{{ taken_at }}'
data:
datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0)
}}
'
alias: Set time the meds were taken
- if:
- condition: template
value_template: '{{ type == ''Interval'' }}'
alias: Is it an interval med?
then:
- service: input_datetime.set_datetime
target:
entity_id: '{{ notify_at }}'
data:
datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(interval)
}}
'
alias: Set notification for next dose
alias: If an interval med, then set time for next dose
- service: script.text_notify
data:
who: tony
type: alert
message: clear_notification
tag: '{{ tag }}'
alias: Clear Notification
alias: Routing
icon: mdi:medication
mode: parallel