Skip to main content
Trending Lyricist I
July 8, 2012

HTTP Post Command Reference for Tasker

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

    Lyricist III
    October 29, 2015
    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
    Headliner II
    October 29, 2015
    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.
    Lyricist III
    October 30, 2015
    You legend, thanks for responding so soon. I'll have another go at it and let you know how I get on. Thanks again.
    Lyricist I
    November 10, 2015
    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.
    Lyricist III
    November 11, 2015
    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
    Headliner II
    November 11, 2015
    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.
    Lyricist III
    November 11, 2015
    For some reason it's not showing all the code even though I used:
    code:
    Lyricist III
    November 11, 2015
    code:
    0x-file-cifs://Stefan-Knights-iMac/Downloaded%20by%20MediaHuman/doorbell.mp3
    Headliner II
    November 11, 2015
    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.
    Headliner II
    November 11, 2015
    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.