commandArray = {} --Fonction trouvée sur http://easydomoticz.com/forum/viewtopic.php?f=10&t=7147 function getDevNameByIdx(devIdx) for i, v in pairs(otherdevices_idx) do if v == devIdx then return i end end return 0 end function logMessage (TheMessage) year = tonumber(os.date("%Y")); month = tonumber(os.date("%m")); day = tonumber(os.date("%d")); hour = tonumber(os.date("%H")); minutes = tonumber(os.date("%M")); seconds = tonumber(os.date("%S")); if (string.len(month) == 1) then month = "0" .. month end if (string.len(day) == 1) then day = "0" .. day end if (string.len(hour) == 1) then hour = "0" .. hour end if (string.len(minutes) == 1) then minutes = "0" .. minutes end if (string.len(seconds) == 1) then seconds = "0" .. seconds end --logtime = year .. " " .. month .. " " .. day .. " " .. hour .. " " .. minutes .. " " .. seconds logtime = year .. month .. day .. " " .. hour .. minutes .. seconds file = io.open("mylog.txt", "a") file:write(logtime .. " " .. TheMessage.."\n") file:close() end local varostime = 0 local varprochainarret = 0 varInterrupteur2boutons = getDevNameByIdx(199) varLumiereGarage = getDevNameByIdx(219) varostime = os.time() varprochainarret = (uservariables["varzigbeeOnOffLightGarage"]) if (devicechanged[varInterrupteur2boutons] == 'B2') then logMessage("Garage : Appui sur Interrupteur B2") local b = otherdevices[varLumiereGarage] local f = otherdevices[varInterrupteur2boutons] logMessage("Garage : Etat light : " .. b .. " Interrupteur : " .. f) if (otherdevices[varLumiereGarage] == "On") then varprochainarret = varostime -1 commandArray['Variable:varzigbeeOnOffLightGarage']= tostring(varprochainarret) commandArray[varLumiereGarage]='Off' logMessage("Garage : extinction de la lumière") else varprochainarret = varostime + (60*60*4) --On allume pour 4 heures logMessage("Garage : varprochainarret après ajout " .. varprochainarret) commandArray['Variable:varzigbeeOnOffLightGarage']= tostring(varprochainarret) commandArray[varLumiereGarage]='On' logMessage("Garage : allumage de la lumière") end end return commandArray