home-assistant-configuration/config/templates/speech/security_report.yaml

56 lines
1.9 KiB
YAML
Raw Normal View History

>
{# 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()) -}}