diff --git a/automations.yaml b/automations.yaml index aa7ffc5..198fbbf 100644 --- a/automations.yaml +++ b/automations.yaml @@ -2360,12 +2360,16 @@ mode: single - id: '1696288846954' alias: Tony Meds Handler - description: Make sure Tony has taken his meds in the morning and at night + description: Make sure Tony has taken his meds at the scheduled times trigger: - platform: time at: input_datetime.tony_morning_meds_notify id: morning-notify alias: Morning Notify + - platform: time + at: input_datetime.tony_afternoon_meds_notify + id: afternoon-notify + alias: Afternoon Notify - platform: time at: input_datetime.tony_night_meds_notify id: night-notify @@ -2377,6 +2381,13 @@ id: boolean-morning alias: Morning Taken from: 'off' + - platform: state + entity_id: + - input_boolean.tony_afternoon_meds_taken + id: boolean-afternoon + from: 'off' + to: 'on' + alias: Afternoon Taken - platform: state entity_id: - input_boolean.tony_night_meds_taken @@ -2393,7 +2404,8 @@ to: 'off' condition: [] action: - - choose: + - alias: Routing + choose: - conditions: - condition: and conditions: @@ -2409,6 +2421,20 @@ entity_id: script.tony_morning_meds data: {} alias: Run morning meds script + - conditions: + - alias: Afternoon Notify + condition: and + conditions: + - condition: trigger + id: + - afternoon-notify + - condition: state + entity_id: input_boolean.tony_afternoon_meds_taken + state: 'off' + sequence: + - service: script.tony_afternoon_meds + data: {} + alias: Run afternoon meds script - conditions: - condition: and conditions: @@ -2439,6 +2465,30 @@ ' alias: Set time morning meds were taken + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tony_afternoon_meds_notify + data: + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(6) + }} + + ' + alias: Adjust afternoon meds reminder + - conditions: + - condition: trigger + id: + - boolean-afternoon + alias: Afternoon Taken + sequence: + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tony_afternoon_meds_taken + data: + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0) + }} + + ' + alias: Set time afternoon meds were taken - conditions: - condition: trigger id: boolean-night @@ -2467,7 +2517,6 @@ ' alias: Set time to start notifying for morning meds - alias: Routing mode: parallel max: 10 - id: '1696288939707' @@ -2564,12 +2613,6 @@ value: '{{ states(''input_number.tomorrow_corrected_high_temp'') | int }}' target: entity_id: input_number.today_corrected_high_temp - - conditions: - - condition: trigger - id: audible-off - sequence: - - service: script.reset_annc_switches - data: {} - service: input_number.set_value target: entity_id: @@ -2578,6 +2621,12 @@ - input_number.basement_studio_door_opened_today data: value: 0 + - conditions: + - condition: trigger + id: audible-off + sequence: + - service: script.reset_annc_switches + data: {} - conditions: - condition: trigger id: school-end @@ -2603,6 +2652,7 @@ - input_boolean.kallen_night_meds_taken - input_boolean.tony_morning_meds_taken - input_boolean.tina_morning_meds_taken + - input_boolean.tony_afternoon_meds_taken data: {} - conditions: - condition: trigger diff --git a/custom_templates/status.jinja b/custom_templates/status.jinja index 06b5c69..4fcfef7 100644 --- a/custom_templates/status.jinja +++ b/custom_templates/status.jinja @@ -172,7 +172,7 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% endif %} {% endmacro %} -{% macro tony_night_meds(type,method) %} +{% macro tony_afternoon_meds(type,method) %} {% set streamBlock = twitchStreamInfo(type,method) | trim == '' %} {% set morningBlock = tony_morning_meds(type,method) | trim != '' %} {% if type == 'meds' or streamBlock == true or morningBlock == true %} @@ -180,6 +180,33 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% else %} {% set identTony = 'He' %} {% endif %} +{% if is_state('input_boolean.tony_afternoon_meds_taken','on') and is_state('input_boolean.tony_awake','on') %} + {{ identTony }} took his afternoon meds at {{ input_datetime_read('input_datetime.tony_afternoon_meds_taken') | trim }}. +{% elif is_state('input_boolean.tony_afternoon_meds_taken','off') and ct >= 61200 %} + {{ identTony }} has not taken his afternoon meds. + {% if ct < state_attr('input_datetime.tony_afternoon_meds_notify','timestamp') | int %} + {% if method == 'tts' %} + {{ ['He has a reminder scheduled for', + 'Rest assured that I will pester him mercilessly about this, starting at', + 'This is absolutely essential, and I will remind him to do it at', + 'Since nobody including Tony himself likes him without his meds, I will remind him at', + ] | random }} {{ input_datetime_read('input_datetime.tony_afternoon_meds_notify') | trim }}. + {% else %} + He will be reminded at {{ input_datetime_read('input_datetime.tony_afternoon_meds_notify') | trim }}. + {% endif %} + {% endif %} +{% endif %} +{% endmacro %} + +{% macro tony_night_meds(type,method) %} +{% set streamBlock = twitchStreamInfo(type,method) | trim == '' %} +{% set morningBlock = tony_morning_meds(type,method) | trim != '' %} +{% set afternoonBlock = tony_afternoon_meds(type,method) | trim != '' %} +{% if type == 'meds' or streamBlock == true or (morningBlock == true and afternoonBlock == true) %} + {% set identTony = 'Tony' %} +{% else %} + {% set identTony = 'He' %} +{% endif %} {% if is_state('input_boolean.tony_night_meds_taken','on') and (is_state('binary_sensor.overnight','on') or ct < 43200) %} {{ identTony }} took his night meds at {{ input_datetime_read('input_datetime.tony_night_meds_taken') | trim }}. {% elif is_state('input_boolean.tony_night_meds_taken','off') and is_state('binary_sensor.overnight','on') %} @@ -198,6 +225,7 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% macro medReportTony(type,method) %} {{ tony_morning_meds(type,method) }} +{{ tony_afternoon_meds(type,method) }} {{ tony_night_meds(type,method) }} {% endmacro %} diff --git a/packages/scheduling.yaml b/packages/scheduling.yaml index 70f4066..ada1703 100644 --- a/packages/scheduling.yaml +++ b/packages/scheduling.yaml @@ -567,6 +567,11 @@ script: entity_id: input_datetime.tony_morning_meds_notify data: time: "{{ states('input_datetime.master_bedroom_wakeup') }}" + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tony_afternoon_meds_notify + data: + time: "{{ (state_attr('input_datetime.master_bedroom_wakeup','timestamp') | int + 21600) | timestamp_custom('%H:%M', false)}}" - service: input_datetime.set_datetime target: entity_id: input_datetime.tina_morning_meds_notify diff --git a/packages/tony.yaml b/packages/tony.yaml index 341bc1d..fed6017 100644 --- a/packages/tony.yaml +++ b/packages/tony.yaml @@ -7,6 +7,9 @@ input_boolean: tony_morning_meds_taken: name: Tony Morning Meds Taken icon: mdi:medication + tony_afternoon_meds_taken: + name: Tony Afternoon Meds Taken + icon: mdi:medication tony_night_meds_taken: name: Tony Night Meds Taken icon: mdi:medication @@ -31,6 +34,11 @@ input_datetime: has_date: true has_time: true icon: mdi:medication + tony_afternoon_meds_taken: + name: Tony Afternoon Meds Taken + has_date: true + has_time: true + icon: mdi:medication tony_night_meds_taken: name: Tony Night Meds Taken has_date: true @@ -41,6 +49,11 @@ input_datetime: has_date: false has_time: true icon: mdi:medication + tony_afternoon_meds_notify: + name: Tony Afternoon Meds Notify + has_date: false + has_time: true + icon: mdi:medication tony_night_meds_notify: name: Tony Night Meds Notify has_date: false diff --git a/scripts.yaml b/scripts.yaml index 044f0e0..183c235 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -2175,3 +2175,109 @@ tony_custom_meds: alias: Routing icon: mdi:medication mode: parallel +tony_afternoon_meds: + alias: Tony Afternoon Meds + sequence: + - service: script.text_notify + data: + who: tony + type: alert + title: Afternoon Meds + message: You need to take your afternoon meds + tag: tony-afternoon-meds + actions: + - action: TONY_AFTERNOON_MEDS_TAKEN + title: Taken + - action: TONY_AFTERNOON_MEDS_SKIPPED + title: Skip + - action: TONY_AFTERNOON_MEDS_ASK_LATER + title: Ask Later + - wait_for_trigger: + - alias: Taken + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: TONY_AFTERNOON_MEDS_TAKEN + id: taken + - alias: Skipped + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: TONY_AFTERNOON_MEDS_SKIPPED + id: skipped + - alias: Ask Later + platform: event + event_type: ios.notification_action_fired + event_data: + actionName: TONY_AFTERNOON_MEDS_ASK_LATER + id: ask-later + - platform: state + entity_id: person.tony_stork + from: home + id: left + alias: Left + - alias: Manual + platform: state + entity_id: + - input_boolean.tony_afternoon_meds_taken + to: 'on' + id: manual + from: 'off' + timeout: 00:30:00 + continue_on_timeout: true + - choose: + - conditions: + - condition: template + value_template: '{{ wait.trigger.id in [''taken'',''manual''] }}' + alias: Taken, Manual + sequence: + - service: input_boolean.turn_on + data: {} + target: + entity_id: input_boolean.tony_afternoon_meds_taken + - conditions: + - condition: template + value_template: '{{ wait.trigger.id == ''ask-later'' }}' + alias: Ask Later + sequence: + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tony_afternoon_meds_notify + data: + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,30) + }} + + ' + - conditions: + - condition: template + value_template: '{{ wait.trigger.id == ''left'' }}' + alias: Left + sequence: + - service: script.text_notify + data: + who: tony + type: critical + title: HEY DUMBASS + message: YOU FORGOT TO TAKE YOUR AFTERNOON MEDS!!!!! + - conditions: + - condition: template + value_template: '{{ wait.trigger == ''none'' or wait.trigger.idx is undefined + }}' + alias: None or undefined + sequence: + - service: input_datetime.set_datetime + target: + entity_id: input_datetime.tony_afternoon_meds_notify + data: + datetime: '{% from ''time.jinja'' import set_datetime %} {{ set_datetime(0,1) + }} + + ' + - service: script.text_notify + data: + type: alert + who: tony + message: clear_notification + tag: tony-afternoon-meds + icon: mdi:medication + mode: restart