HTTP Post Command Reference for Tasker


Badge
I'm new to Sonos, but would like to setup some Tasker tasks in Android to automate playing my favourite radio station, launching playlists, etc.

Is there a reference for http POST commands that I could work from? Could someone point me in the right direction?

My aim is to use Tasker with NFC tags to activate theses common tasks without the need to go into the app.

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

27 replies

Userlevel 4
Badge +14
Hi,

I'm trying to have Sonos either play a song or use TTS so the doorbell could be heard through my speakers.

I can currently send commands such as play, pause etc from my HA system via the following method:

/MediaRenderer/AVTransport/Control

SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"

01

I have seen the following API which would be perfect for me: https://github.com/jishi/node-sonos-http-api/blob/master/README.md

However I'm having some difficulty making this work in the XML format above. Can anyone assist me please? I'm not an expert coder but I'm relative competent Engineer with some moderate experience in coding. Just need a URL effectively that I can execute in my browser to give a specific function, like: ipaddress/Kitchen/favorite/[favorite name] or ipaddress/Office/say/Someone%20is%20at%20the%20door

Any tips would be greatly appreciated


The link that you referenced is actually a gateway software that converts that simplified URL scheme to the actual Sonos UPnP calls. If you don't want to use that, you will need to look into the UPnP spec, and mimic the SetAVTransportURI call (to switch media), followed by a Play call (which you already know how to do).

The SetAVTransport call should go to /MediaRenderer/AVTransport/Control with the SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"

code:

<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>{URI}</CurrentURI>
<CurrentURIMetaData>{MetaData}</CurrentURIMetaData>
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>



( the weird smileys is supposed to be [colon]S )

You will need to replace {URI} with a valid URI to what you want to play (in your case, a working http-url poiting to an mp3), and you might be able to just send empty metadata for that case. However, keep in mind that just playing an mp3 like this, will stop playback, and you will need to find a way to resume the playback afterwards for this to be really useful. It won't even be possible to hit play, since the queue will be inactive afterwards.
Badge
Thanks fantastic, thank you. Will post back if I ever work out how to implement it.
Userlevel 4
Badge +14
No problem. Feel free to get back to me if you need assistance with how to proceed, I have already done a lot of research on this, since I chose not to use a pre-made library for the uPnP part.
Badge
That's very kind. I've spent a few hours looking around the web and there doesn't seem to be much info.


All I want is to issue a command to Sonos to start playing a Radio Station (XFM London). I can then automate it with an NFC tag. What I can't work out is the syntax for the POST.

Here's a screenshot of the Tasker task:

http://dl.dropbox.com/u/7085178/Screenshot_2012-07-09-11-46-59.png

Any help would be much appreciated. d
Won't work without the correct "CurrentURIMetaData".

See this thread:
http://forums.sonos.com/showthread.php?t=22411 (#3)

🆒

Jochen
Badge
Sounds like this is way beyond my pay grade. I'm going to look at using the Vera plugin and HomeBuddy to achieve this.

Thanks for the comments.
Userlevel 4
Badge +14
Won't work without the correct "CurrentURIMetaData".

See this thread:
http://forums.sonos.com/showthread.php?t=22411 (#3)

🆒

Jochen


I don't speak german, but I believe that I actually managed to get it to work without the metadata. However, I do remember that I might have needed the x-rincon-mp3 prefix for it to work.

Nevertheless, it might be a little too hardcore trying to achieve this using Tasker.

Maybe a Sonos automation app for NFC and/or wifi might have a user case either way. Or a simple widget that has instant response...
Userlevel 2
I wanted to have a nicer experience when skipping to the next track in the queue.
It should ease down the volume, then change to the next track and then set the volume back to what it was originally.

I made a task with a "Script"->"Javascript" action.
In the "Path" field i chose a javascript file i have put on my phone with the following content.
Notice - you have to change the ip address to one of your controllers. You can get the ipaddress by looking at your internet routers dhcp log.

