This object is in archive! 

Any way to obtain the current volume of a Sonos device?

David Pritchard shared this question 7 years ago
Need Answer

Is there any way to obtain the current volume of a Sonos device? My Sonos devices don't fit into the "sensor" or "meter" pieces, so there seems to be no way to query them to find out what the current volume is (or the current URI).

Replies (14)

photo
2

no, you are right, there is no way to get any values from sonos. Damn, how can you create a rule to match volume on all speakers.


Then again, I find the sonos integration only half done anyway. No TTS options, no easy way to group some speakers, no way to get a selection of even your favourite playlists. I thought to reason for the puzzle system was to avoid having to use http for these things.

photo
1

Yes, more work is needed. In the morning sometimes I play a sound warning about rain, and after the sound is played I want to return to whatever the volume was on each speaker - but I have no way to know.


Do you know how to group speakers using HTTP? I've never got around to investigating it.

photo
1

There's nothing like asking someone a question to prompt you to go and find the answer yourself :-)


I think I need to use the x-rincon: prefix for all except the coordinator (the Sonos Connect) and x-rincon-stream for the Connect (to take line-in input, which is what I use).


I'll try it tonight.

photo
1

It works!! Also, the setting the URI of the Connect and Boost via the Zipabox devices (rather than via HTTP) also works.

photo
1

Can you share your rules David? Thanks in advance.

photo
1

well done david. Sorry but I would be no help in this matter. Did you even look at the Macronis app on android and debug it?


It would be great, if you have the time, if you could write up a info page or instructions on how you do alot of this with Sonos. I would love to be able to pause the music that is playing, play a notification over the whole sonos system, then restart the music again. Is this possible?

photo
1

See this post:


https://community.zipato.com/topic/how-to-operate-sonos-connect-with-http-post


I've updated it at the end with my latest modifications.


As for pausing, playing a sound, and then resuming, I don't exactly do that, but I have a rule that interrupts the radio to play a rain notification. See attachment. I think it should be possible. I'm a bit hazy on the details of what I'm doing the rule, so I'll have to check when I get home. Queuing should be involved somewhere, I think...

photo
1

What the rule does is first set the URI of the speaker where you want to play the alert to:


x-rincon-queue:RINCON_<MACADDRESSOFSPEAKER>01400#0


and then sets the URI to the MP3. I'm not sure why I do the first step. There must have been a reason for it, I can't remember.

photo
photo
1

In this post (in German):


https://www.symcon.de/forum/threads/3541-Einzelne-Sonos-Player-ansteuern


There's a handy list of Sonos commands you can issue via HTTP (below).


What I don't know is if this alone is enough to do the pause/resume thing. I have my doubts. If you did this:


Set URI to Spotify playlist

Play

Pause

Add alert MP3 file URI to queue

Set current item to MP3 (using next/previous)

Play

Set current item back to Spotify playlist (using next/previous)

Play


