Code: Select all
active = true,
on = { ['timer'] = 'every minute' },
execute = function(domoticz)
local json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local sonos=assert(io.popen('curl http://192.168.50.3:5005/Altan/state'))
local sonos_name = 'Sonos, Altan'
local status = sonos:read('*all')
sonos:close()
local jsonStatus = json:decode(status)
playerstate = jsonStatus['playerState']
if (playerstate == 'PLAYING')
then
domoticz.devices[sonos_name].switchSelector(10)
elseif (playerstate == 'PAUSED_PLAYBACK')
then
domoticz.devices[sonos_name].switchSelector(20)
else
domoticz.devices[sonos_name].switchSelector(0)
end
end
}