Play a random Spotify playlist on Squeezebox

I am using the same plug-in, but somehow i still cannot play playlist. But can get album to play. However, i cannot get a “random” alum to play. It is always the same album. (the first one). Any idea where i did wrong?

  randomsqueeze:
    alias: "Morning music"
    sequence:
        #a bash script that turns on shuffle-by-song
      - service: shell_command.squeeze_shuffle_songs
      - service: media_player.play_media
        data: 
          #change this to match your player
          entity_id: media_player.lms_google_home
          media_content_type: PLAYLIST
        data_template:  
           #add as many playlist or album IDs as you like
          media_content_id: >
              {{ ["spotify:album:5dN7F9DV0Qg1XRdIgW8rke", "spotify:album:7hPq9fDWwXPo1tT0oi3XcM", "spotify:album:2rQ135imvelvp89D8eEZOi", "spotify:album:7xl50xr9NDkd3i2kBbzsNZ", "spotify:album:0vNPAhooQJWujYOZrsOJw8", "spotify:album:2MKNnI6Ttt2kF8kHWWG930", "spotify:album:2MKNnI6Ttt2kF8kHWWG930"] | random}}

This is related to an issue with the random filter not working. If you restart HASS, you’ll get a different random position initially, then it’ll keep using that position until HASS restarts. Very annoying - add your voice to the conversation in hopes that it gets fixed soon:

But you should be able to get a playlist to play if you can get an album to play by its URI.
Playlist URIs look like: spotify:user:ih8gates:playlist:32kolpL0K7jto6GQZE2skl

Get the URI for one of your own playlists by right-clicking in the Spotify app and choose “Copy Spotify URI”

Got it! Will go that discussion later.
About the URI, i actually thought the same. However, no matter i tried my own playlist, or the Spotify playlist, they all won’t work.

spotify:user:spotifytaiwan:playlist:1JsaeXIvhkTntGh4SjUd0q
spotify:user:yunglinglee:playlist:1ntqr5uKpEk7CwMmdHPZ51

No idea why…

That’s very strange.

What if you try via the services dev tool?

Use media_player.play_media with this payload (changing media_player.squeezeplay to match your device’s entity_id):

{“entity_id”:“media_player.squeezeplay”,“media_content_id”:“spotify:user:yunglinglee:playlist:1ntqr5uKpEk7CwMmdHPZ51”,“media_content_type”:“PLAYLIST”}

Have tried this…the log returns

[00:04:03.043451] log_message:81 log: 16:04:03.043 E [ap:4210] ChannelError(0, 1, playlist)

But if you do the same exact thing (using the dev tool) and put an album URI in in-place of the playlist URI, it works fine?

Sounds like maybe it’s an issue with the protocol handler. If I look at the settings for mine (in LMS), the version of the Libspotify API I have is: 12.1.51.g86c92b43 Release win32

Yes. The album URI works fine in the dev tool.
Let me go back to check the Libspotify version. Will share later. Thanks a lot!

Just checked my Spotify plug in, it is 1
2.1.103.gd51f6226 Release Linux-armv6-bcm2708hardfp

I am using it on a raspberry pi. Is this where the problem comes from?

I would hope that running on Linux shouldn’t be the problem. Looks like you’ve got a newer revision of the API than I have. So I don’t expect that’s the issue.

Let’s take a look at the LMS server directly and see if the problem’s there. Create a shell script on your PI with this as the contents:

curl -X GET \
    -H "Content-Type: application/json" \
    -d '{"id":1,"method":"slim.request","params":["bc:5f:f4:e9:44:4a",["playlist","play","spotify:user:ih8gates:playlist:35Q88WL7PvvRzLTuoy60hA"]]}' \
    http://192.168.1.110:9000/jsonrpc.js

You’ll need to replace the “bc:5f:f4:e9:44:4a” part with the MAC of your player as seen by LMS. You can find this by opening “settings” on your LMS interface, then go to the player tab. There should be a drop-down with a list of players. Choose one and the mac will display under “player info”.

Then change the IP address in that last line to match the IP of your LMS server. You can experiment with different Spotify URIs in that setting that starts with “spotify:user…”