would it save the context in your Spotify playlist, and resume from there? I kind of doubt it. But I don't know.


  1. //--- Nix verändern ab hier

    $content_pause='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 252

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Pause></s:Body></s:Envelope>';


    $content_play='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 266

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>';


    $content_next='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 250

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Next></s:Body></s:Envelope>';


    $content_previous='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 258

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:Previous></s:Body></s:Envelope>';


    $content_rewind='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 296

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Unit>REL_TIME</Unit><Target>00:00:00</Target></u:Seek></s:Body></s:Envelope>';


    $content_setvolume='POST /MediaRenderer/RenderingControl/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 32'.strlen($volume).'

    CONTENT-TYPE: text/xml; charset="utf-8"

    SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>'.$volume.'</DesiredVolume></u:SetVolume></s:Body></s:Envelope>';


    $content_setmute='POST /MediaRenderer/RenderingControl/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 314

    CONTENT-TYPE: text/xml; charset="utf-8"

    SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>'.$mute.'</DesiredMute></u:SetMute></s:Body></s:Envelope>';


    $content_setplaymode='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: '.(291+strlen($mode)).'

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetPlayMode xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><NewPlayMode>'.$mode.'</NewPlayMode></u:SetPlayMode></s:Body></s:Envelope>';


    $content_setradio='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: '.(974+strlen(htmlspecialchars($radio))).'

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <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>'.htmlspecialchars($radio).'</CurrentURI><CurrentURIMetaData><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="R:0/0/0" parentID="R:0/0" restricted="true"><dc:title>IP-Symcon Radio</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite></CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>';


    $content_clearqueue='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: 290

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:RemoveAllTracksFromQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID></u:RemoveAllTracksFromQueue></s:Body></s:Envelope>';


    $content_addtoqueue='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: '.(438+strlen(htmlspecialchars($file))).'

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><EnqueuedURI>'.$file.'</EnqueuedURI><EnqueuedURIMetaData></EnqueuedURIMetaData><DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued><EnqueueAsNext>1</EnqueueAsNext></u:AddURIToQueue></s:Body></s:Envelope>';


    $content_removefromqueue='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: '.(307+strlen($track)).'

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:RemoveTrackFromQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><ObjectID>Q:0/'.$track.'</ObjectID></u:RemoveTrackFromQueue></s:Body></s:Envelope>';


    $content_settrack='POST /MediaRenderer/AVTransport/Control HTTP/1.1

    CONNECTION: close

    HOST: '.$address.':1400

    CONTENT-LENGTH: '.(288+strlen($track)).'

    CONTENT-TYPE: text/xml; charset="utf-8"

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


    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Unit>TRACK_NR</Unit><Target>'.$track.'</Target></u:Seek></s:Body></s:Envelope>';

photo
1

But here's something that I'm pretty sure *would* work. Suppose you have a Connect + 3 Play:1s like me. You group them and play Spotify or whatever. Then to, play your alert, you pause, ungroup, choose one of the units to "save" your position in Spotify - let's say the Connect, set the URI of the MP3 in one of the Play:1s, group the rest of the Play:1s together with the Play:1 with the MP3 URI, play the MP3, ungroup, regroup with the Connect, Play.


Yes, it will be a long rule :-). But it should work. If you only have speakers, and no Connect, you'll need to choose one speaker that doesn't play the alert.


What's your setup Adrian?

photo
1

Right now I only have one Sonos speaker, which is a sonos Bar, so this won't work for me right now.

photo
1

Right now I only have one Sonos speaker, which is a sonos Bar, so this won't work for me right now.

photo
1

Why not the playbar? Somebody here said the playbar is supported now

photo
1

The problem is that you need more than one Sonos device for my trick to work. What I'm not sure about is, if you pause an item in the queue, switch to another queue item and play it, and then return to the previous one, is that context saved? I kind of doubt it but I don't know.

photo
1

Reading this, I'm pretty convinced that Sonos doesn't store that sort of state information.


http://forum.micasaverde.com/index.php?topic=8505.465


So that leaves us with the trick of using one Sonos device to keep the state whilst playing the alert on the others. Anything else requires code, or requires the ability to extract and save data from Sonos devices on the Zipabox, which we can't do.


Apparently Vera and HomeSeer have the ability to do this because they either have the option to use plugins, or because the Sonos integration is much richer.


For the Zipabox, it would be enough to have the current track and position available as attributes that we could query and save. Both are obtainable through simple HTTP calls. Using Google App Script or something similar to query the info and send it to the Zipabox is not really feasible because the script would have to run more or less non-stop, and you'd hit Google's limits on daily computer time. And you'd never have a way to capture the exact point in a track where you paused the music (at best you could run a script once per minute for a limited time each day). If you have a server at home that could host a script, that might work, but it's an extremely clunky solution.


The only good solution would be better Sonos integration by Zipato.

photo
1

Footnote: there is a way to trigger a Google App Script using HTTP POST. So the Zipabox could trigger a script, which could send information to the Zipabox... but unfortunately there's another problem. There's no way for the App Script to see the Sonos speakers because they're only available through local URLs. So no dice.

photo
photo
1

Oh and what's Macronis?

photo
1

