Media Player Shuffle

Hey guys,

This is probably user error but I have been staring at this far too long at this point and just can’t see what I am doing wrong.

I have a media_player (picoreplayer running on a Pi 3B+). I can successfully play Spotify playlists in order. Now I am trying to implement shuffle but can’t get it working:

play_music:
    sequence:
    - service: switch.turn_on
      entity_id: switch.soundbar
    - service: media_player.shuffle_set
      entity_id: media_player.lounge
      shuffle: 'true'
    - service: media_player.play_media
      data:
       entity_id: media_player.lounge 
       media_content_id: 'spotify:playlist:4kgoXXXXXN6k7ji3wUdJ1U'
       media_content_type: 'music'

After reading this: Script for media player doesn't work but why?

I also tried this format:

play_music:
    sequence:
    - data:
      entity_id: switch.soundbar
    service: switch.turn_on 
    - data:
      entity_id: media_player.lounge
      shuffle: 'true'
    service: media_player.shuffle_set
    - data:
       entity_id: media_player.living_room 
       media_content_id: 'spotify:playlist:4kgoXXXXXN6k7ji3wUdJ1U'
       media_content_type: 'music'
    service: media_player.play_media

Again it did not work. I am probably missing something obvious? Can anyone point me in the right direction?

Thanks

Your formatting is wrong,try this:

play_music:
    sequence:
    - service: switch.turn_on
      entity_id: switch.soundbar
    - service: media_player.play_media
      entity_id: media_player.lounge
      data:
        media_content_id: 'spotify:playlist:4kgoXXXXXN6k7ji3wUdJ1U'
        media_content_type: playlist
    - service: media_player.shuffle_set
      entity_id: media_player.living_room
      data:
         shuffle: true

A few points to add:

In your second example you set shuffle for lounge, but then play media on livingroom. Also did you check that it plays music in the first place? I don’t think you can play spotify music on any media player, only on the spotify media player. Also the shuffle command needs to be executed after you play a list, not before you play it. And you need to change the media_content_type to playlist to play playlists, as described here.

1 Like

Hi, your formatting is correct, but spotify seems to turn off Shuffle as soon as you start a playlist. This is how I got it working:

#
# Plays a specific playlist on Spotify.
# To get the shuffle to work, you need to
# 1) Start the playlist (as starting a playlist will disable shuffle)
# 2) Enable shuffle
# 3) Choose next song, as otherwise you will first always have to listen to the 1st song in the playlist
#
spotify_play_playlist:
    alias: Spotify Play
    description: 'Play playlist in Spotify'
    sequence:
        - service: media_player.select_source
          data:
            entity_id: media_player.spotify_living_room
            source: 'Moode Spotify'
        - service: media_player.play_media
          data:
            entity_id: media_player.spotify_living_room
            media_content_type: playlist
            media_content_id: 'spotify:playlist:41FRrXCDu3hoZxNCGhXrCP'
        - service: media_player.shuffle_set
          data:
            entity_id: media_player.spotify_living_room
            shuffle: true
        - service: media_player.media_next_track
          data:
            entity_id: media_player.spotify_living_room

6 Likes

Thanks @Burningstone and @Stefaan, this is what I ended up with and it works as desired.

  play_music:
    sequence:
    - service: switch.turn_on
      entity_id: switch.soundbar
    - service: media_player.shuffle_set
      entity_id: media_player.lounge
      data:
         shuffle: true     
    - service: media_player.play_media
      entity_id: media_player.lounge
      data:
        media_content_id: 'spotify:playlist:4kgoXXXXXN6k7ji3wUdJ1U'
        media_content_type: music

@Burningstone, I did originally use playlist but then read somewhere (I’ll be honest I can’t remember where now) that it should now instead be music. I have a vague memory that it didn’t work for me using playlist but did when I switched to using music. The lounge/living_room issue was just a copy paste error in my example.

Thanks to you both for your suggestions

I am a noob at this sort of stuff. Can shuffle.set be used to play (shuffle) the mp3 tracks in an album on local shared media? I haven’t found a way to play the contents of an album or a folder on local media.
TIA

I use the same method. One problem with it is now you will never hear the first song on playlist. :wink:

Is this still working for you? I’m trying to repurpose this for my needs and I’m getting an error that my google nest mini nor the spotify service doesn’t support shuffle? Is my syntax wrong or is that really a basic feature not available on my device? Just trying to understand if I’m asking the right place to “shuffle”.

alias: Spotify Christmas Playlist With Shuffle
sequence:
  - service: media_player.turn_on
    data: {}
    target:
      entity_id: media_player.living_room_mini
  - service: media_player.shuffle_set
    data:
      shuffle: true
    target:
      entity_id: media_player.living_room_mini
  - service: media_player.play_media
    data:
      media_content_id: spotify:playlist:5qqXXXXXXXXXX2BwR40SIC2
      media_content_type: music
    target:
      entity_id: media_player.living_room_mini
mode: single
icon: mdi:music

Nevermind! I found a different approach that was a lot cleaner and more straightforward. It requires the spotcast integration to be configured.

Here’s my yaml for the script I created:

service: spotcast.start
data:
  entity_id: media_player.living_room_mini
  device_name: Living Room Mini
  shuffle: true
  random_song: true
  country: US
  uri: spotify:playlist:5qqXXXXXXXXXX2BwR40SIC2

I tried to add this player and it looks nice.
But how do I get a shuffle button?
I an using the plex integration for my music

This works nicely for me - thank you. I didn’t need the first switch.turn_on step, though, for my Sonos soundbar.