Sonos uses standard UPnP so there are some libraries / examples available which you can use as a starting point, like this one: https://github.com/bencevans/node-sonos/
23.11.2015, 11:44 (This post was last modified: 23.11.2015, 11:48 by gjniewenhuijse.)
(23.11.2015, 08:08)Dadmin Wrote: Sonos uses standard UPnP so there are some libraries / examples available which you can use as a starting point, like this one: https://github.com/bencevans/node-sonos/
For queuing you should use AddURIToQueue command.
Yes but it is not so easy:
- get uri for playlist A or B?
- clear queue
- insert playlist into queue complete, or item by item?
- optional: repeat or shuffle queue
- play from first track
We don't have any Sonos devices so what we can help with is limited.
You can use Node.js library with debug enabled to monitor which kind of requests are being sent and then implement the same thing in LM.
Some hints for your case:
- To find your playlist id (SQ:1 or similar), you need to get a list of all playlists and find it there
- Use RemoveAllTracksFromQueue to empty current queue
- Use SetPlayMode to set repeat / shuffle
- You don't have to add tracks one by one, you can load the whole playlist (stored queue) in one call
(23.11.2015, 12:49)admin Wrote: We don't have any Sonos devices so what we can help with is limited.
You can use Node.js library with debug enabled to monitor which kind of requests are being sent and then implement the same thing in LM.
Some hints for your case:
- To find your playlist id (SQ:1 or similar), you need to get a list of all playlists and find it there
- Use RemoveAllTracksFromQueue to empty current queue
- Use SetPlayMode to set repeat / shuffle
- You don't have to add tracks one by one, you can load the whole playlist (stored queue) in one call
Yes.. it works.
I attached a little bit changed upnpavcmd function.
And two new functions:
Code:
-- find all playlist
function getPlaylists(ip, port)
cBrowse = '<ObjectID>SQ:</ObjectID>' ..
'<BrowseFlag>BrowseDirectChildren</BrowseFlag>' ..
'<Filter>*</Filter>' ..
'<StartingIndex>0</StartingIndex>' ..
'<RequestedCount>25</RequestedCount>' ..
'<SortCriteria>*</SortCriteria>'
res,err = upnpavcmd(ip, port, 'Browse', cBrowse)
return res,err
end
-- add saved queue (playlist) to queue
function qPlaylist(pId)
uriprm = '<EnqueuedURI>file:///jffs/settings/savedqueues.rsq#'..pId..'</EnqueuedURI>' ..
'<EnqueuedURIMetaData></EnqueuedURIMetaData>' ..
'<DesiredFirstTrackNumberEnqueued>0</DesiredFirstTrackNumberEnqueued>' ..
'<EnqueueAsNext>1</EnqueueAsNext>'
return uriprm
end
-- find all playlist (run once and note playlist id)
res,err = getPlaylists(ip, 1400)
log(res)
And then you can use:
Code:
-- clear current queue
upnpavcmd(ip, 1400, 'RemoveAllTracksFromQueue')
-- add playlist to queue
upnpavcmd(ip, 1400, 'AddURIToQueue', qPlaylist(2)) -- add the playlist id here
-- play
uri_queue = "x-rincon-queue:RINCON_B8E937A06A3E01400#0" -- add the right URI for the queue
upnpavcmd(ip, 1400, 'SetAVTransportURI', '<CurrentURI>'..uri_queue..'</CurrentURI><CurrentURIMetaData/>')
upnpavcmd(ip, 1400, 'Play', '<Speed>1</Speed>')
Hi npinguin,
install Developer Tools for UPnP Technology and use there Device Spy module to explore the Sonos structure and/or install sonos desktop and wireshark on your pc, control the function you need and you see the soap enveloppe inside wireshark (use filters to find it quick), the soap envellopes holds almost all information you need for upnpcmd function...
Good luck!
BR,
Erwin van der Zwart
05.03.2016, 13:01 (This post was last modified: 09.03.2016, 00:00 by Erwin van der Zwart.)
(05.03.2016, 12:48)AdriSaliai Wrote: Hello to guys. I need yours help .. I want to set Volume to Sonos for logic machine . Can you help me with scripting???
Hi AdriSaliai,
Try this script, the explanation is added into the script. Its still in development and the only thing i need to add is getting albumart URI for streaming content.
Make a resident script and set it to 3 and add grp.update('1/1/1', 0) (change '1/1/1' to your address where you have your Sonos object with TAG ) to have feedback polling
05.03.2016, 13:55 (This post was last modified: 05.03.2016, 13:55 by AdriSaliai.)
(05.03.2016, 13:01)Erwin van der Zwart Wrote:
(05.03.2016, 12:48)AdriSaliai Wrote: Hello to guys. I need yours help .. I want to set Volume to Sonos for logic machine . Can you help me with scripting???
Hi AdriSaliai,
Try this script, the explanation is added into the script. Its still in development and the only thing i need to add is getting albumart URI for streaming content.
Make a resident script and set it to 3 and add grp.update('1/1/1', 0) (change '1/1/1' to your address where you have your Sonos object with TAG ) to have feedback polling
BR,
Erwin van der Zwart
thnks you Erwin van der Zwart . If you make it all please upload
I'm not fully sure i will update this script, we have Appstore from next month, so i think next version will be a App (plug and play).
Have fun with it (:
BR,
Erwin van der Zwart
Erwin van der Zwart thnks you again for scripting it is very good helpful . I seeing the script again today and i was try to put it to the logic machine but nothing.. Ι have some questions about the structure of scripting . I must put it to the "Event Based" or "Resident" or "Common functions" i use you because i am new at Logic Machine and this is my first scripting .If you can give me some manual
06.03.2016, 19:30 (This post was last modified: 06.03.2016, 19:32 by Erwin van der Zwart.)
Hi,
Make a 1 byte unsigned integer object and a event based script.
Link the script direct to the object or by TAG. Change the player name in the script to match your player name. Optional set the feedback addresses and radio uri's and playlist names and save.
By writing values 0 to 30 to the byte object the commands specified in the script are executed.
To have feedback poll create a resident script as i mention in post above.
08.03.2016, 19:23 (This post was last modified: 08.03.2016, 19:55 by PassivPluss.)
(06.03.2016, 19:30)Erwin van der Zwart Wrote: Hi,
Make a 1 byte unsigned integer object and a event based script.
Link the script direct to the object or by TAG. Change the player name in the script to match your player name. Optional set the feedback addresses and radio uri's and playlist names and save.
By writing values 0 to 30 to the byte object the commands specified in the script are executed.
To have feedback poll create a resident script as i mention in post above.
That should be all you need to do.
Good Luck!
BR,
Erwin van der Zwart
Hi Erwin.
Perfect script.
I see that you don't want to update the script, but a couple of questions.
Everything is working, except the albumart. I get the adress in the knx telegram but not sure how to integrate this into the visulizer?
I also se that play pause feedback and title feedback dont work..
09.03.2016, 00:04 (This post was last modified: 09.03.2016, 00:35 by Erwin van der Zwart.)
Hi Ruben,
I never said i don't want to update (; but i did say i want to port it into a App for appstore making it not needed anymore to do update.
I want to make it more client side (were we can) to reduce the load on the controller and to make it plug and play. Upload to FTP, add additional server side scripts and done...
Server side will only need command from KNX, feedback and albumart can be client side if you ask me. I don't see the need to have remote acces for track feedback/albumart if you
can't hear the music, so client side should be enough for those extra's (;
I changed the original script above with version 1.1 and i changed some items. Play / Pauze and Title should work now, also added some extra artist info for streaming content.
Albumart URL should work now with local content, i'm still searching for a good solution for streaming content album art, but that's a hard one to tackle, when i solved it i let you know.
For using albumart URL in visu i need to create a html file with small piece of javascript
with a event listener on the object. The URL is set to image and when object change the image
automaticly follows. Upload the html to background image and add to frame in visu.
When i have it upload it. I think within a few days.
(09.03.2016, 00:04)Erwin van der Zwart Wrote: Hi Ruben,
I never said i don't want to update (; but i did say i want to port it into a App for appstore making it not needed anymore to do update.
I want to make it more client side (were we can) to reduce the load on the controller and to make it plug and play. Upload to FTP, add additional server side scripts and done...
Server side will only need command from KNX, feedback and albumart can be client side if you ask me. I don't see the need to have remote acces for track feedback/albumart if you
can't hear the music, so client side should be enough for those extra's (;
I changed the original script above with version 1.1 and i changed some items. Play / Pauze and Title should work now, also added some extra artist info for streaming content.
Albumart URL should work now with local content, i'm still searching for a good solution for streaming content album art, but that's a hard one to tackle, when i solved it i let you know.
For using albumart URL in visu i need to create a html file with small piece of javascript
with a event listener on the object. The URL is set to image and when object change the image
automaticly follows. Upload the html to background image and add to frame in visu.
When i have it upload it. I think within a few days.
BR,
Erwin van der Zwart
Ok. I haven't gotten into the hole mosaic/app visu as i like the possibility to customize everything.
I have used your script and some commands from the orginal sonos controller and made some great buttons in my house. I will tell u how i use the gateway for sonos in our house.
When pushing a push button on the elsner co2/temp/humidity thermostat with display. The sonos units automatically erases que, adds a pre def playlist and starts to play with preset sound. On the the display playlist name, artist, title is shown before changing to display inside co2, temp and outside temp
I use this in the living room and on the kids room. So when he goes to bed i can just push the button on his room and the sonos starts playing.
This can also be changes into a scenario where time of day can do different tasks.