How to operate Sonos Connect with HTTP POST

David Pritchard shared this idea 7 years ago
Under Consideration

I have finally managed to fully operate my Sonos setup 100% from the Zipabox. I have a Sonos Connect that receives line-in input, and three Play:1 speakers. What I have done until now is turn the Sonos components on and off via Z-wave on/off sockets, to avoid having the system on all day and using power. But I wasn't able to group the components, or operate the Sonos Connect in any way via the Zipabox - until now.


What I have done is not exactly group the players. I still don't know how to do that. What I've is use two HTTP POST commands to set the Sonos Connect to line-in input, and to play it. Then I use the Sonos integration of the Zipabox to set URIs of the Play:1s to the Sonos Connect, and play them. The result is that I get the same sound from all sources just as if they were grouped.


I've just now got this working, so I hope there isn't some last glitch that I've missed. It seems to OK. The real test will be on Monday morning when the radio is supposed to come on.


I'm posted my two rules:


1. One rule turns on the Sonos components via the Z-Wave sockets, waits a bit, and then invokes the "subroutine" that does all the rest.

2. The subroutine is invoked via a switch. The first thing it does is turn the switch off (otherwise it can never again be invoked). It must first wait 2 seconds, because otherwise the 2 changes to the switch state happening in rapid succession won't work. It then sends the HTTP request to connect the Sonos Connect to the line-in source, and another to start it playing. Each Play:1 is then set to take the Sonos Connect as the source, their volume is set and they're set to play. The Plays need to be sent the RINCON address, which is the MAC address of the Sonos Connect. You can find this out by going to this URL:


http://192.168.0.20:1400/status/perf


where 192.168.0.20 is the IP of your Sonos Connect. It may take some trial and error to find this out. Go and have a look at the IPs of the devices shown in your router. You'll see a line something like this:


currently: PAUSED_PLAYBACK x-rincon-stream:RINCON_xxxxxxxxxx01400


That last bit is the MAC address you need (all have 01400 added to the end. You must also include that.)


3. The HTTP Post to set the Connect to line-in sends as the URI the MAC of the Sonos Connect itself! At least that's what I'm doing right now. It seems to work. So it's the same number as above.


4. The HTTP post to play the Connect is simpler, not much to say here. I stole it all from web sites hither and thither.


Be careful with the syntax of the HTTP POST body. It's sensitive to things like whether the quotes are double or single (they should be double).


I'll be interested to see whether this works for anyone else.

Replies (16)

photo
1

I've confirmed that this works a treat. The radio came blaring out of the speakers on this morning.


One thing: you need to know the IP address of your Sonos Connect. So the best thing to do is to make it a static IP with your router, if possible. Unfortunately my router can't do that. At the moment it seems to always assign the same IP to each device, but if that should change you can try a blunderbuss approach and just send out HTTP requests to a range of IPs where the Sonos Connect could be.

photo
3

Great work, David!


I don't have any Sonos devices, but I own two Chromecasts. When I have time, I will try to get them to work with the Zipabox. I will post my findings in the community.


PS: Normally there are two ways to get "static" IP adresses on the router. One is to assign it to static (no DHCP), another is configuring the DHCP of your router to allways assign a specific IP address to a certain MAC-address.


Are you able to assign a static IP adress in your Sonos config? So that Sonos has a static IP address and is not using DHCP on the router?

photo
1

I don't think Sonos has that option, no. Its configuration is rather sparse unfortunately. I'll see how things go over the next days and weeks. I've set my PCs to static IPs, but I don't think I can control the majority of my other devices.

photo
2

Nice, thanks for sharing.

photo
1

you can give your SONOS static IP by setting this up in your router via DHCP. I set up all my home equipment with a fixed IP address.

photo
1

unless, not 100% sure, you use the sonos bridge, which creates its own wifi network.

photo
1

Unfortunately my router doesn't have that option.

photo
1

I think with most routers you should be able to configure DHCP settings somewhere. I have a main modem connecting to a router/wifi who via cable connect to 2 sepeate wifi access points, and regardless where I connect to, I'm on the same network with the same IP (I fixed IP for my phones as well).


If not, why not switch router, they only cost $100 or so. It took me some time however to sort all these routers and access points out :-)

photo
1

Well I'd rather not. In my experience so far the Sonos devices all get assigned the same IP address - not sure why.

