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 play/queue playlist
#1
I know there's an example to control a Sonos with the LM/HL: http://openrb.com/sonos-control-from-logic-machine/


But i can't find an example how to play a playlist or how to add a playlist to the queue. Anyone?
Reply
#2
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.
Reply
#3
(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

Maybe someone has done this before?
Reply
#4
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
Reply
#5
(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>')

Attached Files
.lua   upnpavcmd.lua (Size: 1.93 KB / Downloads: 72)
Reply
#6
Good job! Thanks for sharing Smile
Reply
#7
To get more information about the upnp commands i used:
Developer Tools for UPnP Technologies v0.0.69 (http://opentools.homeip.net/dev-tools-for-upnp)

How to use it, read:
http://blog.travelmarx.com/2010/06/explo...-upnp.html
Reply
#8
Hi geert

I am looking for an extended solution for the sonos interfacing.

I extended the scripts with dimming the volume, this now works

Next step would be to rotate through the list of favorites up/down

But i am strugling / would like to
- get the list of favorites
- get the current selected favorite
- select the next one

Any idea which commands i need to use to get this done, because it is very poorly documented?

Thanks
Nicky
Reply
#9
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
Reply
#10
Thanks
Will try this
Reply
#11
Hello to guys. I need yours help .. I want to set Volume to Sonos for logic machine . Can you help me with scripting???
Reply
#12
(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

Attached Files
Reply
#13
(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  Smile
Reply
#14
Hi,

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
Reply
#15
(05.03.2016, 14:09)Erwin van der Zwart Wrote: Hi,

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  Tongue Smile Wink
Reply
#16
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
Reply
#17
(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..

Ruben
Reply
#18
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
Reply
#19
(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 tempSmile 

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.

Ruben
Reply
#20
Hi Ruben,

Sounds good, I would make que random to avoid listen to same music over and over (:

What commands from the original sonos script are missing in my version? I can add them..

BR,

Erwin
Reply


Forum Jump: