Check if SONOS queue is empty - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Check if SONOS queue is empty (/showthread.php?tid=331) |
Check if SONOS queue is empty - david.rombaut@gmail.com - 24.06.2016 Hello, I'm trying to figure out a way to check if the queue on my SONOS is empty or not. I programmed pushbuttons to control play/pauze and volume up/down. Works fine except when the queue is empty. In that case pushing the programmed play button is of course not starting anything, so it would be a nice feature if I could then just start my Default streaming radio station. I thought of using the Transportstate ("STOPPED" would mean the queue is empty) but I noticed that the state also shortly goes to "STOPPED" in-between songs which makes it not 100% reliable. Any suggestions would be kindly appreciated. RE: Check if SONOS queue is empty - Erwin van der Zwart - 25.06.2016 Hi David, You can get the number of items from the Sonos by using MediaRenderer -> Queue -> Browse and then invoke with QueueID = 0, StartingIndex = 0, RequestedCount = 0 If you include this in your function upnpavcmd you should be able to get the NumberReturned value that holds the number of items inside the Queue If NumberReturned = 0 then you can start your Radio URI See attachment for screenshot from Device Spy with the fields you need Good luck! BR, Erwin RE: Check if SONOS queue is empty - Erwin van der Zwart - 26.06.2016 Hi David, I had some spare time and added it to the function: Code: -- Set Sonos IP address BR, Erwin van der Zwart RE: Check if SONOS queue is empty - david.rombaut@gmail.com - 02.07.2016 Hello Erwin, first of all many thanks for looking into my question. I tried the code you provided but something seems to be going wrong. I may be doing something wrong but I cannot seem to figure out exactly what. Attached a screenshot of the error log + your code in the background. Apparently is goes wrong at line 74. Any ideas what the cause of this might be? Many thanks, David RE: Check if SONOS queue is empty - Erwin van der Zwart - 04.07.2016 Hi David, I checked, and there was indeed a small issue, but not on line 74. Did you copied the code from chrome? If yes please copy from other browser to avoid Chrome copy issue Can you try to replace the code @ line 80: Code: queuecount = i:match([[<NumberReturned>(.-)</NumberReturned>]]) with: Code: queuecount = string.match(i, '%d+') BR, Erwin RE: Check if SONOS queue is empty - david.rombaut@gmail.com - 06.07.2016 Hello Erwin, I copied with Safari. I had experienced problems before but I had no idea that this was related to the browser. I just retyped the lines until there were no reported faults anymore. Tried it with Firefox now and that seems to work perfect. Thanks for the tip :-) With the brand new copy in Firefox and replacing the one line you suggested it works just fine now. Thanks a lot for your help. Best regards, David |