Playlist script

I’m building a music dashboard. First thing I have is a drop-down helper with all my speakers listed. On the dashboard, I have a condition card set up to show the media player for the speaker that is selected. I have then added button that trigger a script to play the playlist that I want. I’m using the Alexa media player to send a custom command as if I was to say it to the Alexa speaker to play what I want. What do I need to change the ‘device I’d: #####’ to so it changes to the speaker I have selected.

input_select.speaker_select


alias: Apple Dance
sequence:
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: Play apple dance music
    target:
      device_id: 883dc4aec4cc0c114ccd732a87d43b6e
mode: single

I’m guessing it’s something along the lines of this. (I’m very new to all this)


{{ if state('input_select.speaker_select') Work }}
{{ then }}
"work speaker ID"
{{ End if }}
{{ if state('input_select.speaker_select') Living Room }}
{{ then }}
"livingroom speaker ID"
{{ End if }}

For longer lists it is more efficient to use a dictionary and the get() method:

alias: Apple Dance
sequence:
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: Play apple dance music
    target:
      device_id: >
        {% set d = {
        "Work": "work speaker ID",
        "Living Room": "livingroom speaker ID",
        "Downstairs":  ...
         } %}
        {{ d.get( states('input_select.speaker_select') ) }}
mode: single

I think I’ve found my solution now


  {% if is_state('input_select.speaker_select', 'Work') %}
              work speaker id
            {% endif %}
  {% if is_state('input_select.speaker_select', 'Dining Room') %}
              dining room speaker id
            {% endif %}

I’ll leave it here in case it helps anyone else

Thank you, I’ll give this a go