How to Play a Playlist in Spotify?

I am wondering how to play a playlist in spotify?

I created a script to test it out…

spotifydemo:
  alias: 'Spotify Demo'
  sequence:
    - service: media_player.play_media
      data_template:
        entity_id: media_player.spotify_master_bedroom
        media_content_id: 'spotify:user:spotify:playlist:37i9dQZF1DX4dyzvuaRJ0n'
        media_content_type: 'PLAYLIST'

but it doesn’t work. It gives this error…

ERROR (Thread-8) [homeassistant.components.media_player.spotify] media type PLAYLIST is not supported

The documentation need to include more info on how to make use of this component.

2 Likes

I had a bit of a play when testing the component before. It seems like your final line should be:

        media_content_type: playlist

Let me know if that works for you!

2 Likes

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.