Files
Home-Assistant-Configs/templates/speech/welcome_home.yaml
2022-08-29 19:06:37 -04:00

37 lines
1.3 KiB
YAML

>
{# Script Name Here #}
{%- macro getReport() -%}
<p>
"Welcome home, "
{% if is_state('person.tony_stork','home') and is_state('person.christina_stork','home') %}
"Stork family. "
{% elif is_state('person.tony_stork','home') %}
"Tony. "
{% elif is_state('person.christina_stork','home') %}
"Tina. "
{% else %}
"Whoever you are, Tony must have broken me again. "
{% endif %}
{% if now().strftime('%H')|int < 12 %}
"I hope you're having a great morning!"
{% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}
"I hope your afternoon has been a good one!"
{% else %}
"and good evening. I hope you had a good day!"
{% endif %}
</p>
{%- 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()) -}}