From 678b028737d4903156f5df698320cbc6dd59cd4e Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Mon, 9 Oct 2023 18:32:52 -0400 Subject: [PATCH 1/2] Initial concept for sleep awareness --- automations.yaml | 72 +++++++++++++++++++++ packages/announcements.yaml | 8 +++ packages/tina.yaml | 3 + packages/tony.yaml | 3 + templates/speech/master_bedroom_wakeup.yaml | 51 +++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 templates/speech/master_bedroom_wakeup.yaml diff --git a/automations.yaml b/automations.yaml index 5c739c2..3b2884d 100644 --- a/automations.yaml +++ b/automations.yaml @@ -2874,3 +2874,75 @@ alias: TTS notification alias: After wait completed mode: single +- id: '1696884613752' + alias: Tony Sleep Handling + description: Awareness of when Tony is asleep or wakes up + trigger: + - platform: event + event_type: wakeup_event + event_data: + who: tony + type: alarm + context: + user_id: + - c3909d27048140729f002aaef0391775 + alias: Any Alarm + id: wake-alarm + - platform: event + event_type: wakeup_event + event_data: + who: tony + type: wakeup + context: + user_id: + - c3909d27048140729f002aaef0391775 + alias: Wakeup + id: wake-sched + - platform: zone + entity_id: person.tony_stork + zone: zone.home + event: leave + alias: Leave Home + id: wake-leave + - platform: conversation + command: Tony is awake + id: wake-sentence + alias: Sentence + - platform: state + entity_id: + - binary_sensor.tony_s_iphone_focus + from: 'on' + to: 'off' + for: + hours: 0 + minutes: 0 + seconds: 30 + alias: Focus off + id: wake-focus + - platform: state + entity_id: + - binary_sensor.tony_desktop_on + from: 'off' + to: 'on' + alias: Computer + id: wake-computer + condition: [] + action: + - variables: + trigger: '{{ trigger.id }}' + type: '{{ trigger.split(''-'')[0] }}' + reason: '{{ trigger.split(''-'')[1] }}' + alias: Define variables + - choose: + - conditions: + - condition: template + value_template: '{{ type == ''wake'' }}' + alias: Wakeup + sequence: + - service: input_boolean.turn_on + data: {} + target: + entity_id: input_boolean.tony_awake + alias: Set context that I am awake + alias: Routing + mode: restart diff --git a/packages/announcements.yaml b/packages/announcements.yaml index 914086e..ad3c5a6 100644 --- a/packages/announcements.yaml +++ b/packages/announcements.yaml @@ -250,6 +250,14 @@ script: message: !include ../templates/speech/welcome_home.yaml mode: restart + master_bedroom_wakeup_briefing: + alias: Master Bedroom Wakeup Briefing + sequence: + - service: script.speech_engine + data: + who: "{{ who|default('master_bedroom') }}" + message: !include ../templates/speech/master_bedroom_wakeup.yaml + birthday_announcement: alias: 'Birthday Announcement' sequence: diff --git a/packages/tina.yaml b/packages/tina.yaml index 4d01d92..d47ceac 100644 --- a/packages/tina.yaml +++ b/packages/tina.yaml @@ -13,6 +13,9 @@ input_boolean: tina_night_meds_taken: name: Tina Night Meds Taken icon: mdi:medication + tina_awake: + name: Tina Awake + icon: mdi:eye-check input_datetime: tina_workday_start: diff --git a/packages/tony.yaml b/packages/tony.yaml index 52cb8e2..341bc1d 100644 --- a/packages/tony.yaml +++ b/packages/tony.yaml @@ -16,6 +16,9 @@ input_boolean: tony_custom_meds_taken_p1: name: Tony Custom Meds Taken P1 icon: mdi:medication + tony_awake: + name: Tony Awake + icon: mdi:eye-check input_datetime: tony_streaming_start_time: diff --git a/templates/speech/master_bedroom_wakeup.yaml b/templates/speech/master_bedroom_wakeup.yaml new file mode 100644 index 0000000..a55489e --- /dev/null +++ b/templates/speech/master_bedroom_wakeup.yaml @@ -0,0 +1,51 @@ +> + {# Master Bedroom Wakeup #} + {%- macro getReport() -%} + {% from 'speech.jinja' import greeting, today_is %} + {% from 'status.jinja' import tonyStatusReport, tinaStatusReport, kallenStatusReport, emmaStatusReport %} + {% from 'weather.jinja' import weatherReport %} +

+ {{ greeting('date') }} +

+ +

+ {{ today_is() }} +

+ +

+ {{ weatherReport('alerts','tts','day') }} + + {{ tonyStatusReport('full','tts') }} + + {{ tinaStatusReport('full','tts') }} + + {{ kallenStatusReport('full','tts') }} + + {{ emmaStatusReport('full','tts') }} +

+ +

+ Do not forget to set the living room thermostat to your desired daytime temperature! +

+ +

+ {% if is_state('input_boolean.briefing_extras','on') %} + "And now we have the following extra information to pass along. {{ states('input_text.briefing_extras') }} " + {% endif %} +

+ + {%- endmacro -%} + + {# a macro that removes all newline characters, empty spaces, and returns formatted text #} + {%- macro cleanup(data) -%} + {%- for item in data.split("\n") if item | trim != "" -%} + {{ item | trim }} {% endfor -%} + {%- endmacro -%} + + {# a macro to call all macros :) #} + {%- macro mother_of_all_macros() -%} + {{ getReport() }} + {%- endmacro -%} + + {# Call the macro #} + {{- cleanup(mother_of_all_macros()) -}} From c27f080cabf59c3b6850aa9f6ffe95493b38d09a Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 10 Oct 2023 12:31:42 -0400 Subject: [PATCH 2/2] Move master bedroom wakeup briefing to master bedroom yaml package --- packages/announcements.yaml | 8 -------- packages/master_bedroom.yaml | 11 ++++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/announcements.yaml b/packages/announcements.yaml index ad3c5a6..914086e 100644 --- a/packages/announcements.yaml +++ b/packages/announcements.yaml @@ -250,14 +250,6 @@ script: message: !include ../templates/speech/welcome_home.yaml mode: restart - master_bedroom_wakeup_briefing: - alias: Master Bedroom Wakeup Briefing - sequence: - - service: script.speech_engine - data: - who: "{{ who|default('master_bedroom') }}" - message: !include ../templates/speech/master_bedroom_wakeup.yaml - birthday_announcement: alias: 'Birthday Announcement' sequence: diff --git a/packages/master_bedroom.yaml b/packages/master_bedroom.yaml index a19aeaf..e0dce40 100644 --- a/packages/master_bedroom.yaml +++ b/packages/master_bedroom.yaml @@ -156,4 +156,13 @@ script: manual_control: false entity_id: switch.adaptive_lighting_master_bedroom -# TODO: Figure out which actions to move here, and which ones to keep in Node-RED \ No newline at end of file +# TODO: Figure out which actions to move here, and which ones to keep in Node-RED + + master_bedroom_wakeup_briefing: + alias: Master Bedroom Wakeup Briefing + mode: single + sequence: + - service: script.speech_engine + data: + who: "{{ who|default('master_bedroom') }}" + message: !include ../templates/speech/master_bedroom_wakeup.yaml \ No newline at end of file