From ff2515874e30cab346818ba74e11ad6b6d825a92 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Tue, 7 Feb 2023 16:48:25 -0500 Subject: [PATCH] Birthday announcement script --- .gitignore | 1 + packages/announcements.yaml | 85 ++++++++++++++++++++++++++++++++- templates/speech/birthdays.yaml | 43 +++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 templates/speech/birthdays.yaml diff --git a/.gitignore b/.gitignore index e9db3f5..c69867f 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,7 @@ **.log* **alexa_auth **.corrupt* +**ages.yaml # exceptions !/appdaemon/apps/ diff --git a/packages/announcements.yaml b/packages/announcements.yaml index 7e4fa63..80f9636 100644 --- a/packages/announcements.yaml +++ b/packages/announcements.yaml @@ -318,4 +318,87 @@ script: data_template: who: living_room message: !include ../templates/speech/welcome_home.yaml - mode: restart \ No newline at end of file + mode: restart + + birthday_announcement: + alias: 'Birthday Announcement' + sequence: + - alias: "Save current light states" + service: scene.create + data: + scene_id: before_birthday_announcement + snapshot_entities: + - light.living_room_color_1 + - light.living_room_color_2 + - light.living_room_color_3 + - light.tina_desk_strip + - light.tina_lamp_side + - light.tina_lamp_top + - light.dining_room_lamp + - light.mud_room_overhead + - light.basement_led_strip_1 + - light.basement_tall_lamp + - light.basement_short_lamp + - light.basement_stairwell + - alias: "Save current adaptive states" + service: scene.create + data: + scene_id: before_birthday_announcement_adaptive + snapshot_entities: + - switch.adaptive_lighting_living_room + - switch.adaptive_lighting_tina_lamp + - switch.adaptive_lighting_basement_studio + - alias: "Give it time to make sure it saves" + delay: + seconds: 2 + - alias: "Turn off adaptive lighting" + service: switch.turn_off + target: + entity_id: + - switch.adaptive_lighting_living_room + - switch.adaptive_lighting_tina_lamp + - switch.adaptive_lighting_basement_studio + - alias: "Turn off non-color lights" + service: light.turn_off + target: + entity_id: + - light.dining_room_lamp + - light.mud_room_overhead + - alias: "Set color lights to purple" + service: light.turn_on + target: + entity_id: + - light.living_room_lights + - light.tina_lamp + - light.tina_desk_strip + - light.basement_studio_lights + data: + color_name: > + {% if is_state('sensor.anniversary_tony_s_birthday','0') %} + purple + {% elif is_state('sensor.anniversary_tina_s_birthday','0') %} + purple + {% elif is_state('sensor.anniversary_kallen_s_birthday','0') %} + red + {% elif is_state('sensor.anniversary_emmalynn_s_birthday','0') %} + pink + {% endif %} + - alias: "Read the announcement" + service: script.speech_engine + data: + who: everywhere + message: !include ../templates/speech/birthdays.yaml + - alias: "Give time for the announcement to complete" + delay: + seconds: 20 + - alias: "Restore previous light states" + service: scene.turn_on + target: + entity_id: scene.before_birthday_announcement + - alias: "Let the lights come up" + delay: + seconds: 3 + - alias: "Restore previous adaptive states" + service: scene.turn_on + target: + entity_id: scene.before_birthday_announcement_adaptive \ No newline at end of file diff --git a/templates/speech/birthdays.yaml b/templates/speech/birthdays.yaml new file mode 100644 index 0000000..9c9b5e6 --- /dev/null +++ b/templates/speech/birthdays.yaml @@ -0,0 +1,43 @@ +> + {# Birthdays #} + {%- macro getReport() -%} +

+ {{ [ + 'Attention household, I am told that there is a birthday among us!', + 'Ladies and gentlemen, boys and girls, gather round as we celebrate a birthday!', + 'Oh hey, look at this, my records show that there is a birthday today!', + 'Well what do you know, my sensors are detecting a birthday!' + ] | random }} +

+ +

+ {% if is_state('sensor.anniversary_tony_s_birthday','0') %} + Happy {{ states('sensor.tony_current_age') }}th birthday Tony! + {% elif is_state('sensor.anniversary_tina_s_birthday','0') %} + Happy {{ states('sensor.tina_current_age') }}th birthday Tina! + {% elif is_state('sensor.anniversary_kallen_s_birthday','0') %} + Happy {{ states('sensor.kallen_current_age') }}th birthday Collin! + {% elif is_state('sensor.anniversary_emmalynn_s_birthday','0') %} + Happy {{ states('sensor.emma_current_age') }}th birthday Emmalynn! + {% endif %} +

+ +

+ From Jarvis, the Stork Family, and everyone at Nerd Home Incorporated, we hope you have a great year! +

+ + {%- 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()) -}} \ No newline at end of file