Sonos stream and playlist playback

Hi,

(Apologies if this is not the appropriate category for this post/question.)

I am building actions to trigger my Sonos and want to share what has worked for playback of streams. The development workflow goes roughly:

  1. Pick a Sonos speaker to work with and an appropriate app (iOS, Android etc)
  2. Press "Clear Queue"
  3. Select the desired stream to play and start it.
  4. Flip to the Hubitat device for the chosen Sonos speaker and examine the "Current States" on the RHS. Copy the "trackData" and paste it into a JSON pretty printer (e.g., Best JSON Pretty Print Online).
  5. Use the transportUri value as the track name parameter for the "set track" player command.

However, this technique doesn't work for playlists. Notably, a playlist has multiple tracks and if I follow a similar approach, the transportUri I arrive at is only the first track of the playlist. Worse, I don't see a way to enqueue the tracks for the playlist in the set track command.

The Current States JSON contains an enqueuedUri which looks suggestive. Does anyone know how to use it?

George

(Thanks to this post which gave me the ideas to work through the above: Sonos Play Track - Stopped State)

5 Likes

Thanks for your clear instructions. Do you think this works for tracks from Spotify?

I followed the instructions to a T, and instead of playing the desired Spotify track, it plays the existing track.

From Best JSON:
{ "audioSource": "Sonos Q", "station": null, "name": "Raising Hell (feat. Big Freedia)", "artist": "Kesha", "album": "Raising Hell (feat. Big Freedia)", "trackNumber": "1", "status": "playing", "level": "20", "mute": "unmuted", "uri": "x-rincon-queue:RINCON_7828CAE4EC7201400#vli", "trackUri": "x-sonos-spotify:spotify:track:3Ex5RFJRUdpHcDOLXJOVLy?sid=12&flags=0&sn=4", "transportUri": "x-rincon-queue:RINCON_7828CAE4EC7201400#vli", "enqueuedUri": null, "metaData": "Morning Alarm<\\/dc:title>object.container.playlistContainer<\\/upnp:class>SA_RINCON3079_X_#Svc3079-0-Token<\\/desc><\\/upnp:albumArtURI><\\/item><\\/DIDL-Lite>", "trackMetaData": "x-sonos-spotify:spotify:track:3Ex5RFJRUdpHcDOLXJOVLy?sid=12&flags=0&sn=4<\\/res>https:\\/\\/i.scdn.co\\/image\\/15dea9a1cbd61b6f71c8827f920bde4892f42ac2<\\/upnp:albumArtURI>object.item.audioItem.musicTrack<\\/upnp:class>Raising Hell (feat. Big Freedia)<\\/dc:title>Kesha<\\/dc:creator>Raising Hell (feat. Big Freedia)<\\/upnp:album><\\/item><\\/DIDL-Lite>" }

Did anyone find a solution here?
I'd like to automate Sonos playing music when I"m "Away" and am also struggling to figure out how to get Sonos to play a specific playlist. I could be fine with a track if it's reliable and I'll get long hour-long set or something.

Appreciate any pointers.

I am still looking for this solution also.

Take a look at * Sonos Favorites Support*.

Maybe it’s not exactly what you’re looking for but it has worked for me.

I use it for some RM rules as switches that turn on when, for example, there is motion on my dressing room in the morning when I walk in, and plays a Spotify playlist, or specific song, or the news.

https://raw.githubusercontent.com/schwark/hubitat-sonos-favorites/main/sonos-favorites.groovy

1 Like

Much appreciated but I'm too lazy to learn groovy. Was hoping for something using the UI. I know it's slow but like I said: too lazy. :blush: Also, using a playlist residing the PC. :face_with_diagonal_mouth:

I'm working on an App for Sonos speakers that supports playing "Sonos Favorites", and it's mostly "using the UI". You'll need to set up a (free) Sonos developer account to get a client secret and client key for it to work, since it uses the Sonos Cloud API for some things.

As for playing Favorites, there's a button "getFavorites() which displays all your current Sonos Favorites in the Current States area of the device. It has the name of the song/album/playlist and the album art. To play a Favorite, you just get the number of the favorite (listed right next to the name/album art) and put it in the "loadFavorite()" button field and click the button. In an automation, you'd select "custom action" and "loadFavorite()" and provide the number.

I've played around with the "Sonos Favorites" app before and found it excessively annoying to use due to the need to figure out which dang "x-ricon..." thing it needs, as the Sonos devices in Hubitat list like 5 different ones and only one of them is the one that works.

My app also has 100% non-interrupting TTS ability, by utilizing the (cloud-only) "loadAudioClip" API. See more here: [RELEASE] Sonos Cloud Controller

I'm still working on development on it, and eventually will have fully replace the built-in Sonos app, but for now, you'll want to run both side-by-side as mine doesn't provide "current state" for most things, such as volume level, play/paused/stopped status, etc.

2 Likes

I will keep an eye out for the completed app. Thanks!