HI @petro
using this technique myself here, with, as you adviced before, the ‘else’ to prevent errors in the outcome.
Maybe thats superflous since already tested in the value_template condition, but let me ask anyway:
would you still need the else for security?
- alias: Announce activity selection
id: 'Announce activity selection'
#hide_entity: True
#initial_state: 'on'
trigger:
platform: state
entity_id: input_select.activity
condition:
- condition: template
value_template: >
{{ states('input_select.activity') in
['Opstaan','Aan de slag','Home theater',
'Gym', 'Gaming', 'Selamat makan', 'Naar bed'] }}
- condition: template
value_template: >
{{ is_state('input_boolean.notify_announcement', 'on')}}
action:
service: notify.ios_telefoonmhb
data_template:
title: >
Activity {{states('input_select.activity')}} speech
message: >
{% set map = {'Opstaan': '{{"US-EN-Morgan-Freeman-Good-Morning.wav"[21:-4]|replace("-" , " ")}}',
'Aan de slag': '{{"US-EN-Morgan-Freeman-Coworker-Is-Arriving.wav"[21:-4]|replace("-" , " ")}}',
'Home theater': '{{"US-EN-Morgan-Freeman-Starting-Movie-Mode.wav"[21:-4]|replace("-" , " ")}}',
'Gym': '{{"US-EN-Morgan-Freeman-Motion-In-Game-Room.wav"[21:-4]|replace("-" , " ")}}',
'Gaming': '{{"US-EN-Morgan-Freeman-Motion-In-Game-Room.wav"[21:-4]|replace("-" , " ")}}',
'Selamat makan': '{{"US-EN-Morgan-Freeman-Motion-In-Kitchen.wav"[21:-4]|replace("-" , " ")}}'
} %}
{% set state = states('input_select.activity') %}
{{ map[state] if state in map else '{{"US-EN-Morgan-Freeman-Good-Night.wav"[21:-4]|replace("-" , " ")}}' }}
data:
push:
sound: >
{% set map = {'Opstaan': 'US-EN-Morgan-Freeman-Good-Morning.wav',
'Aan de slag': 'US-EN-Morgan-Freeman-Coworker-Is-Arriving.wav',
'Home theater': 'US-EN-Morgan-Freeman-Starting-Movie-Mode.wav',
'Gym': 'US-EN-Morgan-Freeman-Motion-In-Game-Room.wav',
'Gaming': 'US-EN-Morgan-Freeman-Motion-In-Game-Room.wav',
'Selamat makan': 'US-EN-Morgan-Freeman-Motion-In-Kitchen.wav'
} %}
{% set state = states('input_select.activity') %}
{{ map[state] if state in map else 'US-EN-Morgan-Freeman-Good-Night.wav' }}
or would this be preferable:
- alias: Announce activity selection
id: 'Announce activity selection'
# hide_entity: True
# initial_state: 'on'
trigger:
platform: state
entity_id: input_select.activity
condition:
- condition: template
value_template: >
{{ states('input_select.activity') in
['Opstaan','Aan de slag','Home theater',
'Gym', 'Gaming', 'Selamat makan', 'Naar bed'] }}
- condition: template
value_template: >
{{ is_state('input_boolean.notify_announcement', 'on')}}
action:
service: notify.ios_telefoonmhb
data_template:
title: >
Activity {{states('input_select.activity')}} speech
message: >
{% set map = {'Opstaan': '{{"US-EN-Morgan-Freeman-Good-Morning.wav"[21:-4]|replace("-" , " ")}}',
'Aan de slag': '{{"US-EN-Morgan-Freeman-Coworker-Is-Arriving.wav"[21:-4]|replace("-" , " ")}}',
'Home theater': '{{"US-EN-Morgan-Freeman-Starting-Movie-Mode.wav"[21:-4]|replace("-" , " ")}}',
'Gym': '{{"US-EN-Morgan-Freeman-Motion-In-Game-Room.wav"[21:-4]|replace("-" , " ")}}',
'Gaming': '{{"US-EN-Morgan-Freeman-Motion-In-Game-Room.wav"[21:-4]|replace("-" , " ")}}',
'Selamat makan': '{{"US-EN-Morgan-Freeman-Motion-In-Kitchen.wav"[21:-4]|replace("-" , " ")}}',
'Naar bed': '{{"US-EN-Morgan-Freeman-Good-Night.wav"[21:-4]|replace("-" , " ")}}' }}
} %}
{% set state = states('input_select.activity') %}
{{ map[state] }}
data:
push:
sound: >
{% set map = {'Opstaan': 'US-EN-Morgan-Freeman-Good-Morning.wav',
'Aan de slag': 'US-EN-Morgan-Freeman-Coworker-Is-Arriving.wav',
'Home theater': 'US-EN-Morgan-Freeman-Starting-Movie-Mode.wav',
'Gym': 'US-EN-Morgan-Freeman-Motion-In-Game-Room.wav',
'Gaming': 'US-EN-Morgan-Freeman-Motion-In-Game-Room.wav',
'Selamat makan': 'US-EN-Morgan-Freeman-Motion-In-Kitchen.wav',
'Naar bed': '{{"US-EN-Morgan-Freeman-Good-Night.wav"[21:-4]|replace("-" , " ")}}' }}
} %}
{% set state = states('input_select.activity') %}
{{ map[state]}}