I am using a LUA script to turn the lights on and off when some parameters have a certain value. This was working fine untill I wanted to add another switch to the script. When I add this only the second command is working.
This is the script:
Code: Select all
function updatedomoticz(idx,switchcmd)
commandArray['OpenURL'] = 'http://10.27.0.20/json.htm?type=command¶m=switchlight&idx='..idx..'&switchcmd='..switchcmd;
end
function setvariabele(key,value)
commandArray['Variable:'..key]=tostring(value)
end
commandArray = {}
-- Variabelen ophalen
LUX = tonumber(otherdevices['Zonnestraling'])
LUXaan = tonumber(25)
LUXuit = tonumber(25)
verlichtingwoonkamer = otherdevices['Lamp Plafond Woonkamer']
verlichtingwoonkamerstat = uservariables["verlichting_wk"]
aanwezig = otherdevices['Iemand thuis']
afspraak = uservariables["afspraak"]
afspraak_status = uservariables["afspraak_status"]
if (LUX <= LUXaan and verlichtingwoonkamerstat == 0 and aanwezig == 'On') or
(afspraak == 1 and LUX <= LUXaan and afspraak_status == 0 and aanwezig == 'On') then
updatedomoticz(68,"On")
setvariabele("verlichting_wk",1)
if (afspraak == 1) then
setvariabele("afspraak_status",1)
end
print ("Verlichting Woonkamer aan")
elseif (LUX > LUXuit and verlichtingwoonkamerstat == 1) or
(aanwezig == 'Off' and verlichtingwoonkamerstat == 1) then
updatedomoticz(68,"Off")
setvariabele("verlichting_wk",0)
print ("Verlichting Woonkamer uit")
end
I solved it with a new script that switches IDX 69 on when IDX 68 is set to on and that works. But it would be nicer to put it in one script. Also , I'd like to understand why it isn't working as I thought it would.
Thanks in advance!