Hello all,
Could someone help me with showing me how to modify the below based on my upcoming criteria. The below is a portion of my script and I believe you will be able to understand what I am trying to do with just this portion of the script.
I’m trying to figure out if there is a way to use what I have done in the “google_cloud_say” service call in the wait template. (i.e., the logic of “who” being my data template portion essentially); I’m wanting to make the “sonos_entity” text in the wait template be a variable essentially and in my instance, if no “who” is passed when I call the script, I want it to use the living room sonos speaker.
Can I literally just change “sonos_entity” to “who” without the " and everything with this will work properly?
I’m sorry for the strange question, this was “borrowed” code and I’m trying to modify it to meet my criteria. (I’m relatively new to home assistant and not very good with some of the more code involved changes etc.)
- service: tts.google_cloud_say
data_template:
entity_id: >
{% if who == 'back porch' %}
media_player.back_porch_speaker
{% elif who == 'front porch' %}
media_player.front_porch_speaker
{% elif who == 'dining room' %}
media_player.dining_room_wifi
{% elif who == 'office' %}
media_player.office_wifi
{% elif who == 'master bedroom' %}
media_player.master_bedroom_speaker
{% elif who == 'master bathroom' %}
media_player.master_bathroom_speaker
{% elif who == 'gym' %}
media_player.gym_speaker
{% elif who == 'guest bedroom' %}
media_player.guest_bedroom_speaker
{% elif who == 'garage' %}
media_player.garage_speaker
{% elif who == 'guest bathroom' %}
media_player.guest_bathroom_speaker
{% elif who == 'everywhere inside except tvs' %}
media_player.everywhere_inside_except_tvs
{% elif who == 'kitchen' %}
media_player.kitchen_display
{% else %}
media_player.living_room_sonos_speaker
{% endif %}
message: >-
{{ message }}
- delay: 00:00:01
- wait_template: '{{ is_state(sonos_entity, ''paused'') }}'
- service: sonos.restore
data_template:
entity_id: >
{% if who == 'back porch' %}
media_player.back_porch_speaker
{% elif who == 'front porch' %}
media_player.front_porch_speaker
{% elif who == 'dining room' %}
media_player.dining_room_wifi
{% elif who == 'office' %}
media_player.office_wifi
{% elif who == 'master bedroom' %}
media_player.master_bedroom_speaker
{% elif who == 'master bathroom' %}
media_player.master_bathroom_speaker
{% elif who == 'gym' %}
media_player.gym_speaker
{% elif who == 'guest bedroom' %}
media_player.guest_bedroom_speaker
{% elif who == 'garage' %}
media_player.garage_speaker
{% elif who == 'guest bathroom' %}
media_player.guest_bathroom_speaker
{% elif who == 'everywhere inside except tvs' %}
media_player.everywhere_inside_except_tvs
{% elif who == 'kitchen' %}
media_player.kitchen_display
{% else %}
media_player.living_room_sonos_speaker
{% endif %}