The javascript file called nextTrack.js. You can get it here:
nextTrack.js
Userlevel 2
The answear to Tasker and Sonos is called Macronos.
Is found at Google Play for Android.
Userlevel 2
Today I managed to start my bedroom sonos direct from the built in android alarm on my phone.
Simply build a macro from macronos app add it as a task in tasker app, and pair the two.
I know the sonos has a alarm in the software but its a lot easier to control every thing from my phone.
Userlevel 2

The javascript file called nextTrack.js. You can get it here:
nextTrack.js


Hi mdn (and others),
could anyone make this file available again, please? I'm trying to build my own solution and I'm completely lost in trying to make tasker send UPnP commands. I'd love to have a reference to "steal" from :rolleyes:

Unfortunatly I cannot send a PM to mdn, as I'm too new to this forum (min 5 posts to send PMs... !?)
Hi,

I'm trying to have Sonos either play a song or use TTS so the doorbell could be heard through my speakers.

I can currently send commands such as play, pause etc from my HA system via the following method:

/MediaRenderer/AVTransport/Control

SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"

01

I have seen the following API which would be perfect for me: https://github.com/jishi/node-sonos-http-api/blob/master/README.md

However I'm having some difficulty making this work in the XML format above. Can anyone assist me please? I'm not an expert coder but I'm relative competent Engineer with some moderate experience in coding. Just need a URL effectively that I can execute in my browser to give a specific function, like: ipaddress/Kitchen/favorite/[favorite name] or ipaddress/Office/say/Someone%20is%20at%20the%20door

Any tips would be greatly appreciated
You legend, thanks for responding so soon. I'll have another go at it and let you know how I get on. Thanks again.
Hey sck1988, did you ever get this too work? I'm also looking for a clever way to get multi-room audio where people can be listening to anything in their own room, to be interrupted by something of a higher priority. The doorbel is a fantastic example. Use case is indeed: all music in all rooms is muted and overridden with a broadcast going to all rooms. Once broadcast is over, all rooms should just continue playing whatever they were playing before.
Unfortunately not yet.

I've tried the following:

I also tried it with a URL direct from youtube and it didn't work.

jishi any ideas, am I doing something wrong here?

/MediaRenderer/AVTransport/Control

SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"

code:
0x-file-cifs://Stefan-Knights-iMac/Downloaded%20by%20MediaHuman/doorbell.mp3
Userlevel 4
Badge +14
What response do you get? 500 Error? Could you please post the complete XML using http://pastebin.com/ or something? This new forum doesn't handle XML very well.
For some reason it's not showing all the code even though I used:
code:
code:
0x-file-cifs://Stefan-Knights-iMac/Downloaded%20by%20MediaHuman/doorbell.mp3
Userlevel 4
Badge +14
Just a heads up, I have given that idea a real test, and I will just warn you, it's very hard to get it reliable because of a few things:

You need to find a way to wait for all your zones to group together before starting playback, otherwise some of them will not play the whole track.
A lot of automatized control signals like this tends to generate a few errors (control signals that doesn't get received), so you will need to handle retries well.
Some of your audio sources will be hard to restore correctly, some might even be impossible. Think Deezer flow and other curated radio stations from certain music services.
Userlevel 4
Badge +14
For some reason it's not showing all the code even though I used:
code:


You need to escape all your XML with entities, &lt; and &gt; etc, in order to show it here. Better use pastebin, cause it will auto insert emojis as well, very dumb indeed.
http://pastebin.com/CbnHmVs2
I just executed the command and it didn't do anything on my sonos. my other commands like play, pause and queue are all working.
Userlevel 4
Badge +14
If that is the exact XML you are sending, then you have a typo. It's called <setAVTransportURI>, not <uetAVTransportURI>
Yes that was the exact xml. I've changed that now but I still get nothing. I just tried the following, this is everything I've used:
http://pastebin.com/QWgCqCg0
Userlevel 4
Badge +14
Well, you can't just play a YouTube url either. It needs to be a direct link to a well known file format, like an mp3.