Controlling Sonos using HTTP requests?
-
You can control a Sonos device using the UPnP protocol over HTTP. Some examples can be found on:
http://forum.universal-devices.com/topic/11739-sonos-integration/But how do I send these kind of commands using the Internet request action in the Flic app for IOS? What goes in the URL field and what goes in the Body field when using POST mode? And does the content of the body have to be encoded or escaped?
If you have successfully programmed your Flic for controlling Sonos using UPnP commands, I would appreciate an example with the exact contents of your Internet request settings.
-Dennis
-
@bambi2000 Thanks. I did manage to get the basics working (as well as find the streams for P3 and P4 ). I also managed to group players by setting CurrentURI of the "slave" IP to the UUID of the "master".
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon:RINCON_XXXXXXXXXXXX1400</CurrentURI><CurrentURIMetaData /></u:SetAVTransportURI></s:Body></s:Envelope>
Now I just wish Flic would create some sort of copy function to make it easier to reuse those commands:-) And that Sonos would open their official API for better integration and remote control.
-
@thomas204 It's DR P1. Metadata is not needed to play the stream. I tried to use the metadata-tag to show the real name of the station rather than the file name (in this case A03H.mp3), but I didn't succeed.
-Dennis
-
@bambi2000 er det P3? Den prøver jeg at kopiere
Doesn't it need metadata? -
@thomas204 I haven't tested case sensitivity, but I have got a lot of "internal server errors" too, while trying to get the commands working, so I have have just followed the examples I have come across literally. Also, in my setup the contents of the body field is one long string.
Then following example selects a specific radio stream (the rest of the fields are identical to those in my previous post):
Body:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon-mp3radio://live-icy.gss.dr.dk/A/A03H.mp3.m3u</CurrentURI><CurrentURIMetaData /></u:SetAVTransportURI></s:Body></s:Envelope>
-Dennis
-
Hmm. (minor) Progress. I managed to send a "play" command to one player but I am not able to tune it to a radio station or add a player to a group (I found a thread mentioning that setting currentURI to x-rincon:{UUID of master} should do the trick).
Any attempt at setting currentURI returns error 500:-(/Thomas
-
@bambi2000 thanks! Apparently this is over my capabilities:( All I get is an internal server error (500). And I also have a little trouble actually desciphering the command part of the code.
How sensitive is the code to case? And should it all be one long string or are there any CR's (looks like there is one)./Thomas
-
@thomas204 Sure, I havn't tried to group or ungroup players using requests, but here is the request that selects Line-In as input:
URL:
http://192.168.172.67:1400/MediaRenderer/AVTransport/Control
Method:
POST
Body:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>x-rincon-stream:RINCON_000E5887151E01400</CurrentURI><CurrentURIMetaData /></u:SetAVTransportURI></s:Body></s:Envelope>
Content type:
text/xml
Key:
SOAPACTION
Value:
"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
You will have to replace
192.168.172.67
with the IP address of your Sonos device, andRINCON_000E5887151E01400
with the identifier assigned to your Sonos device (I think the last part is the MAC address).-Dennis
-
@bambi2000 Any chance you could post an example with the exact contents of (one of) your internet request settings?
I would like to have (for a start):
- A Flic button group 3 players, then start a specific radio station
- Another button that ungroups if grouped and then starts playback of a different favorite on a single player
Is that possible?
I am sure if I could get an example of the basic "framework" needed then i should be able to tweak the commands myself
/Thomas
-
@anton Custom headers was implemented some time ago, and I have successfully created requests that allows me to toggle between playing from line in, the queue and radio stations -- my own preset button for Sonos!
-Dennis
-
Anything happening here?
-
Hi Anton,
I'm jumping in on this topic.
Since I have Sonos in multiple rooms I got myself 4 flic's but the options are not sufficient for what I thought would be possible.The scenario's I was thinking about;
- Leaving the house;
I placed a Flic at our entrance. By pressing it, it should stop all Sonos players from playing. Some of them may be in a group, some stand alone.
There is an option for "toggle" but that would start not-playing speakers.
The I thought of using "pause". Same problem here. When there's another sonos not playing, that one would start playing.
It would be wonderfull to have an option like "Stop all playing speakers"
- Turn on specific channel or spotify playlist on set-volume
In the morning we listen to a news radio station. I intended to put a button in the bathroom which, when clicked once, would a) remove the bathroom speaker from any groups (so music only plays there) b) select the desired radiostation c) set the speaker to a fixes volume.
At the same time I would also like to be able to do the same for a Spotify playlist and have it play my "Starred" list on shuffle.
I was thinking of solving it on my own by installing a Raspberry Pi and running something like https://github.com/SoCo/SoCo but seeing you're looking into this I was thinking it might help to share my ideas with you.
Kind regards,
Jaap
- Leaving the house;
-
-
@anton I would love to see some more Sonos actions. These are the tasks I do everyday:
- With bedroom, Replace queue with Sonos playlist "good night Ebba"
- With bedroom, Set Volume to 10
- With Lukas, Replace queue with Sonos favorite "goodnight.mp3"
- With Lukas, Set Volume to 15
- With Lukas, Set Crossfade to On
- With Lukas, Set Repeat On
- With Lukas, Set sleep timer to 45 min
And on my wish list I also would like to have a toggle button for two different Volume levels for the Sonos playing my TV sound. Watching movies when the kids are asleep I always have to turn the volume up and down (slow) when there is loud music or car crashes or someone whispers. TV remotes miss the button "Semi mute" and having this option with the press of a button would be super awesome!
-
-
@bambi2000 Btw, are there any particular features that you are looking for when it comes to the Sonos integration? I am actually working on it at the moment, so if you have any suggestions (beyond those already mentioned) then let me know!
-
@anton Thanks for the update!
-Dennis
-
@bambi2000 Improvement to the Internet Request action is in our roadmap, but I can not comment on when it will be released. Although custom headers it is a commonly requested feature so I hope we will be able to add it soon. We are currently also looking at making improvements to the Sonos action itself in order to extend the features there. For example to select songs and playlists.
-
My Sonos devices already have a button for play/pause/next, so I would like to use my Flic to select what to play, like a predefined radio station, the line-in or the queue.
I thought I saw a post saying that custom headers for the Internet request was added recently, but apparently it isn't true. Is it in the works?
-Dennis
-
Hi!
Although it should be possible to do this, the Internet Request action doesn't have support for adding custom request headers, which is needed for Sonos. It would also be a real pain to set Sonos up like this.
May I ask why you are not using the Sonos action? Is it something you are missing?