From 75002946334b58242ea80e27b594ca520d15801c Mon Sep 17 00:00:00 2001 From: Jeffrey Stone Date: Mon, 7 Mar 2022 19:16:45 -0500 Subject: [PATCH] adding in a daily briefing example --- config/packages/speech.yaml | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/config/packages/speech.yaml b/config/packages/speech.yaml index 3b4c9e6..655fb38 100755 --- a/config/packages/speech.yaml +++ b/config/packages/speech.yaml @@ -152,3 +152,43 @@ script: {%- endmacro -%} {{- cleanup(mother_of_all_macros()) -}} + + daily_briefing_script: + sequence: + - service: script.speech_engine + data: + who: media_player.ha_blue + message: >- + {%- macro getGreeting() -%} + {% if now().strftime('%H')|int < 12 %} + Good morning. + {% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %} + Good afternoon. + {% else %} + Good evening. + {% endif %} + + {% if is_state('binary_sensor.morning','on') %} + Today is {{states.sensor.today_is.state }}, {{ as_timestamp(now()) | timestamp_custom('%B %d %Y') }}. + {% else %} + It is {{ now().strftime("%I:%M %p") }}. + {% endif %} + + {%- endmacro -%} + + {%- macro getDoorStatus() -%} + The Pod Bay Doors are Closed. + {%- 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 -%} + + {%- macro mother_of_all_macros() -%} + {{ getGreeting() }} + {{ getDoorStatus()}} + {%- endmacro -%} + + {{- cleanup(mother_of_all_macros()) -}}