Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95488

Script Templating Help - If-else for Spotify source

$
0
0

@Clint_Williams wrote:

I’ve got an Amazon Echo that I want to play music on using the Spotify integration. Everything works fine except for sometimes the source name will change from ‘Living Room’ to ‘Echo-576’. Somehow the echo is loosing it’s name and is switching back and forth between it’s default name and the one I assigned.
So I thought I could use an if-else template to dynamically change the source name depending on if ‘Living Room’ is defined in the Spotify source list.
Here’s what I have:

yoga_time_music_play:
  alias: Play Yoga Playlist on Living Room Echo
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.spotify_clint_williams
        source: >
          {% if 'Living Room' in state_attr("media_player.spotify_clint_williams", "source_list") %}
            Living Room
          {% else %}
            Echo-576 Speaker
          {% endif %}
    - service: media_player.volume_set
      data:
        entity_id: media_player.spotify_clint_williams
        volume_level: 0.4
    - service: media_player.play_media
      data:
        entity_id: media_player.spotify_clint_williams
        media_content_type: playlist
        media_content_id: spotify:playlist:0tZKB07WrNju5Ac2hvhPyV

It sets the volume and plays the content but not on the source specified.
If I delete the template and just use ‘source: Echo-576 Speaker’ everything works fine.
I’ve tried all kinds of variations on the formatting and it just won’t work. Can anyone please help?

P.S. There used to be an alias optional configuration for the Spotify integration where you could define an alias for each of your sources device id’s. What happened to that?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>