This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

SONOS commands to group players
#4
Hi,

To group players you need set the uri of each player to the master player. note as you add each player to the group,  this takes time to do, which is why there is an sleep added after each player is placed into the group. Once you have groups the players, set their volume then you can set what to play on the master.

 One BIG note to point out when you work with SONOS implementation you will need to make sure that ALL sonos players are be configured with a static IP.  The only way to do this is use DHCP reservation which is configured for each player in the router.


Event based script

Code:
   upnpavcmd('192.168.0.24', 1400, 'Stop')    upnpavcmd('192.168.0.24', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>40</DesiredVolume>')    uri = '<CurrentURI>x-rincon:RINCON_000E58DC0F3601400</CurrentURI><CurrentURIMetaData/>'    upnpavcmd('192.168.0.8', 1400, 'SetAVTransportURI', uri)    os.sleep(1)    upnpavcmd('192.168.0.9', 1400, 'SetAVTransportURI', uri)    os.sleep(1)    upnpavcmd('192.168.0.20', 1400, 'SetAVTransportURI', uri)    os.sleep(1)    upnpavcmd('192.168.0.25', 1400, 'SetAVTransportURI', uri)    os.sleep(1)    upnpavcmd('192.168.0.8', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>20</DesiredVolume>')    upnpavcmd('192.168.0.9', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>20</DesiredVolume>')    upnpavcmd('192.168.0.20', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>20</DesiredVolume>')    upnpavcmd('192.168.0.25', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>20</DesiredVolume>')    upnpavcmd('192.168.0.24', 1400, 'SnapshotGroupVolume')    uri = '<CurrentURI>pndrradio:2496906846458345314?sn=1</CurrentURI>'    meta = uri  .. '<CurrentURIMetaData>&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;&lt;item id=&quot;OOOX2496906846458345314&quot; parentID=&quot;0&quot; restricted=&quot;true&quot;&gt;&lt;dc:title&gt;Rihanna Radio&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.audioItem.audioBroadcast&lt;/upnp:class&gt;&lt;desc id=&quot;cdudn&quot; nameSpace=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;SA_RINCON3_massimo@massmore.com&lt;/desc&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</CurrentURIMetaData>'      upnpavcmd('192.168.0.24', 1400, 'SetGroupVolume', '<Channel>Master</Channel><DesiredVolume>40</DesiredVolume>')    upnpavcmd('192.168.0.24', 1400, 'SetGroupMute', '<Channel>Master</Channel><DesiredMute>0</DesiredMute>')    upnpavcmd('192.168.0.24', 1400, 'SetAVTransportURI', meta)      upnpavcmd('192.168.0.24', 1400, 'Play', '<Speed>1</Speed>')

Common Function

Code:
   function upnpavcmd(host, port, cmd, param)    local client, soap, reqs, service, res, err        require('socket')    client = socket.tcp()    client:settimeout(3)        -- try connecting to upnp endpoint    res, err = client:connect(host, port)    if not res then    return nil, err    end        -- guess service name based on command  if cmd =='SetGroupVolume' or cmd == 'SetGroupMute' or cmd == 'SnapshotGroupVolume' then    service = 'GroupRenderingControl'  elseif cmd == 'SetVolume' or cmd == 'GetVolume' or cmd == 'SetMute' or cmd == 'GetMute' then    service = 'RenderingControl'    else    service = 'AVTransport'    end      -- soap envelope    soap = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' ..    '<s:Body>' ..    '<u:' .. cmd .. ' xmlns:u="urn:schemas-upnp-org:service:' .. service .. ':1">' ..    '<InstanceID>0</InstanceID>' ..    (param or '') ..    '</u:' .. cmd .. '>' ..    '</s:Body>' ..    '</s:Envelope>'        -- http request    reqs = 'POST /MediaRenderer/' .. service .. '/Control HTTP/1.1\r\n' ..    'CONNECTION: close\r\n' ..    'HOST: ' .. host .. ':' .. port .. '\r\n' ..    'CONTENT-LENGTH: ' .. soap:len() .. '\r\n' ..    'CONTENT-TYPE: text/xml; charset="utf-8"\r\n' ..    'SOAPACTION: "urn:schemas-upnp-org:service:' .. service .. ':1#' .. cmd .. '"\r\n' ..    '\r\n' .. soap        -- send http request    res, err = client:send(reqs)    if not res then    return nil, err    end        -- get reply and close connection    res, err = client:receive('*a')    client:close()        return res, err    end


thanks,

Roger
Reply


Messages In This Thread
RE: SONOS commands to group players - by rocfusion - 07.07.2016, 13:34

Forum Jump: