Sonos playlists etc?

@homeauto2112, what type of music were you playing to get the uri and where exactly did you get extract it from.

@stephack that was my Miles (as in Miles Davis) playlist.

@bill.d I got it from the state variables of my Kitchen Sonos in HE. I loaded the Built In Sonos app and then I used the Sonos app on my Mac to pick what I wanted to listen to. I lifted the URI after the music started playing and I refreshed the webpage on the device.

You can use the API to set presets and then an HTTP Get to access them (http://IP address:5005/preset/nameofpreset)

@homeauto2112 What specific variable did you get it from ....a uri, a subset of the TrackData?

Screen shot PM'd to you.

My point was that to get that URI you have to be running the Sonos HTTP API node app. Port 5005 is not a Sonos port. And the URIs generated by Sonos app or Spotify app as shown in HE are different in format and don't seem to work.

I worked with @homeauto2112 and we realized that the working uri that he posted was for a Spotify Radio stream and not a playlist. For radio streams, the Sonos Preset app will get the right uri and it should work. Spotify playlists however do not present a usable uri to the HE Sonos speaker driver.

Long story short....Radio streams work, playlists do not. If there is a way to get a working uri for Spotify playlists, it is above my head.

@stephack, take a look at jiishi’s node api here

https://raw.githubusercontent.com/jishi/node-sonos-http-api/master/lib/music_services/spotifyDef.js

You can see in the method getURI how he constructs the URI for Spotify. I don’t have a Spotify account so I can’t test it but maybe it will help you getting some more information on what to look for.

Thanks @dan.t. I actually did just that yesterday. There appears to be a lot of variables that need to be catered for and a complete breakdown and reconstruction of the uri. Most of it seemed beyond my limited groovy abilities. I'm not sure why the playlists can't generate a usable uri when the Radio stations do but that difference makes it a non starter for me.

Agreed, I don't think it will be a simple thing to solve by just evaluating the states exposed within HE. I think there will be some wireshark or a much more detailed code review of jiishi's library necessary to solve that "issue"

1 Like

I went ahead and installed the Sonos HTTP API node app. Here are a few observations/conclusions:

  1. Spotify URIs won't play on their own in the API app or Hubitat. User authentication is required. From the Github readme:

Note for Spotify users!

To use Spotify, go to spotify-for-developers and create a Spotify application to get your client keys. You can name it Sonos or anything else and you don't have to change any values. Use the Client ID and the Client Secret values in the settings.json file as indicated above.

  1. It is possible to get around the Spotify authentication issue by using the Sonos favorites - just save the Spotify playlist as a Sonos favorite. The Sonos HTTP API url to play the favorite is simple:
    http://localhost:5005/[zone name]/favorite/[favorite name]

  2. There is no "Play Favorite" functionality in the Hubitat driver or as a custom action. I think it would be nice to have, for favorites from any source, not just Spotify. @mike.maxwell

With respect to point 2 & 3, you can set presets. The preset (whatevername.json) holds the speakers desired in a group, the volume level of each device and the name of the favorite station (Radio, Spotify, Apple Music etc).

With respect to point 3, can use a HTTP GET to start (shown in post number 18 above).

here are two other threads that I believe are orbiting a similar point.

I get all that. My point all relate to native Hubitat functionality. If Hubitat driver had the ability to play a Sonos favorite (that is a Spotify playlist) then there would be little need to run the node app other than for grouping.

And as useful as the grouping function might be, without the ability to set or control Trueplay settings it's of little use to me as Trueplay makes a big difference in my room where I want to be able to change groups.

Got it. There are a few things that the driver needs and I believe that's what is driving these other "solutions." That said, @mike.maxwell indicated on the last HE live video that he would rather focus on Chromcast for a bit.

I just read through the jishi readme and he has updated this Api quite a bit since I looked at it early last year. I actually had a basic driver working before HE released their Sonos integration and I scrapped it.

@homeauto2112, @dan.t, how solid has this Api been...especially with regard to grouping and playback?

@stephack

jishi's node-sonos-http-api has been rock-solid for me for groups (2 Sonos speakers), and for playing presets. Been using it for ~2-3 weeks 1 month exactly (just checked).

:point_up: :point_up: :point_up:
Have been using it for so long, I can’t even remember when I installed it.... just rock solid front to back

:+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1:

Just to add to this, the sonos integration is pretty much in maintnence at this point, primarily due to Sonos continuing to threaten deprecating the dlna api that we use. Our next overhaul, whenever that may be, will be an implementation against their new api.

IFTTT has the ability to import Sonos Favorites, so it's fairly straightforward to trigger a Sonos Favorite (which can be a playlist or station on Spotify/Deezer/Apple Music/etc). This is fairly robust aside from the slight lag in talking too/from IFTTT.

Stephan,

Thanks for posting this code. My nighttime music automation has been buggy forever, and while trying to figure out how to do it better, i ran across this old thread.

The presets are brilliant. I saved some Pandora favorite "channels" to my Sonos "stations" hit play, pulled the URI from the Sonos device page in Hubitat, and added 3 others. Using the container "switches" was brilliant for a supplementary dashboard interface, and they simplified my rule dramatically.

I think reliability on my rule will be improved, and testing indicates it will, but only time will tell!

Again, thanks for this!

Scott

1 Like