Sonos - play random album of artist

Hi there,

I am in need of creativity right here.
I have build a little jukebox for my toddler where he can start his favourite music or stories on his sonos speaker.
The files are all organized on a plex server.
Now if I want to play a specific song oder specific album everything ist great.
I can just run the “play_media” service and for example send:

'{ "library_name": "Music", "artist_name": "Adele", "album_name": "25", "track_name": "Hello" }'

for a specific song and:

'{ "library_name": "Music", "artist_name": "Adele", "album_name": "25"}'

for a specific album.

But for his stories I want him to have a random album by a specific artist. But:

'{ "library_name": "Music", "artist_name": "Adele"}'

always plays the first album.

If I do:

'{ "library_name": "Music", "artist_name": "Adele", "shuffle":1}'

it plays a random album - which is great. But it starts with a random song of this album and also shuffles inside of the album, which I don’t want it to do.

Any ideas how I can get to my goal?


You’re in luck as advanced searches were just added to Plex in 2021.11. See the linked docs above for more details.

To achieve what you’re looking for, you can add the sort and libtype keys to your search:

'{ "library_name": "Music", "artist_name": "Adele", "libtype": "album", "sort": "random", "maxresults": 1}'

This will play a single random album. If you want continuous playback of all albums by the artist in random order, you can omit the maxresults key.

Thank you - but then I am actually out of luck at the moment.
Because of a ZHA Issue I am stuck on 2021.09 and can’t update at the moment…
But then after the update this should work. Thank you.

Any progress on this? I have all sorts of stuff that would benefit from random playback (kids’ cartoons on Kodi, Sonos, Spotify) but I can’t get any of them to play back randomly reliably. Trying various ways for two years to no avail. Seems like a small ask but… Thanks!

The marked solution works just fine. I updated to the newest home assistant version and all the advanced searches work for me. What are you having problems with?