run the script (“bash scriptname.sh”) and see what happens.

Albums should work - curious to see if playlists do.

Got it! Let me try after work today, thanks for your kind help!

Just tested both album and playlist. Album worked as expected, and playlist did not. Really have no idea what i can do next…

OK. So it’s a problem with LMS, not with HA.

Take a look at the Triode helper app log - there’s a link to it in the plugin settings.

Also check for updates to the Triode protocol handler. Check to see if there’s a support forum for it.

BTW - when I was generating that info for you, I tested both album and playlist and both worked.

Be sure that you’re using the Triode protocol handler, not the Triode Spotify plugin. If you still have the old Spotify plugin, try disabling it. I think the preferred setup is to use the official Spotify plugin (from Logitech), with Triode’s protocol handler.

I have Spotify (v1.0) from Logitech and Spotify Protocol Handler (v1.1.1) from Triode. Think that should be it. Am trying to find the relative discussion about the playlist issues. There seems to be quite a few, but not really exactly my case. Probably i will need to spend some time reading through the thread.

Don’t forget to take a look at the Triode helper app log - that might shed some light on the situation.

Just to make sure that the log is web page that shows:

[09:30:48.942452] log_message:81 log: 01:30:48.942 E [ap:4210] ChannelError(0, 1, playlist)

I go there by pressing the “log” button in the SPH setting page. Is this the one you are referring to?

Yes. I was hoping you’d get a more-descriptive error. But that at least gives you a place to start. Searching their forums.

Are you able to browse and play playlists from Spotify from within the Squeeze Server interface?

@ih8gates,

Your comment of playing the Spotify playlists from mysqueezebox.com helped!
I went to the website and found that i did not log in my Spotify account on the web interface! I logged in there and the magic happened! The playlists just started playing! :smiley:
Although i have no idea why other stuff (albums/ tracks) could work… but anyway now it works perfectly. Thanks for your help in past few weeks!!!

Wow. That’s a weird solution! But glad that you got things worked out!

Logging in from the web interface lets the official Spotify plugin do it’s thing.

For people coming back to this. As of April 2017, the random filter has been broken in HA. You’ll get a random playlist the first time this runs, but subsequent commands load the same randomly-chosen playlist. Reboot HA and you’ll get a new random choice, but you’re stuck with that choice till you reboot.

@7h30n3 discovered that the problem only seemed to occur with lists. So here’s a work-around that I’ve been using to restore randomness:

data_template:
         media_content_id: >
          {%- set plists = ["spotify:user:ih8gates:playlist:3C4vzY7mOqylGLmGRlPplf", 
            "spotify:user:ih8gates:playlist:32kolpL0K7jto6GQZE2skl", 
            "spotify:user:ih8gates:playlist:0TRYnIGISaQV3l2va1dPCp", 
            "spotify:user:ih8gates:playlist:6PDDqtno9XiHU0YbmysQEp", 
            "spotify:user:ih8gates:playlist:0MHHBF5wsI3zweHaYBp1t8",            
            "spotify:user:ih8gates:playlist:0RFECUW6B7mGZlQPwytJgd",            
            "spotify:user:ih8gates:playlist:7I3IZTkHbX5z5nyIbiQ84P", 
            "spotify:user:ih8gates:playlist:3aVhoe60krjCtm0owZGwu8", 
            "spotify:user:ih8gates:playlist:0EddcASHBaRuWQFnlw852q",            
            "spotify:user:ih8gates:playlist:3v4uykRhSasEaS8ApIM7Sp",
            "spotify:user:ih8gates:playlist:7vPmKlFOMMdY1Uw1ZQNMIn",
            "spotify:user:frankspin:playlist:2Lzb461rpLNb9dVYN3uC7i",
            "spotify:user:spotify:playlist:37i9dQZEVXcSBzBguZEMX8"
            ] -%}
            {% set pindex =  (range(0, (plists | length - 1 ) )|random) -%}
            {{ plists[pindex] }}

Just fill that plists array with the URIs for your playlists.

1 Like