SONOS - 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: SONOS (/showthread.php?tid=1309) Pages:
1
2
|
SONOS - balatis - 23.03.2018 hello . i use this script http://openrb.com/sonos-control-from-logic-machine/ for control sonos . i have some questions... 1) i must to creat an address 1 byte for control or ascii? 2) how is possibole to control 2or more sonos player ? 3) how is possibole to start play my favorite ply list from spotify ? is possibole to upload an example on the http://4n.lv:7999/apps/? thank you in advance. RE: SONOS - balatis - 26.03.2018 please can you help me....... RE: SONOS - Erwin van der Zwart - 26.03.2018 Hi, You are now using a standard UpnP script, why don't you use the Sonos App and use the build in API of the app, it supports grouping etc. Read this article for commands: https://forum.logicmachine.net/showthread.php?tid=415&pid=2244#pid2244 BR, Erwin RE: SONOS - balatis - 26.03.2018 please is very easy to help me because I am a beginner with them the ip ip from wiser is 192.168.1.50 my sonos ip is 192.168.1.7 and 192.168.1.8 thank you in advance. -- Load modules require('json') require('socket.http') -- Set timout socket.http.TIMEOUT = 5 -- Read IP address from controller data = io.readproc('if-json') data = json.decode(data) ip = data.eth0.inetaddr -- Set SONOS name Sonos_Player_Name = 'dining' -- Get event value value = event.getvalue() -- Set stepsize volume Volume_Step = 10 -- Set Action if value == 101 then Sonos_Action = 'play' elseif value == 102 then Sonos_Action = 'stop' elseif value == 103 then Sonos_Action = 'next' elseif value == 104 then Sonos_Action = 'previous' elseif value == 105 then Sonos_Action = 'mute' elseif value == 106 then Sonos_Action = 'unmute' elseif value == 107 then Sonos_Action = 'setvolumeup' Volume_Step = Volume_Step or 10 elseif value == 108 then Sonos_Action = 'setvolumedown' Volume_Step = Volume_Step or 10 else action = 'none' end -- Execute action on value 0 to 100 if value >= 0 and value <= 100 then local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=setvolume&name=' .. dining.. '&volume=' .. value .. '') end -- Execute action on value 101 to 106 if value >= 101 and value <= 106 then local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining.. '') end -- Execute action on value 107 to 108 if value >= 107 and value <= 108 then local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=' .. Sonos_Action .. '&name=' ..dining .. '&step=' .. Volume_Step .. '') end -- Execute action on value 255 (Feedback) if value == 255 then local reply = socket.http.request('http://'192.168.1.50'/apps/data/sonos/sonos.lp?action=getextendedstate&name=' ..dining.. '&createbaseimg=true') reply = json.pdecode(reply) if reply then local current_volume = reply[1].volume local current_mutestate = reply[2].mute local current_crossfadestate = reply[3].crossfade local current_playmode = reply[4].playmode local current_transportmode = reply[5].transport local current_duration = reply[7].duration local current_playingtime = reply[8].playingtime local current_title = reply[9].tracktitle local current_artist = reply[10].creator local current_album = reply[11].album local current_albumart = reply[12].albumart local current_mediatype = reply[11].mediatype end end RE: SONOS - Erwin van der Zwart - 26.03.2018 Hi, You added the name dining as a variable in the URL so that will never work.. Try this first so you have a working sample, from there you can expand the script: Code: -- Load modules Code: -- Load modules PS: Be sure to have opened the Sonos app at least once so the players are scanned and listed in the controller with name and IP before using this script BR, Erwin RE: SONOS - balatis - 27.03.2018 first of all to thank you for the answer i did the follow but do not work -- Load modules require('socket.http') -- Set timout socket.http.TIMEOUT = 5 -- Set SONOS IP Sonos_Player_IP = '192.168.1.7' -- Get event value value = event.getvalue() -- Set stepsize volume Volume_Step = 10 -- Set Action if value == 101 then Sonos_Action = 'play' elseif value == 102 then Sonos_Action = 'stop' elseif value == 103 then Sonos_Action = 'next' elseif value == 104 then Sonos_Action = 'previous' elseif value == 105 then Sonos_Action = 'mute' elseif value == 106 then Sonos_Action = 'unmute' elseif value == 107 then Sonos_Action = 'setvolumeup' Volume_Step = Volume_Step or 10 elseif value == 108 then Sonos_Action = 'setvolumedown' Volume_Step = Volume_Step or 10 else action = 'none' end -- Get value for volume value = event.getvalue() -- 0 to 100 so set object to scale reply = socket.http.request('http://192.168.1.50/apps/data/sonos/sonos.lp?action=setvolume&ip= http://192.168.1.7 &volume= 10 ')-- Execute action on value 255 (Feedback) -- Execute action on value 101 to 106 if value >= 101 and value <= 106 then local reply = socket.http.request('http://192.168.1.50/apps/data/sonos/sonos.lp?action=play&ip= http://192.168.1.7 ') end -- Execute action on value 107 to 108 if value >= 107 and value <= 108 then local reply = socket.http.request('http://192.168.1.50/apps/data/sonos/sonos.lp?action=stop&ip= http://192.168.1.7 ') end if value == 255 then local reply = socket.http.request('http://192.168.1.50/apps/data/sonos/sonos.lp?action=getextendedstate&ip= http://192.168.1.7 &createbaseimg=true') reply = json.pdecode(reply) if reply then local current_volume = reply[1].volume local current_mutestate = reply[2].mute local current_crossfadestate = reply[3].crossfade local current_playmode = reply[4].playmode local current_transportmode = reply[5].transport local current_duration = reply[7].duration local current_playingtime = reply[8].playingtime local current_title = reply[9].tracktitle local current_artist = reply[10].creator local current_album = reply[11].album local current_albumart = reply[12].albumart local current_mediatype = reply[11].mediatype end end RE: SONOS - admin - 27.03.2018 It probably does not work because you have password enabled for apps. Create user with login sonos and password sonos123 Then create an event script mapped to 1-byte scale object: Code: Sonos_Player_IP = '192.168.1.7' If this still does not work, add this at the end of the script and post what you get in Logs tab: Code: log(reply) RE: SONOS - Erwin van der Zwart - 27.03.2018 Hi, It also does not work because there are multiple spaces in the URL (not allowed) and you have added http:// before the IP address, Sonos is not controlled over HTTP. Please keep the URL as it is and only change IP address of the controller to the correct IP or 127.0.0.1 as admin's sample.. BR, Erwin RE: SONOS - balatis - 27.03.2018 hi were i must to creat user? in my application on my phone ? Event for sonos (1/1/1) 27.03.2018 15:03:47 * string: Access Denied RE: SONOS - admin - 27.03.2018 In User Access tab RE: SONOS - balatis - 27.03.2018 (27.03.2018, 12:14)admin Wrote: In User Access tab ok now i have that Event for sonos (1/1/1) 27.03.2018 15:16:55 * string: true RE: SONOS - admin - 27.03.2018 This means that the request is working correctly. Does the volume change on your Sonos device? RE: SONOS - balatis - 27.03.2018 (27.03.2018, 12:21)διαχειριστής Wrote: This means that the request is working correctly. Does the volume change on your Sonos device? unfortunately no i use the follow -- Load modules require('socket.http') -- Set timout socket.http.TIMEOUT = 5 -- Set SONOS IP Sonos_Player_IP = '192.168.1.7' reply = socket.http.request('http://admin:sonos123@192.168.1.50/apps/data/sonos/sonos.lp?action=setvolume&ip=192.168.1.7&volume=' ..value) log(reply) RE: SONOS - admin - 27.03.2018 Please use the example that I've provided. You keep changing the code randomly and of course it's not working. In your case value variable is not defined. RE: SONOS - balatis - 27.03.2018 (27.03.2018, 12:37)admin Wrote: Please use the example that I've provided. You keep changing the code randomly and of course it's not working. In your case value variable is not defined. I'm sorry I'm a beginner with lua. it change volume now. how is posible to cotrolthe next commands from sonos? thanks RE: SONOS - admin - 27.03.2018 Map this event script to 1-bit object. True/on = play, false/off = stop Code: Sonos_Player_IP = '192.168.1.7' RE: SONOS - Daniel - 27.03.2018 Hi Did you know that basic sonos control you can do without any script? Open app, pres + next to your player and add it. It will create objects in LM to control sonos. Just search your objects. BR RE: SONOS - balatis - 27.03.2018 thank you very much for your help (invaluable) I understood it RE: SONOS - Erwin van der Zwart - 27.03.2018 Hi Daniel, Now i know why you added that (: BR, Erwin RE: SONOS - thomasoppida - 15.04.2018 (27.03.2018, 13:06)Daniel. Wrote: Hi Hi, Is it possible somewhere to change the groupadresses this function creates? Seems like it start with the first available addresses... BR thomas |