How to Play a Playlist in Spotify?

well, thanks. it works!

I am wondering how to turn on shuffle mode?

1 Like

What kind of device you have in media_player.spotify_master_bedroom?

I’m trying to make this work with Chromecast

I am using Echo

Thank you for the tip.
Playlist works nicely.
I would like to play a randon playlist of a list of playlists.
Something like here:

I tried it this way

but could not get it to work.
Does anyone have an idea how to get this to work?

What’s not working? I use the script posted every morning to wake to a random playlist.

If you’re having issues with playing Spotify URIs, the issue is with the Squeeze server. Make sure you’re logged in to mysqueezebox.com

I use the new Spotify Connect feature with Panasonic Allplay speakers and an, echo dot. Single Playlists work as described in the first post.
but I tried your your setup like that and it does not start:

spotifydemo:
  alias: 'Spotify Demo'
  sequence:
    - service: media_player.play_media
      data_template:
        media_content_id: >
          {%- set plists = ["spotify:user:spotify:playlist:37i9dQZF1DX55dNU0PWnO5", 
            "spotify:user:spotify:playlist:37i9dQZF1DWVyfHu8SNQgH",
            "spotify:user:spotify:playlist:37i9dQZF1DX9OTdoPfdJpF"
              ] -%}
            {% set pindex =  (range(0, (plists | length - 1 ) )|random) -%}
            {{ plists[pindex] }}

Error in the log file:

17-04-25 14:48:41 ERROR (Thread-1) [homeassistant.util.yaml] while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/script/spotify_test.yaml”, line 7, column 12
17-04-25 14:48:41 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/script/spotify_test.yaml”, line 7, column 12

You’re skipping some required data for media_player.play_media.

Try this. It worked for me (except I replaced media_content_id with the value from my example)

spotifydemo:
  alias: 'Spotify Demo'
  sequence:
    - service: media_player.play_media
      data: 
        entity_id: media_player.spotify
        media_content_type: playlist
      data_template:
        media_content_id: >
          {%- set plists = ["spotify:user:spotify:playlist:37i9dQZF1DX55dNU0PWnO5", 
            "spotify:user:spotify:playlist:37i9dQZF1DWVyfHu8SNQgH",
            "spotify:user:spotify:playlist:37i9dQZF1DX9OTdoPfdJpF"
             ] -%}
            {% set pindex =  (range(0, (plists | length - 1 ) )|random) -%}
            {{ plists[pindex] }}
3 Likes

How could I not see that :sweat: thanks @ih8gates.

Now I just need a shuffle mode like @masterkenobi mentioned :slight_smile:.
Want to implement this as well in my alarm clock :slight_smile:

When testing, I was able to call that script multiple times and it would repeatedly replace the current playlist/queue with a new random one.

You’re right not enough playlists. Seemed to pic the same playlist 4 times in a row :smiley:
Still shuffle mode but it seems this one is yet missing as it does not show up in the media_player setup.

In the example in my random-playlist thread, I had to use Logitech Media Server’s API to set the shuffle mode.

The only media_player I’ve got configured that supports shuffle appears to be Kodi (kodi_set_shuffle). It’d be great for other platforms to support shuffle in a consistent way.

Please upvote:

1 Like

Is it possible to dynamically list all your spotify playlists?
So as soon you create a playlist in Spotify it appear in HASS as a selection list

1 Like

That would be very useful !!

It doesn’t seem to work: Spotify in combination with chromecast
Do you know of any fix?

@ih8gates @derdude1893 @masterkenobi

Should this functionality still work or has it been superceeded?

From the thread I tried three different scripts to get it working as there are different approaches in the thread.

My goal is simply to have a script that will activate a set playlist on a set speaker (Google Mini/Home).

spotify_kids_chart:
  alias: Test Kids Charts
  sequence:
  - service: media_player.play_media
    data_template:
      entity_id: media_player.study_speaker
      media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'
      media_content_type: 'playlist'

spotify_kids_chart2:
  alias: Test Kids Charts2
  sequence:
  - service: media_player.select_source
    data_template:
      entity_id: media_player.spotify
      source: Study Speaker
#      source: media_player.study_speaker
  - service: media_player.play_media
    data_template:
      entity_id: media_player.spotify
      media_content_type: playlist
      media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'

spotify_kids_chart3:
  alias: Test Kids Charts3
  sequence:
  - service: media_player.select_source
    data_template:
      entity_id: media_player.spotify
      source: CC32E753
#      source: media_player.study_speaker
  - service: media_player.play_media
    data_template:
      entity_id: media_player.spotify
      media_content_type: playlist
      media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'
1 Like

I tested the first one with the services dev tool. Looks like it works fine. What error are you seeing in the logs?

@ih8gates Thanks for your reply. FYI I am not ignoring you but overnight my entire HA stopped working and I am now trying to install on a NUC rather than on a QNAP Container Docker.

When I have finished I will be using my previous config and will repost if there is the same error.

Does anyone have this working? I have tried both approaches without success.

hello how I can get my media_content_id: playlist ?

media_content_id: ???

I done this using adb command. Spotify is installed on my android tv.

service: androidtv.adb_command
data:
  entity_id: media_player.android_tv_1
  command: >-
    am start -a android.intent.action.VIEW -n
    com.spotify.tv.android/.SpotifyTVActivity -d https://open.spotify.com/playlist/2jFHTHj1s3FF4okSBu9vz5
1 Like