CANCEL THIS - I SOLVED IT WITH A VD USING THE MAIN LOOP
Hi,
This is prob not a huge mystery and something basic I'm missing.
If I remove the While true do loop from the code below and execute it manually it works okay but once I add the while loop to get it check all the time the scene doesn't run
Could somebody take a look and tell me where I'm being stupid
Thanks
-F
--[[
%% autostart
%% properties
%% events
%% globals
--]]
-- Configuration - Scene Info
sceneName = "Sonos State tracker"
sceneVersion = "1.0.1"
-- Scene Description
-- Track and stores the state of three of the sonos
-- zones so the respective amp can be switched on
-- Configuration - Device IDs
-- none for this scene
-- Validate Number of Scene Instance
if (fibaro:countScenes()>1) then
--fibaro:debug("stop scene")
fibaro:abort()
end
-- read playroom state
function StateFunc()
while true do
fibaro:sleep(2000) -- execute this every 2 seconds
if fibaro:getGlobal("G_SPC_AREA_STATUS_1") == "UNSET" then -- don't check if we are not at home
http = net.HTTPClient({ timeout = 3000 })
url = 'http://192.168.1.89:5005/Playroom/state'
controlHeaders = {['content-type'] = 'application/json; charset=utf-8'}
http:request(url, {
options = {
headers = controlHeaders,
method = 'GET',
},
success = function(response)
if response.status == 200 then
local responds = json.decode(response.data)
local zPRState = responds.zoneState
fibaro:debug(zPRState)
fibaro:setGlobal("Sonos_PRState", zPRState);
end
end,
})
-- read living room state
http = net.HTTPClient({ timeout = 3000 })
url = 'http://192.168.1.89:5005/Living_Room/state'
controlHeaders = {['content-type'] = 'application/json; charset=utf-8'}
http:request(url, {
options = {
headers = controlHeaders,
method = 'GET',
},
success = function(response)
if response.status == 200 then
local responds = json.decode(response.data)
local zLRState = responds.zoneState
fibaro:debug(zLRState)
fibaro:setGlobal("Sonos_LRState", zLRState);
end
end,
})
-- read dining room state
http = net.HTTPClient({ timeout = 3000 })
url = 'http://192.168.1.89:5005/Dining_Room/state'
controlHeaders = {['content-type'] = 'application/json; charset=utf-8'}
http:request(url, {
options = {
headers = controlHeaders,
method = 'GET',
},
success = function(response)
if response.status == 200 then
local responds = json.decode(response.data)
local zDRState = responds.zoneState
fibaro:debug(zDRState)
fibaro:setGlobal("Sonos_DRState", zDRState);
end
end,
})
end -- end if statement
end -- end while loop
end -- end function
-- Main Scene execution code
StateFunc()