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
#1
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.
Reply
#2
please can you help me.......
Reply
#3
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/showthrea...44#pid2244

BR,

Erwin
Reply
#4
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
Reply
#5
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
require('socket.http')

-- Set timout
socket.http.TIMEOUT = 5

-- Set SONOS name
Sonos_Player_Name = 'dining'  -- Is this written exactly as you see in the Sonos App without capital etc?

-- 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&name=' .. Sonos_Player_Name .. '&volume=' .. value .. '')
or by IP (i prever name as IP is DHCP and can change, name will never change automaticly)
Code:
-- Load modules
require('socket.http')

-- Set timout
socket.http.TIMEOUT = 5

-- Set SONOS IP
Sonos_Player_IP = '192.168.1.7'

-- 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=' .. Sonos_Player_IP .. '&volume=' .. value .. '')

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
Reply
#6
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
Reply
#7
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'
value = event.getvalue() -- 0 to 100 so set object to scale

http = require('socket.http')
http.TIMEOUT = 5
reply = http.request('http://sonos:sonos123@127.0.0.1/apps/data/sonos/sonos.lp?action=setvolume&ip=' .. Sonos_Player_IP .. '&volume=' .. value)

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)
Reply
#8
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
Reply
#9
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
Reply
#10
In User Access tab
Reply
#11
(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
Reply
#12
This means that the request is working correctly. Does the volume change on your Sonos device?
Reply
#13
(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)
Reply
#14
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.
Reply
#15
(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
Reply
#16
Map this event script to 1-bit object. True/on = play, false/off = stop

Code:
Sonos_Player_IP = '192.168.1.7'
value = event.getvalue()

if value then
  action = 'play'
else
  action = 'stop'
end

http = require('socket.http')
http.TIMEOUT = 5
reply = http.request('http://sonos:sonos123@127.0.0.1/apps/data/sonos/sonos.lp?action=' .. action .. '&ip=' .. Sonos_Player_IP)
Reply
#17
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
------------------------------
Ctrl+F5
Reply
#18
thank you very much for your help (invaluable) I understood it
Reply
#19
Hi Daniel,

Now i know why you added that (: 

BR,

Erwin
Reply
#20
(27.03.2018, 13:06)Daniel. Wrote: 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

Hi,

Is it possible somewhere to change the groupadresses this function creates? Seems like it start with the first available addresses...

BR
thomas
Reply


Forum Jump: