HI,
I have 2 scripts, for making an announcement:
announce_daughters:
sequence:
service: notify.ios_phone
data_template:
title: >
{{presence_person}} arrived home speech
message: >
{{-as_timestamp(now()) | timestamp_custom("%X") }} :
{{presence_person}} arrived {{presence_location}}.
data:
push:
sound: >
US-EN-Morgan-Freeman-Daughter-Is-Arriving.wav
and
announce_wife:
etc
with the same content only the wav file is different.
this automation calls the scripts:
- service_template: >
script.announce_{{ 'daughters' if trigger.entity_id in ['group.daughter1', 'group.daughter2', 'group.daughter3',
'group.daughter4'] else 'wife'}}
data_template:
presence_person: "{{trigger.to_state.attributes.friendly_name}}"
presence_location: "{{trigger.to_state.state}}"
works fine.
Now I want to expand that with a 3d option, but I can’t get it right. Using the above syntax
{{ 'daughters' if trigger.entity_id in ['group.daughter1', 'group.daughter2', 'group.daughter3',
'group.daughter4']
'wife' if trigger.entity_id == 'device_tracker.wife'
else 'husband' }}
or like this:
- service_template: >
script.announce_{% if trigger.entity_id in
['group.daughter1', 'group.daughter2', 'group.daughter3','group.daughter4']%}daughters
{%elif trigger.entity_id == 'device_tracker.wife_presence' %}wife
{% else%}husband
{%endif%}
What am I doing wrong here? If I test it in the dev-template it shows the correct script…
Maybe I could try:
{% if trigger.entity_id in ['group.daughter1', 'group.daughter2', 'group.daughter3','group.daughter4']%} script.announce_daughters
{%elif trigger.entity_id == 'device_tracker.wife_presence' %} script.announce_wife
{% else%} script.announce_husband
{%endif%}
But I like to keep it as compact as possible, and dont like the script.announce_
in each option if I can avoid that
please have a look would you?
would be even cooler if I could make it into 1 script and place the wav file automatically too,
‘daughter’: ‘US-EN-Morgan-Freeman-Daughter-Is-Arriving.wav’
‘wife’: ‘US-EN-Morgan-Freeman-Wife-Is-Arriving.wav’
‘husband’: ‘US-EN-Alexa-Husband-Is-Arriving.wav’
thx!