My loop while work but in this I have a if condition with a commandArray and the command is running only one not for every true condition.
I put a print to Debug and I can see multiple true but only the last run the commandArray.
Help
Code: Select all
commandArray = {}
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
-- Tableau Hue/Domotiz Exemple Idlamp Hue1 = idz108
lamp = {1,2,3,4,5,6,7,8} --Put your Hue lamp ID here
device = {108,109,110,111,112,113,114,115} --Put your Domotiz ID here
nblamp = 8 --Put here nbr lamp you want check
i = 1
while i <= nblamp
do
huelightid=lamp[i]
domohueid=device[i]
idjson = tostring(huelightid)
urlid = tostring(domohueid)
-- API call
local config=assert(io.popen('curl "http://IPHue/api/UserHue/lights/'..idjson..'"')) -- change Iphue and login hue
local Stringjson = config:read('*all')
config:close()
local jsonData = json:decode(Stringjson)
lampe = jsonData.name
reachable = jsonData.state.reachable
-- print (Stringjson) -- debug json
reachable = tostring(reachable)
-- print('Hue Reachable Log: '..reachable..lampe) -- Test value for Debuging.
if reachable == "false"
then
commandArray['OpenURL']='http://domoticzip:port/json.htm?type=command¶m=switchlight&idx='..urlid..'&switchcmd=Off' -- Changedomoticzip and port
print ('url : '..urlid) -- Log Debug Help
end
i = i + 1
end
return commandArray