I’ve been trying to use a script, whereby I feed a media player’s name into the script through a variable, then send TTS to that speaker. I’ve had some issues with concurrent messages being played and so want to put a wait template in to make sure the speaker is not being used before playing.
In this example, variable source is being fed in, it contains the string “media_player.living_room_speaker”.
If I do this,
- service: tts.google_say
data_template:
entity_id: >
{% if source is defined %}
{{ source }}
{% else %}
group.google_home_speakers
{% endif %}
message: "Message here".
If no source variable is supplied, the message is broadcast. If it is, then its only played on that speaker.
Normally with a wait template I could do the following:
- wait_template: "{{ states.group.google_home_speakers.state == 'off' }}"
However, if I want to check if that speaker supplied by the variable is playing, how do I transform the variable into the format of “states.{{variable}}.state”?
- wait_template: "{{ states."source".state == 'off' }}"
Tried a heap of different variants and can’t quite hit the right one?