Input select - Sonos automation

I´m trying out Node Red and moving some automations but get stuck on this. I have a couple input_select for selecting source in my Sonos speakers and can’t figure out what the best way would be to create the following automation in Node Red

- alias: Sonos Kök Genre
  trigger:
  - entity_id: input_select.genre_kok
    platform: state
  condition: []
  action:
  - service: media_player.select_source
    data_template:
      entity_id: media_player.koket
      source: >
        {% if is_state("input_select.genre_kok", "Country") %}
          DB Snus Country
        {%-elif is_state("input_select.genre_kok", "Disco") %}
          Det e la Disco Då Ju
        {%-elif is_state("input_select.genre_kok", "Hip-Hop") %}
          Hip Hop
        {%-elif is_state("input_select.genre_kok", "Hippie") %}
          Hippie
        {%-elif is_state("input_select.genre_kok", "Punk") %}
          Punk
        {%-elif is_state("input_select.genre_kok", "Rock") %}
          Rock
        {%-elif is_state("input_select.genre_kok", "Svenskt") %}
          Sverige
        {% else %}
          none
        {% endif %}

Basically how can I use a node to fetch the selected input for the source?

Never mind. I figure out how to fetch the data input into the service call node via the template node and a switch, leaving the data field in the service call node empty {}. Since some of the playlists had different names than what I´ve set in the input select I run them trough the change node.

Template node
{"data":{"entity_id":"media_player.koket","source":"{{payload}}"}}

3 Likes