photo
2

The Sonos Connect seems to be supported now. It was detected automatically just like my Play:1 and Play:5 speakers. And I can control it.

photo
1

Oh really?? That's news!

photo
photo
1

I figured out how to group speakers. It's actually super easy. Instead of x-rincon-stream:, you use x-rincon: for the speakers (pointing them to the controller, Sonos Connect in my case). If you don't have the Connect, I imagine you would pick one speaker and point the rest to that one.


Just tried it, and it works.

photo
1

thats sounds easy. Whats a x-rincon stream? No really, would be nice to achieve this without to much hassle. Have you created a virtual switch for each group? And when activated groups those speakers? If so, a little tutorial would be greatly appreciated.


I would love something like the macronis app in Zipato. A way to create a virtual switch that activates a certain group and at predefined volume and playlist. And a TTS puzzle box.

photo
1

First take a look at what I posted above. Here is the new version of the rule. I've removed the HTTP requests, added some constants in place of the hardwired volume numbers and altered the Play:1 URIs from x-rincon-stream to x-rincon, played with the order a bit, and altered the switch that triggers the subroutine so that it works with "any" rather than just when the switch goes on (much easier). Also I've added a Boost to my system so I've included that too.


The Connect and all the plays are sent the MAC address of the Sonos Connect. x-rincon-stream tells the Connect to take the input from line in. x-rincon tells the Plays to group with the unit whose MAC address they are being sent (the Connect).


Connect:

x-rincon-stream:RINCON_<MAC-Address-of-Sonos-Connect>01400


Play 1s:

x-rincon:RINCON_<MAC-Address-of-Sonos-Connect>01400


If you had just three standalone Play:1s, I would imagine that you'd choose one Play:1 to be the source and set that to whatever sound source you need. You'd need to do some investigating to find out exactly what URI you need. Then the other two Play:1s would be sent a URI with the MAC address of the Play:1 acting as the sound source, plus x-rincon, meaning they group with that speaker:


x-rincon:RINCON_<MAC-Address-of-coordinating-speaker>01400

photo
1

great thanks. Could you, to make this easier and faster, create a variable with those x-rincon mac address, so you can constantly group and ungroup the speakers?

photo
1

Sure, no reason why not.

photo
1

Ahh, it looks like you can't. Annoyingly, variables seem limited to numbers only. String handling is a big hole in the Zipabox.

photo
photo
1

Hi


this is great. I managed to get my Zipabox to start my whole tv system and switch 2 Sonos devices to linein with the help of this post! Thank you very much.


What I would like to do is also to start playing music from my amazon account through sonos.


I get this URI


"x-sonos-http:library%2fartists%2fBruce_20Springsteen%2ftracks%2f1261c353-584e-4050-bc55-90b5ea71f687%2f.mp3?sid=201&fla"


But if I put this into URI of my sonos device it doesn't work!


Does someone have an idea if I have to replace all these %2f in the string with something else? Or any other ideas how this could work?


I think it is the same pattern as with playing Spotify. Did someone manage to start playing Spotify music?


Thank you for your help.


Beat

photo
1

Try replacing %2f with /

See if that works.

photo
1

Thanks David, I tried this but it is not working...

photo
1

Try replacing the ampersand with & as per this:

https://github.com/SoCo/SoCo/issues/25

photo
1

OHHH!! You are a star! It looks like this could work!


Will try later tonight...and reply here.


Thank you very much.


Beat

photo
1

Hi David


Finally I've got it working! Your link and hint was the thing which did help:


I had to replace all & at the end with &


Thank you very much for your help.


Do you have an idea how to play a whole album or a playlist?


Regards


Beat

photo
1

Brilliant!

I think then you have to get into queues, which I've never managed to completely get working. I plan to do some more experiments with them at some point.

photo
1

Hi

have bring back this thread to life! I tried to change of my sonos "configuration" yesterday and realised that http://192.168.0.20:1400/status/perf => status/perf on my sonos is not working anymore. Sonos has disabled this function since firmware 7.x.

Any ideas how to find out what a specific sonos player is playing...so how to find out the URI?

Thank you for your help.

Beat

photo
1

I don't use that in my system, so I have no idea. It's really annoying when they start breaking functionality like that.

photo
Leave a Comment
 
Attach a file