Sonos Playmode Shuffle Toggle

Sonos functionality right now is great, but it is missing one significant feature that is present in the soco module leveraged by the sonos media_player: toggling shuffle mode.

Sonos supports the following play modes: (‘NORMAL’, ‘SHUFFLE_NOREPEAT’, ‘SHUFFLE’, ‘REPEAT_ALL’, ‘SHUFFLE_REPEAT_ONE’, ‘REPEAT_ONE’)

Soco can change the playmode using the newplaymode method.

Would it be possible add this capability via the sonos media_player component?

Others have implemented this using shell commands and the sonos http api, but that requires yet another service on your homeassistant box, would be great to offer this as native functionality.

This script is an example where I would love to also set the playmode:

  music_kitchen:
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.kitchen
          volume_level: 0.25
      - service: media_player.media_stop
        data_template:
          entity_id: media_player.kitchen
      - service: media_player.select_source
        data:
          entity_id: media_player.kitchen
          source: "G+R 3- Rock-,Elec-"

This playlist will only play in order unless I then use the Sonos app to change the playmode.

Would be great to be able to do this:

      - service: media_player.shuffle_set
        data:
          entity_id: media_player.kitchen
          shuffle: true

Having true and false toggle between SHUFFLE_NOREPEAT and NORMAL would be a fantastic addition.

Thanks for reading! I’d be happy to help test.

+1 on this request. If it is possible to do

1 Like

It’s totally possible: Soco already supports it, just a matter of passing it all the way through to HA.

Turns out it was an easy addition when diggin into it, got it to work locally this evening and will probably issue a PR tomorrow to get it in next release

1 Like

PR submitted (https://github.com/home-assistant/home-assistant/pull/10875)

5 Likes

Great, will this also allow to play a Spotify playlist from the favorites in shuffle mode? This is a feature im desperately waiting for, since my playlists will start at the same song over and over again :smiley:.

That was precisely my need as well, so yes that will work :slight_smile:

1 Like

Thanks for the nice christmas present, if it will find its way into a release before christmas.

This is great news. Thank you for all the hard work! Do you know when this will be implemented ?

The PR just got merged. So it will be included in the next release. Merry Christmas :star2:

4 Likes

my man. thank you!

Outstanding!! Thanks, roneius!!

Was this put in 59.2 ?

Thanks again!

I just pulled the dev build and tested with the following script:

  music_kitchen:
    sequence:
      - service: media_player.media_stop
        data_template:
          entity_id: media_player.kitchen
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.kitchen
          volume_level: 0.25
      - service: media_player.shuffle_set
        data:
          entity_id: media_player.kitchen
          shuffle: true
      - service: media_player.select_source
        data:
          entity_id: media_player.kitchen
          source: "G+R 3- Rock-,Elec-"

It works as expected, and I am very grateful for this enhancement.

Thanks again, @ronelius!!

1 Like

It was included in release 60.0

thanks. hopefully they fix the issue with two hue bridges soon. Id like to upgrade.

Is this feature supported with Sonos Play1 ?

Using with code:

- service: media_player.shuffle_set
  data:
    entity_id: media_player.sala
    shuffle: true

- service: media_player.select_source
  data:
    entity_id: media_player.sala
    source: "CelticRadio"

I got:

ERROR (Thread-18) [homeassistant.components.media_player.sonos] Error on set_shuffle with UPnP Error 712 received: Play mode not supported from 192.168.188.83

“CelticRadio” is a Spotify playlist.

Of course, from the Android app I can shuffle the playlist.

It’s supported on Play:1 but not for radio streams. If it really is a playlist, maybe you will have more luck by swapping the order of the services.

2 Likes

Hey, sorry to bump an old thread but Im trying to figure something out and came across this.

Im trying to use the sonos component and turn repeat on and off. Is this doable, currently? I cant figure it out.