Play a random Spotify playlist on Squeezebox

I’m in 0.28.2 …

What version you have?

wasn´t playmedia added quite recently for squeezebox?

Yup, my bad …

I just updated to latest verstion and works with no issue.

thank you guys! :slight_smile:

1 Like

I can’t seem to get the shuffling to work. If I put the command into putty it works but calling it from within homeassistant seemingly has no result and doesn’t throw any errors.

I have tried moving the location of the scripts, the .sh files from /home/pi/scripts/ to a folder within the raspberry pi AIO virtual environment ( /home/hass/.homeassistant/shcripts/ ).

I’ve tried changing the permissions with a chmod from putty on files and folders.

I’ve tried changing my shell commands configuration between !include_dir_merge_named, named, merge_list, list and directly in configuration.

And variations of the above - any ideas where I’m going wrong? Or even how to test if a shell command works from Hass at all?

Try creating a simple bash script that copies a file. Then trigger it from the services dev tab. Just to confirm that things are working.

In my example, you don’t need the script unless you also want to turn shuffle on/off. Playing a random music source should work without that. Maybe test that first if you’re having issues there?

Thanks @ih8gates.

It seems I can’t trigger a script at all. Perhaps something to do with permissions and the AIO being in a virtual environment. I can see another user having the same problem with it here.

The random music source has been working great. For the last two weeks I’ve been trying to build a radio from it that uses time conditions within the script to determine the set of playlists to choose from. Getting these conditions to work has been driving me nuts. I’m still trying but it looks like I’m going to have to ask for help with that one too.

FYI: I’m running the AIO on a Pi3. I haven’t had any permissions issues. I took a look and all of my scripts are owned by pi.

Thanks again - might be time for a clean install test since a simple copy script fails too. Time to order some spare SD cards.

Chances are I have broken something somewhere with my fiddling.

I bought a couple extra cards, but in practive, I’ve just been making IMG backups every once in a while. Cheaper.

Unfortunately, I’ve been doing that in theory rather than practice.

The plan was, clean install, get all basics working then image, (and incremental image each time I make major changes).
The day after I did my AIO clean install the async update came through and I’ve been fighting with it ever since.

I thought you might like to see how I adapted your script to make a radio station I turn on and off with Alexa. Here’s a simplified version of my music robot yaml.

robot_radio:
  alias: robot radio
  sequence:
    - service: script.morning_easy
    - service: script.evening_gentry
    - service: script.nicht_muzik
### Morning ###
morning_easy:
  alias: play random music in morning
  sequence:
    - condition: time
      before: '14:00:00'
      after: '06:00:01'
    - service: shell_command.squeeze_shuffle_songs
    - service: media_player.play_media
      data:
        entity_id: media_player.hoolio
        media_content_type: PLAYLIST
      data_template:
        media_content_id: >
         {{ ["PlaylistM1", "PlaylistM2", "PlaylistM3", "PlaylistM4", "PlaylistM5", "PlaylistM6", "PlaylistEM", "PlaylistM8", "PlaylistM9", "PlaylistM10"] | random}}

### Evening ###
evening_gentry:
  alias: play random music in evening
  sequence:
    - condition: time
      before: '21:00:00'
      after: '14:00:01'
    - service: shell_command.squeeze_shuffle_songs
    - service: media_player.play_media
      data:
        entity_id: media_player.hoolio
        media_content_type: PLAYLIST
      data_template:
        media_content_id: >
         {{ ["PlaylistE1", "PlaylistE2", "PlaylistE3", "PlaylistE4", "PlaylistE5", "PlaylistE6", "PlaylistE7", "PlaylistE8", "PlaylistE9", "PlaylistE10"] | random}}

### Night ###
nicht_muzik:
  alias: play random music at night
  sequence:
    - condition: time
      before: '23:59:00'
      after: '21:00:01'
    - service: shell_command.squeeze_shuffle_songs
    - service: media_player.play_media
      data:
        entity_id: media_player.hoolio
        media_content_type: PLAYLIST
      data_template:
        media_content_id: >
         {{ ["PlaylistN1", "PlaylistN2", "PlaylistN3", "PlaylistN4", "PlaylistN5", "PlaylistN6", "PlaylistN7", "PlaylistN8", "PlaylistN9", "PlaylistN10"] | random}}


robot_stop:
  alias: kill the radio
  sequence:
  - service: media_player.turn_off
    entity_id: media_player.hoolio

I have a bunch of playlists set up on my squeezeserver because my internet connection is rubbish. These playlists are split into different times of day based on my listening preferences. For an easy start to the day I have 10 different playlists called “PlaylistM1” “PlaylistM2” …M10 and the same thing setup for other times of day. Some of those playlists contain hundreds of songs so I get a lot of variety.

So via Ha-Bridge I say “Alexa, turn on robot radio” which runs the robot_radio script and the turn off command is linked to the robot_stop script at the end of the file.

I’m using include script: !include_dir_merge_named scripts in my config file so no hyphens on the scripts.

I wasn’t able to work out multiple instances of the time condition in a single script so I have worked around it by using scripts running sequentially within a script. If one fails to meet the condition it moves onto the next script. I suspect there is a far better way to do this.

2 Likes

I have worked out my shell command / .sh problems finally. I used a clean blank install and trial and error until I got it working and then replicated on my full install. Really I think I just needed to step away for a few days, too frustrated to see what was right in front of me perhaps…

For anyone else who has the same issue see here

Hi @ih8gates,

I was trying to use your script to play spotify over my chromecast (via LMS).
I managed to play single songs, but not being able to use playlists.
Also, every if i entered multiple song URIs in the script (to replace playlists), it can play only one song, not to mention shuffling. Any idea how i can make it work? Thanks!

If you get the Spotify URI for a playlist and load it with media_content_id, that should work. And does work for me every day.

I don’t think it’ll work with multiple separate tracks - each one will replace the first.

Thanks! May I know what plug-in you use for Spotify in LMS?

I use the Spotify 1.0 from Logitech and the Spotify Protocol Handler 1.1.1 (Triode).

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”}