From ee1620b9b1be1020527f8f502b804853c758c45a Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sun, 4 Aug 2024 14:36:25 -0400 Subject: [PATCH] Implement new trackers for K #205 --- automations.yaml | 294 ++++++++++++++++++++++++++++++++++----- packages/kallen.yaml | 10 +- scripts.yaml | 318 ++++++++++++++----------------------------- 3 files changed, 369 insertions(+), 253 deletions(-) diff --git a/automations.yaml b/automations.yaml index 19b2908..5554641 100644 --- a/automations.yaml +++ b/automations.yaml @@ -4681,26 +4681,34 @@ mode: restart - id: '1710611198911' alias: Kallen Meds Handler - description: Make sure Kallen has taken his meds in the morning and at night + description: Handles the scheduling of medication reminders for Kallen trigger: + - platform: time_pattern + minutes: /30 + id: trigger30 + alias: Every 30 minutes - platform: time at: input_datetime.kallen_morning_meds_notify - id: wakeup + id: morning-notify alias: Morning Notify - platform: time at: input_datetime.kallen_night_meds_notify - id: sleep + id: night-notify alias: Night Notify - platform: state - entity_id: input_boolean.kallen_morning_meds_taken + entity_id: + - input_boolean.kallen_morning_meds_taken to: 'on' id: boolean-morning alias: Morning Taken + from: 'off' - platform: state - entity_id: input_boolean.kallen_night_meds_taken - to: 'on' + entity_id: + - input_boolean.kallen_night_meds_taken id: boolean-night alias: Night Taken + from: 'off' + to: 'on' condition: - condition: state entity_id: input_boolean.kallen_overnight @@ -4709,90 +4717,133 @@ action: - alias: Routing choose: + - conditions: + - condition: trigger + id: + - trigger30 + sequence: + - alias: Check morning reminder switch + if: + - condition: state + entity_id: input_boolean.kallen_morning_meds_reminder + state: 'on' + alias: Morning meds reminder needed + then: + - service: script.kallen_morning_meds + metadata: {} + data: {} + alias: Run morning meds notification script + - alias: Check night reminder switch + if: + - condition: state + entity_id: input_boolean.kallen_night_meds_reminder + state: 'on' + alias: Night meds reminder needed + then: + - service: script.kallen_night_meds + metadata: {} + data: {} + alias: Run night meds notification script + alias: Every 30 minutes - conditions: - condition: and conditions: - condition: trigger - id: wakeup + id: morning-notify - condition: state entity_id: input_boolean.kallen_morning_meds_taken state: 'off' alias: Morning Notify sequence: - - service: counter.increment + - service: input_boolean.turn_on metadata: {} data: {} target: - entity_id: counter.kallen_morning_meds_reminder_count - alias: Increment counter - - service: script.turn_on - target: - entity_id: script.kallen_morning_meds + entity_id: input_boolean.kallen_morning_meds_reminder + alias: Activate morning reminders + - service: script.kallen_morning_meds + metadata: {} data: {} - alias: Run morning meds script + alias: Run morning meds notification script - conditions: - condition: and conditions: - condition: trigger - id: sleep + id: + - night-notify - condition: state entity_id: input_boolean.kallen_night_meds_taken state: 'off' alias: Night Notify sequence: - - alias: Increment counter - service: counter.increment + - alias: Activate night reminders + service: input_boolean.turn_on metadata: {} data: {} target: - entity_id: counter.kallen_night_meds_reminder_count - - service: script.turn_on - target: - entity_id: script.kallen_night_meds + entity_id: input_boolean.kallen_night_meds_reminder + - service: script.kallen_night_meds + metadata: {} data: {} - alias: Run night meds script + alias: Run night meds notification script - conditions: - condition: trigger id: boolean-morning alias: Morning Taken sequence: - - service: counter.reset - metadata: {} - data: {} - target: - entity_id: counter.kallen_morning_meds_reminder_count - alias: Reset counter - service: input_datetime.set_datetime target: entity_id: input_datetime.kallen_morning_meds_taken data: - datetime: '{% from ''time.jinja'' import current_time %} {{ current_time(''datetime'',24) + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0) }} ' alias: Set time morning meds were taken + - service: input_boolean.turn_off + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_morning_meds_reminder + alias: Deactivate morning reminders + - service: script.text_notify + metadata: {} + data: + type: alert + who: kallen + message: clear_notification + tag: kallen-left-meds + alias: Clear kallen-left-meds notification tag - conditions: - condition: trigger id: boolean-night alias: Night Taken sequence: - - alias: Reset counter - service: counter.reset - metadata: {} - data: {} - target: - entity_id: counter.kallen_night_meds_reminder_count - service: input_datetime.set_datetime target: entity_id: input_datetime.kallen_night_meds_taken data: - datetime: '{% from ''time.jinja'' import current_time %} {{ current_time(''datetime'',24) + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0) }} ' alias: Set time night meds were taken + - alias: Deactivate night reminders + service: input_boolean.turn_off + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_night_meds_reminder + - service: script.text_notify + metadata: {} + data: + type: alert + who: kallen + message: clear_notification + tag: kallen-left-meds + alias: Clear kallen-left-meds notification tag mode: parallel - max: 4 + max: 12 - id: '1711657679853' alias: Basement Briefing description: '' @@ -5760,3 +5811,172 @@ tag: tina-left-meds mode: queued max: 10 +- id: '1722387020007' + alias: Kallen Meds Cleanup + description: Handles the setting/clearing of medication configs for Kallen + trigger: + - platform: state + entity_id: + - input_boolean.kallen_morning_meds_reminder + from: 'on' + to: 'off' + id: morning-reminders-off + alias: Morning reminders off + - alias: Night reminders off + platform: state + entity_id: + - input_boolean.kallen_night_meds_reminder + from: 'on' + to: 'off' + id: night-reminders-off + - platform: event + event_type: ios.notification_action_fired + event_data: + actionName: KALLEN_MORNING_MEDS_TAKEN + id: morning-taken + alias: Morning taken + - alias: Night taken + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: KALLEN_NIGHT_MEDS_TAKEN + id: night-taken + - alias: Morning skipped + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: KALLEN_MORNING_MEDS_SKIPPED + id: morning-skipped + - alias: Night skipped + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: KALLEN_NIGHT_MEDS_SKIPPED + id: night-skipped + - platform: state + entity_id: + - person.kallen_stork + from: home + id: left + alias: Left + condition: [] + action: + - alias: Routing + choose: + - conditions: + - condition: trigger + id: + - morning-reminders-off + alias: Morning Reminders Off + sequence: + - service: counter.reset + metadata: {} + data: {} + target: + entity_id: counter.kallen_morning_meds_reminder_count + alias: Reset morning reminder count + - service: script.text_notify + data: + type: alert + who: kallen + message: clear_notification + tag: kallen-morning-meds + alias: Clear morning notification + - conditions: + - condition: trigger + id: + - night-reminders-off + alias: Night reminders off + sequence: + - alias: Reset night reminder count + service: counter.reset + metadata: {} + data: {} + target: + entity_id: counter.kallen_night_meds_reminder_count + - service: script.text_notify + data: + type: alert + who: kallen + message: clear_notification + tag: kallen-night-meds + alias: Clear night notification + - conditions: + - condition: trigger + id: + - morning-taken + alias: Morning taken + sequence: + - service: input_boolean.turn_on + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_morning_meds_taken + alias: Turn on morning meds taken + - conditions: + - condition: trigger + id: + - night-taken + alias: Night taken + sequence: + - service: input_boolean.turn_on + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_night_meds_taken + alias: Turn on night meds taken + - conditions: + - condition: trigger + id: + - morning-skipped + alias: Morning skipped + sequence: + - service: input_boolean.turn_off + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_morning_meds_reminder + alias: Deactivate morning reminders + - conditions: + - condition: trigger + id: + - night-skipped + alias: Night skipped + sequence: + - service: input_boolean.turn_off + metadata: {} + data: {} + target: + entity_id: input_boolean.kallen_night_meds_reminder + alias: Deactivate night reminders + - conditions: + - condition: trigger + id: + - left + alias: Left + sequence: + - alias: Send critical TTS notification if any meds aren't taken + if: + - alias: Check if any reminders are active + condition: or + conditions: + - condition: state + entity_id: input_boolean.kallen_morning_meds_reminder + state: 'on' + alias: Morning meds reminder active + - condition: state + entity_id: input_boolean.kallen_night_meds_reminder + state: '' + alias: Night meds reminder active + then: + - alias: Send critical TTS notification + service: script.text_notify + metadata: {} + data: + type: critical + who: kallen + title: EYYO + message: YOU FORGOT TO TAKE YOUR MEDS!!!!! + tag: kallen-left-meds + mode: queued + max: 10 diff --git a/packages/kallen.yaml b/packages/kallen.yaml index bd117c6..9fa1576 100644 --- a/packages/kallen.yaml +++ b/packages/kallen.yaml @@ -16,9 +16,15 @@ input_boolean: kallen_late_bedtime: name: Kallen Late Bedtime icon: mdi:weather-night + kallen_morning_meds_reminder: + name: Kallen Morning Meds Reminder + icon: mdi:medication kallen_morning_meds_taken: name: Kallen Morning Meds Taken icon: mdi:medication + kallen_night_meds_reminder: + name: Kallen Night Meds Reminder + icon: mdi:medication kallen_night_meds_taken: name: Kallen Night Meds Taken icon: mdi:medication @@ -67,12 +73,12 @@ input_datetime: icon: mdi:medication kallen_morning_meds_notify: name: Kallen Morning Meds Notify - has_date: false + has_date: true has_time: true icon: mdi:medication kallen_night_meds_notify: name: Kallen Night Meds Notify - has_date: false + has_date: true has_time: true icon: mdi:medication kallen_alarm_clock: diff --git a/scripts.yaml b/scripts.yaml index ff03b47..b225b31 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -1717,35 +1717,19 @@ tony_night_meds: minutes: 0 seconds: 5 milliseconds: 0 - - alias: Send night notifications via text, and TTS if needed - parallel: - - alias: Send text notification - service: script.text_notify - data: - who: tony - type: alert - title: Night Meds - message: You need to take your night meds - tag: tony-night-meds - actions: - - action: TONY_NIGHT_MEDS_TAKEN - title: Taken - - action: TONY_NIGHT_MEDS_SKIPPED - title: Skip - - alias: Send TTS if reminders > 2 - if: - - condition: numeric_state - entity_id: counter.tony_night_meds_reminder_count - above: 2 - alias: When reminder count > 2 - then: - - service: script.speech_engine - data: - who: common_areas - type: alert - message: Tony, you need to take your night meds. This is reminder number - {{ states('counter.tony_night_meds_reminder_count') }} for today. - alias: Send TTS notification + - alias: Send text notification + service: script.text_notify + data: + who: tony + type: alert + title: Night Meds + message: You need to take your night meds + tag: tony-night-meds + actions: + - action: TONY_NIGHT_MEDS_TAKEN + title: Taken + - action: TONY_NIGHT_MEDS_SKIPPED + title: Skip tony_stream_today: alias: Tony Stream Today sequence: @@ -2304,203 +2288,109 @@ tony_tylenol: mode: queued icon: mdi:medication max: 10 -'1710612011154': +kallen_morning_meds: alias: Kallen Morning Meds sequence: - - service: script.text_notify - data: - who: kallen - type: alert - title: Morning Meds - message: You need to take your morning meds. Go to mom or dad to confirm. - tag: kallen-morning-meds-self - - service: script.text_notify - data: - who: parents - type: alert - title: Morning Meds - message: Kallen needs to take his morning meds - tag: kallen-morning-meds-parents - actions: - - action: KALLEN_MORNING_MEDS_TAKEN - title: Taken - - action: KALLEN_MORNING_MEDS_SKIPPED - title: Skip - - action: KALLEN_MORNING_MEDS_ASK_LATER - title: Ask Later - - wait_for_trigger: - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_MORNING_MEDS_TAKEN - id: taken - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_MORNING_MEDS_SKIPPED - id: skipped - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_MORNING_MEDS_ASK_LATER - id: ask-later - - platform: state - entity_id: person.kallen_stork - from: home - id: left - - platform: state - entity_id: input_boolean.kallen_morning_meds_taken - to: 'on' - id: manual - timeout: 00:10:00 - continue_on_timeout: true - - choose: - - conditions: - - condition: template - value_template: '{{ wait.trigger.id in [''taken'',''manual''] }}' - sequence: - - service: input_boolean.turn_on - target: - entity_id: input_boolean.kallen_morning_meds_taken - data: {} - - conditions: - - condition: template - value_template: '{{ wait.trigger.id == ''ask-later'' }}' - sequence: - - service: input_datetime.set_datetime - target: - entity_id: input_datetime.kallen_morning_meds_notify - data: - datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,5) - }} - - ' - - conditions: - - condition: template - value_template: '{{ wait.trigger.id == ''left'' or wait.trigger == ''none'' - or wait.trigger.idx is undefined }}' - sequence: - - if: - - condition: state - entity_id: person.kallen_stork - state: home - then: - - service: input_datetime.set_datetime - target: - entity_id: input_datetime.kallen_morning_meds_notify - data: - datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,1) - }} - - ' - - service: script.text_notify - data: - type: alert - who: kallen - message: clear_notification - tag: kallen-morning-meds-parents - - service: script.text_notify - data: - type: alert - who: kallen - message: clear_notification - tag: kallen-morning-meds-self + - service: counter.increment + metadata: {} + data: {} + target: + entity_id: counter.kallen_morning_meds_reminder_count + alias: Increment morning reminder counter + - alias: Clear previous morning notifications + parallel: + - service: script.text_notify + data: + type: alert + who: parents + message: clear_notification + tag: kallen-morning-meds-parents + alias: Clear for parents + - service: script.text_notify + data: + type: alert + who: kallen + message: clear_notification + tag: kallen-morning-meds-self + alias: Clear for Kallen + - delay: + hours: 0 + minutes: 0 + seconds: 5 + milliseconds: 0 + - alias: Send text notifications + parallel: + - alias: Send to parents + service: script.text_notify + data: + who: parents + type: alert + title: Morning Meds + message: Kallen needs to take his morning meds + tag: kallen-morning-meds-parents + actions: + - action: KALLEN_MORNING_MEDS_TAKEN + title: Taken + - action: KALLEN_MORNING_MEDS_SKIPPED + title: Skip + - service: script.text_notify + data: + who: kallen + type: alert + title: Morning Meds + message: You need to take your morning meds. Go to mom or dad to confirm. + tag: kallen-morning-meds-self + alias: Send to Kallen icon: mdi:medication mode: restart -'1710612164315': +kallen_night_meds: alias: Kallen Night Meds sequence: - - service: script.text_notify - data: - who: kallen - type: alert - title: Night Meds - message: You need to take your night meds (melatonin) - tag: kallen-night-meds - actions: - - action: KALLEN_NIGHT_MEDS_TAKEN - title: Taken - - action: KALLEN_NIGHT_MEDS_SKIPPED - title: Skip - - action: KALLEN_NIGHT_MEDS_ASK_LATER - title: Ask Later - - service: script.text_notify - data: - who: "{% if states('person.christina_stork') in ['Bob Evans','BobEvans'] %}\n - \ tony\n{% else %}\n parents\n{% endif %}\n" - type: alert - title: Night Meds - message: Kallen needs to take his night meds (melatonin) - tag: kallen-night-meds - actions: - - action: KALLEN_NIGHT_MEDS_TAKEN - title: Taken - - action: KALLEN_NIGHT_MEDS_SKIPPED - title: Skip - - action: KALLEN_NIGHT_MEDS_ASK_LATER - title: Ask Later - - wait_for_trigger: - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_NIGHT_MEDS_TAKEN - id: taken - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_NIGHT_MEDS_SKIPPED - id: skipped - - platform: event - event_type: ios.notification_action_fired - event_data: - actionName: KALLEN_NIGHT_MEDS_ASK_LATER - id: ask-later - - platform: state - entity_id: input_boolean.kallen_night_meds_taken - to: 'on' - id: manual - timeout: 00:05:00 - continue_on_timeout: true - - choose: - - conditions: - - condition: template - value_template: '{{ wait.trigger.id in [''taken'',''manual''] }}' - sequence: - - service: input_boolean.turn_on - target: - entity_id: input_boolean.kallen_night_meds_taken - data: {} - - conditions: - - condition: template - value_template: '{{ wait.trigger.id == ''ask-later'' }}' - sequence: - - service: input_datetime.set_datetime - target: - entity_id: input_datetime.kallen_night_meds_notify - data: - datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,15) - }} - - ' - - conditions: - - condition: template - value_template: '{{ wait.trigger == ''none'' or wait.trigger.idx is undefined - }}' - sequence: - - service: input_datetime.set_datetime - target: - entity_id: input_datetime.kallen_night_meds_notify - data: - datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,1) - }} - - ' + - service: counter.increment + metadata: {} + data: {} + alias: Increment night reminder counter - service: script.text_notify data: type: alert who: all message: clear_notification tag: kallen-night-meds + alias: Clear previous night notification + - delay: + hours: 0 + minutes: 0 + seconds: 5 + milliseconds: 0 + - parallel: + - service: script.text_notify + data: + who: "{% if states('person.christina_stork') in ['Bob Evans','BobEvans'] %}\n + \ tony\n{% else %}\n parents\n{% endif %}\n" + type: alert + title: Night Meds + message: Kallen needs to take his night meds (melatonin) + tag: kallen-night-meds + actions: + - action: KALLEN_NIGHT_MEDS_TAKEN + title: Taken + - action: KALLEN_NIGHT_MEDS_SKIPPED + title: Skip + alias: Send to parents + - alias: Send to Kallen + service: script.text_notify + data: + who: kallen + type: alert + title: Night Meds + message: You need to take your night meds (melatonin) + tag: kallen-night-meds + actions: + - action: KALLEN_NIGHT_MEDS_TAKEN + title: Taken + - action: KALLEN_NIGHT_MEDS_SKIPPED + title: Skip + alias: Send text notifications icon: mdi:medication mode: restart reset_annc_switches: