mirror of
https://github.com/thejeffreystone/home-assistant-configuration.git
synced 2025-09-14 07:45:48 +00:00
Trying to simplify speech templates
This commit is contained in:
56
config/templates/speech/security_briefing.yaml
Executable file
56
config/templates/speech/security_briefing.yaml
Executable file
@@ -0,0 +1,56 @@
|
||||
>
|
||||
{# Security Report #}
|
||||
{%- macro getReport() -%}
|
||||
<p>
|
||||
{%- if states.input_boolean.sentry_mode.state == 'on' %}
|
||||
{{ [
|
||||
'Sentry Mode is enabled.',
|
||||
'Sentry mode is currently active.',
|
||||
'Barn Door Protocol is currently in effect.',
|
||||
'My security system is currently armed.',
|
||||
'Anchorage House is in lockdown mode. '
|
||||
] | random}}
|
||||
{% else %}
|
||||
{{ [
|
||||
'Sentry Mode is disabled.',
|
||||
'Sentry mode is currently inactive.',
|
||||
'My security system is currently disarmed.',
|
||||
'Anchorage House is currently in standby. '
|
||||
] | random}}
|
||||
{% endif %}
|
||||
{%- if states.group.external_doors.state == 'off' %}
|
||||
All external doors are currently secured.
|
||||
{% else %}
|
||||
{% set open_doors = expand('group.external_doors')| selectattr('state', 'eq', 'on') | map(attribute='name')|join(' and ') %}
|
||||
{% set open_door_count = expand('group.external_doors') | selectattr('state', 'eq', 'on') | list | count %}
|
||||
{% if open_door_count == 1 %}
|
||||
{% set is_are = ' is ' %}
|
||||
{% else %}
|
||||
{% set is_are = ' are ' %}
|
||||
{% endif %}
|
||||
{%- macro announcement(open_doors, is_are) -%}
|
||||
{{ [
|
||||
open_doors ~ is_are + " standing open.",
|
||||
open_doors ~ is_are + " not secured.",
|
||||
open_doors ~ is_are + " open."
|
||||
] | random }}
|
||||
{%- endmacro -%}
|
||||
{{announcement(open_doors)}}
|
||||
{% 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()) -}}
|
Reference in New Issue
Block a user