Macronos is an android app for sonos. It allows you to set a custom command with a widget. The widget acts like a button or shortcut, that sets the group of speakers, sets the volume of each speaker, and sets the playlist and starts playing. You can create all types of custom commands with a single press of an icon this way. I used to use it with tasker and it has tasker plugin capability.


I just thought if you had a look at this app, and could debug it, you could see the commands sent all at once rather than sourcing the http commands yourself. Not sure if this would work. Hell, if i was Zipato, i would contact this guys and get him to write the script for Zipato with same functions.

photo
1

I didn't source anything, I used the work done by others that I've found here and there on the internet :-)

Sonos is supposed to publish the API, but it's taking its sweet time doing it.

photo
photo
1

ohh, and thanks. Nice work on this.


Basically I only have 3 zones setup here. Play 1's and play 5. I also have chromecast, playfi and Amazon echo's. A mixed system, but basically used for testing and experimenting with different platforms. What I want to accomplish is a way to get the Doorbird notification to trigger a virtual sensor in zipato, that in turn activates a doorbell mps over the sonos network. This is what I would use for clients. If you could do this, I would be very appreciative. Do you have a Doorbird? Want one?

photo
1

I don't have one, and I don't think I need one really. I live in a flat, so the motion sensor would be triggered by anyone using the stairwell. I don't miss deliveries because I have everything sent to the office (Spain's postmen never get up early enough to deliver a parcel when you're at home), and I'm extremely wary of any networked means of opening doors. I'll let other people play with that.

Does the Doorbird work with the Zipabox? Provided you can get a notification, the only problem is at the Sonos end.

photo
1

I have posted a solution for volume problem and for playing notifications with resuming current track afterwards. It is basically 2 php scripts implemented on my local web server.

photo
1

Adrian, I just stumbled on this post. Did you figure out how to do it? I can play MP3 sounds over the Sonos now, and I think I posted a how-to elsewhere on this forum. I can post the details here if you need them.

photo
1

all good thanks David. I moved on from sonos. Found it easier to install Echos and Echo dots attached to amps, etc and control with voice. Sonos, and all AV media for that matter, are not a priority with Zipato. A shame as this is what drives most customers and has high priority on other platforms, AV solutions. So we use other platforms for this now and side load the apks to clients Zipatiles. We also dont use Zipato UI anymore as it is so restrictive.

photo
1

Yeah. My current solution is far from ideal since there is no way to guarantee that the sound has finished playing before the line-in resumes (and if you want to return to a random source, i.e. whatever happens to be playing on the Sonos, you're screwed - in my case it's always line-in so I can write the rule to do that). The sounds are sometimes delayed and get cut off. Other platforms have a specific "alert" function that will play a sound and then return you to what you were playing.

photo
2

i know, there are a few good solutions out there, just not with Zipato. I dont know why they haven't developed a plugin for playing sounds to DNLA speakers yet or the voice message you can program the Zipatile to say to go straight to a sonos speaker or DNLA speaker. Everybody else has.

I tried using Tasker running on a Zipatile with Macronos app and using http requests from Zipato to Tasker to run a task that uses the Macronos Plugin for tasker. But if was such a stuff around.

Another thought I had was to use the bluetooth connection within zipatile to connect to a bluetooth speaker and broadcast via its built in voice message service, as it has no 3.5mm audio output, I cant share this with an input into a amplifier, so bluetooth speakers turn off and it doesnt work.

Lastly I looked into IEast audio devices https://www.ieast.net/ , they are quite good and have an open api that you can get that covers absolutely everything. But again, it is the lack of ability to truly integrate it into Zipato platform, i dont want separate virtual switches for doing everything and level controls. I want a virtual audio player that can be customized with these http commands. I'm giving up hope of any true Audio integration with Zipato.

photo
1

My current solution with Sonos and Zipato is acceptable because of the limitations of what I do and because I accept its quirks. But for a paid-for professional installation? No way. I think Zipato needs to focus more on the needs of system installers, and plug these gaping holes in functionality. Doing so would also make life easier for the rest of us.

photo
Leave a Comment
 
Attach a file