Sonos Shuffle Playlist

Hello,
Please could I ask for some assistance?
I have the following script code to shuffle songs in a Spotify or Media Playlist:


'1582294744152':
  alias: Boyd Funk Everywhere
  sequence:
  - entity_id: media_player.kitchen,media_player.tv_room,media_player.master_bedroom
    service: sonos.unjoin
  - data:
      master: media_player.tv_room
    entity_id: media_player.kitchen,media_player.master_bedroom
    service: sonos.join
  - delay: '2'
  - data:
      volume_level: 0.4
    entity_id: media_player.kitchen,media_player.tv_room,media_player.master_bedroom
    service: media_player.volume_set
  - data:
      shuffle: true
    entity_id: media_player.master_bedroom
    service: media_player.shuffle_set
  - delay: '2'
  - data:
      source: Boyd Funk
    entity_id: media_player.tv_room
    service: media_player.select_source

It works but only occasionally. Often it starts playing tracks from A onwards. I added in some delays in case Sonos was taking time to handle the joining of players and missed the shuffle command but I don’t think it’s made any difference.

I’m wondering if the code I’ve put together is not the most optimal. I welcome any advice you may have.

Many thanks

1 Like

Try adding the shuffle after you select the source

Many thanks Syrius. Is working much more reliably now. I still have to use a delay when unjoining/joining speakers before setting the source (give time for Sonos to catch up before sending further commands which get ignored).

Much appreciated.

I couldn’t help but notice the way you configure delay in your automation’s action.

- delay: '2'

That doesn’t correspond to anything I have seen in the documentation or in other examples posted in the forum.

To specify a delay of 2 seconds, the documented examples are:

- delay : '00:00:02'

or

- delay:
    seconds: 2

Thanks for the tip! I’ve changed my code to the correct syntax.