Code: Select all
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local sonos=assert(io.popen('curl http://ip:5005/eetkamer/state'))
local status = sonos:read('*all')
sonos:close()
local jsonStatus = json:decode(status)
local tv_woonkamer_status = 'TV Woonkamer System Alive'
local sonos_woonkamer = 'Sonos Woonkamer/Eetkamer'
--print("Eerste JSON stappen met LUA")
--print(status)
print(jsonStatus)
playbackState = jsonStatus['playbackState']
artist = jsonStatus['currentTrack']['artist']
title = jsonStatus['currentTrack']['title']
album = jsonStatus['currentTrack']['album']
type = jsonStatus['currentTrack']['type']
--streaminfo = jsonStatus['currentTrack']['streamInfo']
commandArray = {}
if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK" or playbackState == "PLAYING") then
if (playbackState == "PLAYING") then
if type == "radio" then
print('Woonkamer/Eetkamer Sonos status: ' ..playbackState.. ' ' ..type.. ' Titel: '..title)
else
if artist ~= nil then
print('Badkamer Sonos status: ' ..playbackState.. ' Artiest: ' ..artist.. ' Titel: '..title)
else
print('Badkamer Sonos status: ' ..playbackState.. ' Titel: '..title)
end
end
if (uservariables["SonosWoonkamerStatus"] == "PAUSED") then
commandArray['Variable:SonosWoonkamerStatus']='PLAYING'
print("Uservar SonosWoonkamer updated to PLAYING")
end
end
if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK") then
print('Woonkamer/Eetkamer Sonos Status: ' ..playbackState)
if (uservariables["SonosWoonkamerStatus"] == "PLAYING") then
commandArray['Variable:SonosWoonkamerStatus']='PAUSED'
print("Uservar SonosWoonkamer updated to PAUSED")
end
end
else
--print("2")
print('<font color="red">Woonkamer/Eetkamer: SONOS-HTTP-API is off-line</font>')
end
if (playbackState == "STOPPED" or playbackState == "PAUSED_PLAYBACK") then
switch_status_sonos_woonkamer_eetkamer = otherdevices["Sonos Woonkamer/Eetkamer"]
print('Sonos Woonkamer/Eetkamer Switch Status: ' ..switch_status_sonos_woonkamer_eetkamer)
if otherdevices["Sonos Woonkamer/Eetkamer"] == 'Pauze' then
print('Sonos Woonkamer/Eetkamer Switch Status is correct, should be PAUZE: ' ..switch_status_sonos_woonkamer_eetkamer)
else
print('Sonos Woonkamer/Eetkamer Switch Status not correct, should be PAUZE: ' ..switch_status_sonos_woonkamer_eetkamer)
commandArray['UpdateDevice'] = '43|20|20'
end
end
if (playbackState == "PLAYING") then
switch_status_sonos_woonkamer_eetkamer = otherdevices["Sonos Woonkamer/Eetkamer"]
print('Sonos Woonkamer/Eetkamer Switch Status: ' ..switch_status_sonos_woonkamer_eetkamer)
if otherdevices["Sonos Woonkamer/Eetkamer"] == 'Play' then
print('Sonos Woonkamer/Eetkamer Switch Status is correct, should be PLAY: ' ..switch_status_sonos_woonkamer_eetkamer)
else
print('Sonos Woonkamer/Eetkamer Switch Status not correct, should be PLAY: ' ..switch_status_sonos_woonkamer_eetkamer)
commandArray['UpdateDevice'] = '43|10|10'
end
end
if devicechanged[tv_woonkamer_status] == 'On' then
print("TV Woonkamer is net aangezet, status Sonos Woonkamer onderzoeken")
if (playerstate == "PLAYING" or playbackState == "PLAYING") then
print("Sonos woonkamer heeft status PLAYING, Sonos Woonkamer/Eetkamer wordt uitgeschakeld")
commandArray[sonos_woonkamer]='Set Level 20'
end
end
return commandArray