From 9801d21a1eccce62629f0e23ad08f359d9fd3ddd Mon Sep 17 00:00:00 2001 From: Thibaut PEROTIN Date: Mon, 6 Jun 2016 10:29:07 +0200 Subject: [PATCH] fix bug when we call fibaro:wakeUpDeadDevice --- GEA.lua | 468 ++++++++++++++++++++++++++-------------------------- GEA.min.lua | 10 +- 2 files changed, 239 insertions(+), 239 deletions(-) diff --git a/GEA.lua b/GEA.lua index 44a8ba6..63b8a2d 100644 --- a/GEA.lua +++ b/GEA.lua @@ -9,7 +9,7 @@ -- ================================================== -- GEA : Gestionnaire d'Evénements Automatique -- ================================================== --- [FR] Scénario permettant de contrôler si un périphérique est +-- [FR] Scénario permettant de contrôler si un périphérique est -- activé depuis trop longtemps ou lancer un push d'avertissement. -- Ce scénario permet une annotation plus simple que le code LUA -- il nécessite néanmoins quelques connaissances. @@ -34,7 +34,7 @@ -- Paramétrage de GEA / GEA configuration function config() - GEA.isVersionFour = true -- On est en version 4.017 Beta ou supérieure / + GEA.isVersionFour = true -- On est en version 4.017 Beta ou supérieure / GEA.language = "FR" -- Votre langue : FR (default) / Your language : EN GEA.checkEvery = 30 -- On vérifie toutes les X secondes (default : 30) / Check every X seconds GEA.portables = {179} -- Liste des portables devant recevoir une notification {70, 71} / Smartphones you want to be notified @@ -44,13 +44,13 @@ function config() GEA.optimize = GEA.typeOptimize["IMMEDIATE_ONLY"] -- option : GEA.typeOptimize["NONE"], GEA.typeOptimize["IMMEDIATE_ONLY"], GEA.typeOptimize["ALL"] -- permet d'optimiser les soucis liés au getName et getRoom de fibaro mais n'affiche plus le nom des modules concernés. -end +end -- Ajouter ici les événements à exécuter / Add here events to schedule -- Une liste d'exemples est disponible dans un fichier annexe samples.lua / A samples list is available in another file called samples.lua -function setEvents() +function setEvents() @@ -90,7 +90,7 @@ if (not GEA) then GEA.optimize = GEA.typeOptimize["NONE"] GEA.getGlobalForActivation = {} GEA.source = fibaro:getSourceTrigger() - + GEA.translate = {true, true} GEA.translate["FR"] = { ACTIONS = "traitement des actions", @@ -193,7 +193,7 @@ if (not GEA) then VALUE = "value", WILL_SUSPEND = "will suspend " } - + -- --------------------------------------------------------------------------- -- Ajoute un périphérique dans la liste des éléments à traiter -- --------------------------------------------------------------------------- @@ -206,17 +206,17 @@ if (not GEA) then local name = {} local room = {} - if (arg and #arg > 0) then - for i = 1, #arg do + if (arg and #arg > 0) then + for i = 1, #arg do lowCapsArg = string.lower(arg[i][1]) - if (lowCapsArg == "repeat") then + if (lowCapsArg == "repeat") then repeating = true - elseif (lowCapsArg == "maxtime") then + elseif (lowCapsArg == "maxtime") then maxtime = tonumber(arg[i][2]) - elseif (lowCapsArg == "group") then + elseif (lowCapsArg == "group") then groups[tonumber(arg[i][2])] = true - elseif (lowCapsArg == "notstarted") then - notStarted = true + elseif (lowCapsArg == "notstarted") then + notStarted = true end end @@ -224,13 +224,13 @@ if (not GEA) then end if (maxtime > -1) then repeating = true end - + GEA.index = GEA.index + 1 - + if (type(id) == "table") then if (type(id[1]) == "number" or type(id[1]) == "table") then local conditions = {} - for i = 2, #id do + for i = 2, #id do table.insert(conditions, id[i]) name[i], room[i] = GEA.getName(id[i]) end @@ -252,23 +252,23 @@ if (not GEA) then end end end - + name[1], room[1] = GEA.getName(id) - + local entry = {id, secondes, message, repeating, params, name, 0, false, {}, groups, false, 0, GEA.index, maxtime, room} if (GEA.source["type"] == "autostart" and tonumber(entry[GEA.keys["SECONDES"]]) >= 0) then GEA.insert(entry) GEA.log("Add Autostart", entry, GEA.translate[GEA.language]["ADDED_FOR"] .. " " .. secondes .. " " .. GEA.translate[GEA.language]["SECONDS"], true, "grey") - if (notStarted) then + if (notStarted) then local cIndex = GEA.getCode("S", entry[GEA.keys["INDEX"]]) if (GEA.suspended ~= nil) then GEA.suspended = string.gsub(GEA.suspended, cIndex, "") end - GEA.suspended = GEA.suspended .. cIndex + GEA.suspended = GEA.suspended .. cIndex end elseif (GEA.source["type"] == "global" and tonumber(entry[GEA.keys["SECONDES"]]) < 0) then if (type(entry[GEA.keys["ID"]]) == "table" and GEA.match(string.lower(entry[GEA.keys["ID"]][1]), "global|global.") and entry[GEA.keys["ID"]][2] == GEA.source["name"]) then @@ -298,19 +298,19 @@ if (not GEA) then return entry[GEA.keys["INDEX"]] end - + -- --------------------------------------------------------------------------- -- Ajoute une opération dans la liste -- --------------------------------------------------------------------------- - GEA.insert = function(entry) + GEA.insert = function(entry) GEA.todo[GEA.pos] = entry; -- table.insert(GEA.todo, entry) - -- entry[GEA.keys["INDEX"]] = #GEA.todo + -- entry[GEA.keys["INDEX"]] = #GEA.todo GEA.pos = GEA.pos + 1 return entry[GEA.keys["INDEX"]] end - + -- --------------------------------------------------------------------------- -- Ajoute ou supprime un code dans la variable global GEA_Tasks -- --------------------------------------------------------------------------- @@ -318,7 +318,7 @@ if (not GEA) then local glob = nil local cIndex = GEA.getCode(code, index) - if (GEA.useTasksGlobal) then + if (GEA.useTasksGlobal) then glob = fibaro:getGlobalValue(GEA.globalTasks) else glob = GEA.tasks @@ -329,33 +329,33 @@ if (not GEA) then end if (add) then - if (GEA.useTasksGlobal) then + if (GEA.useTasksGlobal) then fibaro:setGlobal(GEA.globalTasks, glob .. cIndex) else GEA.tasks = glob .. cIndex end else - if (GEA.useTasksGlobal) then + if (GEA.useTasksGlobal) then fibaro:setGlobal(GEA.globalTasks, glob) else GEA.tasks = glob end end end - + -- --------------------------------------------------------------------------- -- Vérifie l'existence d'un code dans la variable global GEA_Tasks - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.isTask = function(code, index) local glob = nil local cIndex = GEA.getCode(code, index) - if (GEA.useTasksGlobal) then + if (GEA.useTasksGlobal) then glob = fibaro:getGlobalValue(GEA.globalTasks) else glob = GEA.tasks end - + if (glob ~= nil) then return string.match(glob, cIndex) end @@ -369,7 +369,7 @@ if (not GEA) then GEA.getCode = function(code, index) return "|" .. code .. "_" .. index .. "|" end - + -- --------------------------------------------------------------------------- -- Obtention d'un nom pour le système -- --------------------------------------------------------------------------- @@ -396,7 +396,7 @@ if (not GEA) then if (lowerCaps == "batteries") then return "Batteries <= " .. id[1], "" elseif (lowerCaps == "sceneactivation") then - return "Scene [" .. id[2] .. "|" .. fibaro:getName(idNumeric) .. "] = " .. id[3], GEA.getRoom(idNumeric) + return "Scene [" .. id[2] .. "|" .. fibaro:getName(idNumeric) .. "] = " .. id[3], GEA.getRoom(idNumeric) elseif (lowerCaps == "sensor") then return "Sensor [" .. id[2] .. "|" .. fibaro:getName(idNumeric) .. "] = " .. id[3], GEA.getRoom(idNumeric) elseif (lowerCaps == "sensor+") then @@ -441,12 +441,12 @@ if (not GEA) then return "Property [" .. id[2] .. "|".. id[3] .. "] ~= " .. id[4], GEA.getRoom(idNumeric) elseif (lowerCaps == "group") then return "Group [" .. id[2] .. "]", "" - else + else -- autres à venir end end end - + -- --------------------------------------------------------------------------- -- Retourne la pièce contenant le module -- --------------------------------------------------------------------------- @@ -481,13 +481,13 @@ if (not GEA) then return dayFound end - + -- --------------------------------------------------------------------------- -- Vérification des plages de date -- --------------------------------------------------------------------------- GEA.checkTimes = function(entry) GEA.log("Check", entry, GEA.translate[GEA.language]["CHECKING_DATE"], false) - + if (not entry[GEA.keys["PARAMS"]]) then return true end @@ -515,15 +515,15 @@ if (not GEA) then -- todo check local from = iterator[2] - if (string.len(from) == 5) then - from = from .. "/" .. os.date("%Y") + if (string.len(from) == 5) then + from = from .. "/" .. os.date("%Y") end from = string.format ("%04d", GEA.split(from, "/")[3]) .. string.format("%02d", GEA.split(from, "/")[2]) .. string.format("%02d", GEA.split(from, "/")[1]) local to = iterator[3] - if (string.len(to) == 5) then - to = to .. "/" .. os.date("%Y") + if (string.len(to) == 5) then + to = to .. "/" .. os.date("%Y") end to = string.format ("%04d", GEA.split(to, "/")[3]) .. string.format("%02d", GEA.split(to, "/")[2]) .. string.format("%02d", GEA.split(to, "/")[1]) @@ -540,23 +540,23 @@ if (not GEA) then local iterator = entry[GEA.keys["PARAMS"]][i] if (type(iterator) == "table" and string.lower(iterator[1]) == "dates") then - if (not found) then - dateFound = false + if (not found) then + dateFound = false end local now = os.date("%Y%m%d") -- todo check local from = iterator[2] - if (string.len(from) == 5) then - from = from .. "/" .. os.date("%Y") + if (string.len(from) == 5) then + from = from .. "/" .. os.date("%Y") end from = string.format("%04d", GEA.split(from, "/")[3]) .. string.format("%02d", GEA.split(from, "/")[2]) .. string.format("%02d", GEA.split(from, "/")[1]) local to = iterator[3] - if (string.len(to) == 5) then - to = to .. "/".. os.date("%Y") + if (string.len(to) == 5) then + to = to .. "/".. os.date("%Y") end to = string.format("%04d", GEA.split(to, "/")[3]) .. string.format("%02d", GEA.split(to, "/")[2]) .. string.format("%02d", GEA.split(to, "/")[1]) @@ -577,7 +577,7 @@ if (not GEA) then for i = 1, #entry[GEA.keys["PARAMS"]] do local iterator = entry[GEA.keys["PARAMS"]][i] - if (type(iterator) == "table" and string.lower(iterator[1]) == "time") then + if (type(iterator) == "table" and string.lower(iterator[1]) == "time") then notFound = false if (GEA.checkTime(entry, GEA.flatTime(iterator[2]) .. "-" .. GEA.flatTime(iterator[3]))) then @@ -601,7 +601,7 @@ if (not GEA) then return notFound and dateFound and dayFound and dst end - + -- --------------------------------------------------------------------------- -- Contrôle des heures -- --------------------------------------------------------------------------- @@ -612,7 +612,7 @@ if (not GEA) then t = string.gsub(t, "h", ":") t = string.gsub(t, "sunset", fibaro:getValue(1, "sunsetHour")) t = string.gsub(t, "sunrise", fibaro:getValue(1, "sunriseHour")) - + if (string.find(t, "<")) then t = GEA.flatTime(GEA.split(t, "<")[1]) .. "<" .. GEA.flatTime(GEA.split(t, "<")[2]) end @@ -649,10 +649,10 @@ if (not GEA) then s1 = string.format("%02d", GEA.split(s1, ":")[1]) .. ":" .. string.format("%02d", GEA.split(s1, ":")[2]) s2 = string.format("%02d", GEA.split(s2, ":")[1]) .. ":" .. string.format("%02d", GEA.split(s2, ":")[2]) - if (s1 < s2) then - t = s1 - else - t = s2 + if (s1 < s2) then + t = s1 + else + t = s2 end elseif (string.find(t, ">")) then @@ -662,19 +662,19 @@ if (not GEA) then s1 = string.format("%02d", GEA.split(s1, ":")[1]) .. ":" .. string.format("%02d", GEA.split(s1, ":")[2]) s2 = string.format("%02d", GEA.split(s2, ":")[1]) .. ":" .. string.format("%02d",GEA. split(s2, ":")[2]) - if (s1 > s2) then - t = s1 - else - t = s2 + if (s1 > s2) then + t = s1 + else + t = s2 end else t = string.format("%02d", GEA.split(t, ":")[1]) .. ":" .. string.format("%02d", GEA.split(t, ":")[2]) end - + return t end - + -- --------------------------------------------------------------------------- -- Vérification d'une plage de date -- --------------------------------------------------------------------------- @@ -684,7 +684,7 @@ if (not GEA) then if (not times or times == "") then return true end - + local from = string.sub(times, 1, 5) local to = string.sub(times, 7, 11) local now = os.date("%H:%M") @@ -704,7 +704,7 @@ if (not GEA) then return inplage end - + -- --------------------------------------------------------------------------- -- Split une chaîne selon un délimiteur -- --------------------------------------------------------------------------- @@ -716,17 +716,17 @@ if (not GEA) then return fields end - + -- --------------------------------------------------------------------------- -- Supprime les espaces avant et après -- --------------------------------------------------------------------------- GEA.trim = function(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end - + -- --------------------------------------------------------------------------- -- Utilisation des regex - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.match = function(s, p) if (type(s) == "nil") then return type(p) == "nil" @@ -742,14 +742,14 @@ if (not GEA) then words[i] = "^"..words[i].."$" end - if (string.match(s, GEA.trim(words[i]))) then - return true + if (string.match(s, GEA.trim(words[i]))) then + return true end - end + end return false end - + -- --------------------------------------------------------------------------- -- On vérifie pour un pérphérique -- --------------------------------------------------------------------------- @@ -765,31 +765,31 @@ if (not GEA) then GEA.addOrRemoveTask("R", entry[GEA.keys["INDEX"]], false) GEA.addOrRemoveTask("S", entry[GEA.keys["INDEX"]], false) end - + if (GEA.isTask("S", entry[GEA.keys["INDEX"]]) ~= nil) then GEA.log("Check", entry, GEA.translate[GEA.language]["SUPSENDED"], true) return end - if (not entry[GEA.keys["DONE"]]) then - entry[GEA.keys["OK"]] = false + if (not entry[GEA.keys["DONE"]]) then + entry[GEA.keys["OK"]] = false end - + if (GEA.checkTimes(entry)) then if (GEA.isActivated(entry, 1, entry)) then -- le périphérique est actif, on incrémente le compteur if (entry[GEA.keys["SECONDES"]] < 0) then - local maxglob = GEA.isTask("M", entry[GEA.keys["INDEX"]] .. "{(%d+)}") + local maxglob = GEA.isTask("M", entry[GEA.keys["INDEX"]] .. "{(%d+)}") if (maxglob ~= nil) then entry[GEA.keys["TOTALRUNS"]] = tonumber(maxglob) GEA.addOrRemoveTask("M", entry[GEA.keys["INDEX"]] .. "{(%d+)}", false) end end - + if (entry[GEA.keys["NBRUN"]]) then entry[GEA.keys["NBRUN"]] = entry[GEA.keys["NBRUN"]] + 1 - entry[GEA.keys["TOTALRUNS"]] = entry[GEA.keys["TOTALRUNS"]] + 1 + entry[GEA.keys["TOTALRUNS"]] = entry[GEA.keys["TOTALRUNS"]] + 1 else entry[GEA.keys["NBRUN"]] = 0 entry[GEA.keys["TOTALRUNS"]] = 0 @@ -798,18 +798,18 @@ if (not GEA) then if (not entry[GEA.keys["DONE"]]) then GEA.log("Check", entry, GEA.translate[GEA.language]["ACTIVATED_SINCE"] .. (entry[GEA.keys["TOTALRUNS"]] * GEA.checkEvery) .. "/" .. entry[GEA.keys["SECONDES"]], false) end - + if (entry[GEA.keys["SECONDES"]] < 0 and (entry[GEA.keys["MAXTIME"]] == -1 or (entry[GEA.keys["TOTALRUNS"]]-1) < entry[GEA.keys["MAXTIME"]])) then - GEA.sendActions(entry) + GEA.sendActions(entry) end - + if (entry[GEA.keys["SECONDES"]] < 0 and entry[GEA.keys["MAXTIME"]] > -1) then GEA.addOrRemoveTask("M", entry[GEA.keys["INDEX"]] .. "{(%d+)}", false) if (entry[GEA.keys["TOTALRUNS"]] >= entry[GEA.keys["MAXTIME"]] ) then GEA.addOrRemoveTask("S", entry[GEA.keys["INDEX"]], true) else - GEA.addOrRemoveTask("M", entry[GEA.keys["INDEX"]] .. "{" .. entry[GEA.keys["TOTALRUNS"]] .. "}", true) + GEA.addOrRemoveTask("M", entry[GEA.keys["INDEX"]] .. "{" .. entry[GEA.keys["TOTALRUNS"]] .. "}", true) end end else @@ -818,12 +818,12 @@ if (not GEA) then entry[GEA.keys["TOTALRUNS"]] = 0 entry[GEA.keys["DONE"]] = false entry[GEA.keys["OK"]] = false - end + end if (GEA.source["type"] == "autostart" and ((entry[GEA.keys["NBRUN"]] * GEA.checkEvery) >= entry[GEA.keys["SECONDES"]]) and not entry[GEA.keys["DONE"]] and (entry[GEA.keys["MAXTIME"]] == -1 or (entry[GEA.keys["TOTALRUNS"]]-1) < entry[GEA.keys["MAXTIME"]])) then -- Envoi du messsage au destinataires GEA.sendActions(entry) - entry[GEA.keys["OK"]] = true + entry[GEA.keys["OK"]] = true if (entry[GEA.keys["ISREPEAT"]] and entry[GEA.keys["MAXTIME"]] == -1) then --- nothing @@ -841,9 +841,9 @@ if (not GEA) then entry[GEA.keys["OK"]] = false end end - + -- --------------------------------------------------------------------------- - -- Vérification spécifique pour savoir si un périphérique est activé + -- Vérification spécifique pour savoir si un périphérique est activé -- ou non -- --------------------------------------------------------------------------- GEA.isActivated = function(entry, nb, master) @@ -852,17 +852,17 @@ if (not GEA) then else GEA.log("isActivated", entry, GEA.translate[GEA.language]["CHECK_IF"], false) end - + local mainid = -1 local id = entry[GEA.keys["ID"]] local result = true local typeID = type(id) - - if (typeID == "nil") then + + if (typeID == "nil") then result = true master[GEA.keys["VALUE"]][nb] = "true" - elseif (typeID == "boolean") then + elseif (typeID == "boolean") then result = id if (result) then @@ -904,7 +904,7 @@ if (not GEA) then else result = tonumber(fibaro:getValue(tonumber(id), "value")) == 1 end - + mainid = tonumber(id) master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id), "value") @@ -920,13 +920,13 @@ if (not GEA) then GEA.log("isActivated", entry, "type : Global+", false) result = tonumber(fibaro:getGlobalValue(id[2])) > tonumber(id[3]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getGlobalValue(id[2]) + master[GEA.keys["VALUE"]][nb] = fibaro:getGlobalValue(id[2]) elseif (lowerValue == "global-" and #id > 2) then GEA.log("isActivated", entry, "type : Global-", false) result = tonumber(fibaro:getGlobalValue(id[2])) < tonumber(id[3]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getGlobalValue(id[2]) + master[GEA.keys["VALUE"]][nb] = fibaro:getGlobalValue(id[2]) elseif (lowerValue == "global!" and #id > 2) then GEA.log("isActivated", entry, "type : Global!", false) @@ -947,7 +947,7 @@ if (not GEA) then elseif (lowerValue == "slider!" and #id > 3) then GEA.log("isActivated", entry, "type : Slider!", false) result = tonumber(fibaro:getValue(id[2], "ui." .. id[3] .. ".value")) ~= tonumber(id[4]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") elseif (lowerValue == "slider+" and #id > 3) then GEA.log("isActivated", entry, "type : Slider+", false) @@ -959,25 +959,25 @@ if (not GEA) then GEA.log("isActivated", entry, "type : Label", false) result = GEA.match(fibaro:getValue(id[2], "ui." .. id[3] .. ".value"), id[4]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") elseif (lowerValue == "label!" and #id > 3) then GEA.log("isActivated", entry, "type : Label!", false) result = not GEA.match(fibaro:getValue(id[2], "ui." .. id[3] .. ".value"), id[4]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], "ui." .. id[3] .. ".value") elseif (lowerValue == "property" and #id > 3) then GEA.log("isActivated", entry, "type : Property", false) result = GEA.match(fibaro:getValue(id[2], id[3]), id[4]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], id[3]) + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], id[3]) elseif (lowerValue == "property!" and #id > 3) then GEA.log("isActivated", entry, "type : Property", false) result = not GEA.match(fibaro:getValue(id[2], id[3]), id[4]) --mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], id[3]) + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(id[2], id[3]) elseif (lowerValue == "batteries" and #id > 1) then GEA.log("isActivated", entry, "type : batteries", false) @@ -986,18 +986,18 @@ if (not GEA) then for i = 1, 1000 do local batt = fibaro:getValue(i, 'batteryLevel') - if (type(batt) ~= nil and (tonumber(batt) ~= nil) and (tonumber(batt) <= tonumber(id[2])) or (tonumber(batt) == 255)) then + if (type(batt) ~= nil and (tonumber(batt) ~= nil) and (tonumber(batt) <= tonumber(id[2])) or (tonumber(batt) == 255)) then GEA.log("isActivated", entry, "checking : batteries " .. fibaro:getName(i), false) if (not string.find(fibaro:getName(i), "Zwave_")) then - msg = msg .. GEA.translate[GEA.language]["BATTERIE"] .. " [" .. fibaro:getName(i) .. "] " .. batt .. "%\n" - result = true + msg = msg .. GEA.translate[GEA.language]["BATTERIE"] .. " [" .. fibaro:getName(i) .. "] " .. batt .. "%\n" + result = true end end end - master[GEA.keys["VALUE"]][nb] = id[2] - entry[GEA.keys["MESSAGE"]] = msg + master[GEA.keys["VALUE"]][nb] = id[2] + entry[GEA.keys["MESSAGE"]] = msg elseif ((lowerValue == "sensor" or lowerValue == "power") and #id > 2) then GEA.log("isActivated", entry, "type : Sensor", false) @@ -1009,7 +1009,7 @@ if (not GEA) then GEA.log("isActivated", entry, "type : Sensor+", false) result = tonumber(fibaro:getValue(tonumber(id[2]), GEA.power)) > tonumber(id[3]) mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), GEA.power) + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), GEA.power) elseif ((lowerValue == "sensor-" or lowerValue == "power-") and #id > 2) then GEA.log("isActivated", entry, "type : Sensor-", false) @@ -1021,15 +1021,15 @@ if (not GEA) then GEA.log("isActivated", entry, "type : Sensor!", false) result = tonumber(fibaro:getValue(tonumber(id[2]), GEA.power)) ~= tonumber(id[3]) mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), GEA.power) + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), GEA.power) elseif (lowerValue == "battery" and #id > 2) then GEA.log("isActivated", entry, "type : Battery", false) result = false local batt = fibaro:getValue(tonumber(id[2]), 'batteryLevel') - if (type(batt) ~= nil and tonumber(batt) <= tonumber(id[3]) or tonumber(batt) == 255) then - result = true + if (type(batt) ~= nil and tonumber(batt) <= tonumber(id[3]) or tonumber(batt) == 255) then + result = true master[GEA.keys["VALUE"]][nb] = batt end @@ -1039,19 +1039,19 @@ if (not GEA) then GEA.log("isActivated", entry, "type : Value", false) result = tonumber(fibaro:getValue(tonumber(id[2]), "value")) == tonumber(id[3]) mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") elseif (lowerValue == "value+" and #id > 2) then GEA.log("isActivated", entry, "type : Value+", false) result = tonumber(fibaro:getValue(tonumber(id[2]), "value")) > tonumber(id[3]) mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") elseif (lowerValue == "value-" and #id > 2) then GEA.log("isActivated", entry, "type : Value-", false) result = tonumber(fibaro:getValue(tonumber(id[2]), "value")) < tonumber(id[3]) mainid = tonumber(id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "value") elseif (lowerValue == "value!" and #id > 2) then GEA.log("isActivated", entry, "type : Value!", false) @@ -1061,13 +1061,13 @@ if (not GEA) then elseif (lowerValue == "dead" and #id > 1) then GEA.log("isActivated", entry, "type : isDead", false) - result = tonumber(fibaro:getValue(tonumber(id[2]), "dead")) >= 1 + result = tonumber(fibaro:getValue(tonumber(id[2]), "dead")) >= 1 master[GEA.keys["VALUE"]][nb] = fibaro:getValue(tonumber(id[2]), "dead") elseif (lowerValue == "weather" and #id > 1) then GEA.log("isActivated", entry, "type : weather", false) result = GEA.match(fibaro:getValue(3, "WeatherConditionConverted"), id[2]) - master[GEA.keys["VALUE"]][nb] = fibaro:getValue(3, "WeatherConditionConverted") + master[GEA.keys["VALUE"]][nb] = fibaro:getValue(3, "WeatherConditionConverted") elseif (lowerValue == "function" and #id > 1) then GEA.log("isActivated", entry, "type : Function", false) @@ -1076,9 +1076,9 @@ if (not GEA) then if (status) then result = err - if (value) then - master[GEA.keys["VALUE"]][nb] = value - end + if (value) then + master[GEA.keys["VALUE"]][nb] = value + end else result = false end @@ -1125,7 +1125,7 @@ if (not GEA) then else -- autre à venir end - + if (nb == 1) then for i = 1, #entry[GEA.keys["PARAMS"]] do if (string.lower(entry[GEA.keys["PARAMS"]][i][1]) == "inverse") then @@ -1178,18 +1178,18 @@ if (not GEA) then end end - if (result) then + if (result) then GEA.log("isActivated", entry, GEA.translate[GEA.language]["ACTIVATED"], false) else GEA.log("!CANCEL! isActivated", entry, GEA.translate[GEA.language]["DESACTIVATED"], false, "yellow") end return result end - + -- --------------------------------------------------------------------------- -- Permet de définir / spécifier un message précis qui sera envoyé -- par la méthode sendWarning - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.getMessage = function(entry, message) local msg = "" @@ -1199,10 +1199,10 @@ if (not GEA) then if (message and message ~= "") then msg = message - end - - if (entry[GEA.keys["VALUE"]][1]) then - msg = string.gsub(msg, "#value#", entry[GEA.keys["VALUE"]][1]) + end + + if (entry[GEA.keys["VALUE"]][1]) then + msg = string.gsub(msg, "#value#", entry[GEA.keys["VALUE"]][1]) msg = string.gsub(msg, "#value%[1%]#", entry[GEA.keys["VALUE"]][1]) end @@ -1218,7 +1218,7 @@ if (not GEA) then msg = string.gsub(msg, "#time#", os.date("%X")) msg = string.gsub(msg, "#date#", os.date("%x")) - if (entry[GEA.keys["NAME"]][1]) then + if (entry[GEA.keys["NAME"]][1]) then msg = string.gsub(msg, "#name#", entry[GEA.keys["NAME"]][1]) msg = string.gsub(msg, "#name%[1%]#", entry[GEA.keys["NAME"]][1]) end @@ -1232,7 +1232,7 @@ if (not GEA) then if (entry[GEA.keys["NAME"]][8]) then msg = string.gsub(msg, "#name%[8%]#", entry[GEA.keys["NAME"]][8]) end if (entry[GEA.keys["NAME"]][9]) then msg = string.gsub(msg, "#name%[9%]#", entry[GEA.keys["NAME"]][9]) end - if (entry[GEA.keys["ROOM"]][1]) then + if (entry[GEA.keys["ROOM"]][1]) then msg = string.gsub(msg, "#room#", entry[GEA.keys["ROOM"]][1]) msg = string.gsub(msg, "#room%[1%]#", entry[GEA.keys["ROOM"]][1]) end @@ -1244,23 +1244,23 @@ if (not GEA) then if (entry[GEA.keys["ROOM"]][6]) then msg = string.gsub(msg, "#room%[6%]#", entry[GEA.keys["ROOM"]][6]) end if (entry[GEA.keys["ROOM"]][7]) then msg = string.gsub(msg, "#room%[7%]#", entry[GEA.keys["ROOM"]][7]) end if (entry[GEA.keys["ROOM"]][8]) then msg = string.gsub(msg, "#room%[8%]#", entry[GEA.keys["ROOM"]][8]) end - if (entry[GEA.keys["ROOM"]][9]) then msg = string.gsub(msg, "#room%[9%]#", entry[GEA.keys["ROOM"]][9]) end + if (entry[GEA.keys["ROOM"]][9]) then msg = string.gsub(msg, "#room%[9%]#", entry[GEA.keys["ROOM"]][9]) end msg = string.gsub(msg, "#seconds#", entry[GEA.keys["SECONDES"]]) - + local durees = GEA.getDureeInString( entry[GEA.keys["TOTALRUNS"]] * GEA.checkEvery) - + msg = string.gsub(msg, "#duration#", durees[1]) msg = string.gsub(msg, "#durationfull#", durees[2]) msg = string.gsub(msg, "#runs#", entry[GEA.keys["TOTALRUNS"]]) - + return msg end - + -- --------------------------------------------------------------------------- -- Converti une durée en chaîne de caratères -- --------------------------------------------------------------------------- - GEA.getDureeInString = function(duree) + GEA.getDureeInString = function(duree) local duree = duree local dureefull = "" @@ -1269,75 +1269,75 @@ if (not GEA) then nSecs = math.floor(duree - nHours*3600 - nMins *60) duree = "" - if (nHours > 0) then - duree = duree .. nHours .. "h " + if (nHours > 0) then + duree = duree .. nHours .. "h " dureefull = dureefull .. nHours - if (nHours > 1) then - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["HOURS"] - else - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["HOUR"] + if (nHours > 1) then + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["HOURS"] + else + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["HOUR"] end end - if (nMins > 0) then - duree = duree .. nMins .. "m " + if (nMins > 0) then + duree = duree .. nMins .. "m " - if (nHours > 0) then - dureefull = dureefull .. " " + if (nHours > 0) then + dureefull = dureefull .. " " end - if (nSecs == 0 and nHours > 0) then - dureefull = dureefull .. "et " + if (nSecs == 0 and nHours > 0) then + dureefull = dureefull .. "et " end dureefull = dureefull .. nMins - if (nMins > 1) then - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["MINUTES"] - else - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["MINUTE"] + if (nMins > 1) then + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["MINUTES"] + else + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["MINUTE"] end end - if (nSecs > 0) then - duree = duree .. nSecs .. "s" + if (nSecs > 0) then + duree = duree .. nSecs .. "s" - if (nMins > 0) then - dureefull = dureefull .. " et " + if (nMins > 0) then + dureefull = dureefull .. " et " end dureefull = dureefull .. nSecs - if (nSecs > 1) then - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["SECONDS"] - else - dureefull = dureefull .. " " .. GEA.translate[GEA.language]["SECOND"] + if (nSecs > 1) then + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["SECONDS"] + else + dureefull = dureefull .. " " .. GEA.translate[GEA.language]["SECOND"] end end - + return {duree, dureefull} end - + -- --------------------------------------------------------------------------- -- Envoi le message en push -- --------------------------------------------------------------------------- GEA.sendActions = function(entry) - + GEA.log("sendActions", entry, GEA.translate[GEA.language]["ACTIONS"] , true) local pushed = false - + if (type(entry[GEA.keys["PARAMS"]]) == "table") then - + for i = 1, #entry[GEA.keys["PARAMS"]] do local paramsIterator = entry[GEA.keys["PARAMS"]][i] if (type(paramsIterator) == "table") then local lowerValue = string.lower(paramsIterator[1]) - if ((lowerValue == "turnoff" or lowerValue == "turnon" or lowerValue == "switch")) then + if ((lowerValue == "turnoff" or lowerValue == "turnon" or lowerValue == "switch")) then local id = GEA.getId(entry, paramsIterator) - if (id > 0) then + if (id > 0) then local etat = fibaro:getValue(tonumber(id), "value") local typef = fibaro:getType(tonumber(id)) @@ -1349,11 +1349,11 @@ if (not GEA) then -- verison 4.x etat = 1 end - end + end - if (tonumber(etat) >= 1 and lowerValue == "turnoff") or (tonumber(etat) == 0 and lowerValue == "turnon") then + if (tonumber(etat) >= 1 and lowerValue == "turnoff") or (tonumber(etat) == 0 and lowerValue == "turnon") then fibaro:call(tonumber(id), paramsIterator[1]) - elseif (lowerValue == "switch") then + elseif (lowerValue == "switch") then local mode = "turnOff" if (tonumber(etat) == 0) then @@ -1366,25 +1366,25 @@ if (not GEA) then GEA.log("sendActions", entry, "!ACTION! : " .. paramsIterator[1] , true) end end - + if (lowerValue == "global" and #paramsIterator > 2) then local value = string.match(paramsIterator[3], "(%d+)") if (GEA.match(paramsIterator[3], "inc%+")) then local number = tonumber(fibaro:getGlobalValue(paramsIterator[2])) - if (type(value) ~= "nil") then - fibaro:setGlobal(paramsIterator[2], number + value) - else - fibaro:setGlobal(paramsIterator[2], number + 1) + if (type(value) ~= "nil") then + fibaro:setGlobal(paramsIterator[2], number + value) + else + fibaro:setGlobal(paramsIterator[2], number + 1) end elseif (GEA.match(paramsIterator[3], "dec%-")) then local number = tonumber(fibaro:getGlobalValue(paramsIterator[2])) - if (type(value) ~= "nil") then - fibaro:setGlobal(paramsIterator[2], number - value) - else - fibaro:setGlobal(paramsIterator[2], number - 1) + if (type(value) ~= "nil") then + fibaro:setGlobal(paramsIterator[2], number - value) + else + fibaro:setGlobal(paramsIterator[2], number - 1) end else fibaro:setGlobal(paramsIterator[2], GEA.getMessage(entry,paramsIterator[3])) @@ -1457,7 +1457,7 @@ if (not GEA) then elseif (lowerValue == "copyglobal" and #paramsIterator > 2) then fibaro:setGlobal(paramsIterator[3], fibaro:getGlobalValue(paramsIterator[2])) - GEA.log("sendActions", entry, "!ACTION! : CopyGlobal " .. paramsIterator[2], true) + GEA.log("sendActions", entry, "!ACTION! : CopyGlobal " .. paramsIterator[2], true) elseif (lowerValue == "restarttask" and #paramsIterator > 1) then GEA.addOrRemoveTask("R", paramsIterator[2], true) @@ -1468,7 +1468,7 @@ if (not GEA) then GEA.log("sendActions", entry, "!ACTION! : StopTask " .. paramsIterator[2], true) elseif (lowerValue == "wakeup" and #paramsIterator > 1) then - fibaro:wakeUpDeadDevice(paramsIterator[2]) + fibaro:call(1, 'wakeUpAllDevices', (paramsIterator[2])) GEA.log("sendActions", entry, "!ACTION! : WakeUp " .. paramsIterator[2], true) elseif (lowerValue == "virtualdevice" and #paramsIterator > 2) then @@ -1508,7 +1508,7 @@ if (not GEA) then GEA.log("sendActions", entry, "!ACTION! : RGB " .. paramsIterator[2] .. ", Color = " .. paramsIterator[3] .. "," .. paramsIterator[4] .. "," .. paramsIterator[5] .. "," .. paramsIterator[6]) elseif (lowerValue == "program" and #paramsIterator > 2) then - if (tonumber(fibaro:getValue(tonumber(paramsIterator[2]), "currentProgramID")) ~= tonumber(paramsIterator[3])) then + if (tonumber(fibaro:getValue(tonumber(paramsIterator[2]), "currentProgramID")) ~= tonumber(paramsIterator[3])) then fibaro:call(paramsIterator[2], "startProgram", paramsIterator[3]) end @@ -1523,7 +1523,7 @@ if (not GEA) then GEA.log("sendActions", entry, "!ACTION! : setValue " .. paramsIterator[3], true) else fibaro:call(id, "setValue", paramsIterator[2]) - GEA.log("sendActions", entry, "!ACTION! : setValue " .. paramsIterator[2], true) + GEA.log("sendActions", entry, "!ACTION! : setValue " .. paramsIterator[2], true) end end @@ -1534,20 +1534,20 @@ if (not GEA) then local pourc = 100 if (#paramsIterator > 2) then - if (lowerValue == "close") then - pourc = pourc - paramsIterator[3] - else - pourc = paramsIterator[3] + if (lowerValue == "close") then + pourc = pourc - paramsIterator[3] + else + pourc = paramsIterator[3] end fibaro:call(id, "setValue", pourc) GEA.log("sendActions", entry, "!ACTION! : setValue " .. pourc, true) elseif (#paramsIterator > 1) then - if (lowerValue == "close") then - pourc = pourc - paramsIterator[2] - else - pourc = paramsIterator[2] + if (lowerValue == "close") then + pourc = pourc - paramsIterator[2] + else + pourc = paramsIterator[2] end fibaro:call(id, "setValue", pourc) @@ -1575,10 +1575,10 @@ if (not GEA) then end end end - + -- --------------------------------------------------------------------------- -- Chercher l'id du périphérique - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.getId = function(entry, param) local id = 0 @@ -1598,10 +1598,10 @@ if (not GEA) then return id end - + -- --------------------------------------------------------------------------- -- Le système est-il en pause - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.pause = function() local continue = true @@ -1610,18 +1610,18 @@ if (not GEA) then if (fibaro:getGlobalValue(GEA.getGlobalForActivation[1]) == GEA.getGlobalForActivation[2]) then continue = true - else + else GEA.log("Run", nil, GEA.translate[GEA.language]["GEA_SUSPENDED"] .. " " .. GEA.getGlobalForActivation[1] .. " " .. GEA.translate[GEA.language]["VALUE"] .. " " .. fibaro:getGlobalValue(GEA.getGlobalForActivation[1]) .. " " .. GEA.translate[GEA.language]["REQUIRED"] .. " " .. GEA.getGlobalForActivation[2], true) end end return not continue end - + -- --------------------------------------------------------------------------- -- Contrôle tous les périphériques déclarés toutes les X secondes - -- --------------------------------------------------------------------------- - GEA.run = function() + -- --------------------------------------------------------------------------- + GEA.run = function() if (config) then config() end @@ -1629,13 +1629,13 @@ if (not GEA) then if (setEvents) then setEvents() end - - if (GEA.isVersionFour) then + + if (GEA.isVersionFour) then GEA.power = "power" end - + GEA.log("GEA Version " .. GEA.version, nil, " " .. GEA.translate[GEA.language]["RUNNING"] .. "...", true, "green") - + if (#GEA.todo == 0) then if (GEA.source["type"] ~= "property") then GEA.log(GEA.translate[GEA.language]["RUN"], nil, GEA.translate[GEA.language]["NOTHING_TODO"], true) @@ -1644,39 +1644,39 @@ if (not GEA) then end return false - end - + end + local nbElement = #GEA.todo - + if (GEA.source["type"] == "autostart") then if (GEA.useTasksGlobal) then fibaro:setGlobal(GEA.globalTasks, GEA.suspended) else GEA.tasks = GEA.suspended end - + local delai = GEA.checkEvery local count = 1 local firstOfAll = true local allStart = os.time() - + while true do GEA.log(GEA.translate[GEA.language]["RUN"], nil, GEA.translate[GEA.language]["SLEEPING"] .. " " .. GEA.checkEvery .. " " .. GEA.translate[GEA.language]["SECONDS"], false) fibaro:sleep(delai * 1000) local start = os.time() - local stop = GEA.checkAllToDo(nbElement) + local stop = GEA.checkAllToDo(nbElement) local diff = (stop - start) -- / 1000 - if (firstOfAll) then - diff = diff * 2 + if (firstOfAll) then + diff = diff * 2 firstOfAll = false end delai = GEA.checkEvery - diff -- Log toutes les 20 checks que GEA tourne - if (count >= 20) then + if (count >= 20) then local msg = GEA.translate[GEA.language]["RUN_FOR"] .. diff .. "s " .. GEA.translate[GEA.language]["RUN_NEW"] .. delai .. "s / ".. GEA.translate[GEA.language]["RUN_SINCE"] .. " " .. GEA.getDureeInString(os.time() - allStart)[1] fibaro:debug("" .. msg .. "") count = 0 @@ -1685,15 +1685,15 @@ if (not GEA) then count = count + 1 end else - GEA.checkAllToDo(nbElement) + GEA.checkAllToDo(nbElement) end end -- --------------------------------------------------------------------------- -- Check les tâches à effectuer sinon, log si une erreur survient - -- --------------------------------------------------------------------------- + -- --------------------------------------------------------------------------- GEA.checkAllToDo = function(nbElement) - if (not GEA.pause()) then + if (not GEA.pause()) then for i = 1, nbElement do GEA.log(GEA.translate[GEA.language]["RUN"], GEA.todo[i], GEA.translate[GEA.language]["CHECKING"], false) @@ -1702,30 +1702,30 @@ if (not GEA) then GEA.log(GEA.translate[GEA.language]["ERROR"], GEA.todo[i], GEA.translate[GEA.language]["CHECKING"], true, red) end else - GEA.check(GEA.todo[i], i) + GEA.check(GEA.todo[i], i) end end end - return os.time() + return os.time() end - + -- --------------------------------------------------------------------------- -- Contrôle tous les périphériques déclarés toutes les X secondes - -- --------------------------------------------------------------------------- - GEA.log = function(method, entry, message, force, color) + -- --------------------------------------------------------------------------- + GEA.log = function(method, entry, message, force, color) if (force or GEA.debug) then local msg = "" local name = "If" - if (not entry and not force) then - return + if (not entry and not force) then + return elseif (entry) then local typeEntry = type(entry[GEA.keys["ID"]]) - if (entry[GEA.keys["NAME"]]) then - name = entry[GEA.keys["NAME"]] + if (entry[GEA.keys["NAME"]]) then + name = entry[GEA.keys["NAME"]] if (type(name) == "table") then name = name[1] @@ -1740,28 +1740,28 @@ if (not GEA) then elseif (typeEntry == "table") then lowerId = string.lower(entry[GEA.keys["ID"]][1]) - if (GEA.match(lowerId, "global|global.")) then + if (GEA.match(lowerId, "global|global.")) then msg = msg .. "[ " .. entry[GEA.keys["ID"]][2] .. "=" .. entry[GEA.keys["ID"]][3] .. " ] " - elseif (lowerId == "batteries") then + elseif (lowerId == "batteries") then msg = msg .. "[ " .. entry[GEA.keys["ID"]][2] .. " ] " - elseif (lowerId == "group") then + elseif (lowerId == "group") then msg = msg .. "[ " .. name - elseif (GEA.match(lowerId, "sensor|sensor.|value|value.|dead|sceneactivation|battery")) then + elseif (GEA.match(lowerId, "sensor|sensor.|value|value.|dead|sceneactivation|battery")) then msg = msg .. "[ " .. name - elseif (GEA.match(lowerId, "slider|slider.|label|label.|property|property.")) then + elseif (GEA.match(lowerId, "slider|slider.|label|label.|property|property.")) then msg = msg .. "[ " .. name - elseif (lowerId == "weather") then - msg = msg .. "[ Weather ] " - elseif (lowerId == "function") then + elseif (lowerId == "weather") then + msg = msg .. "[ Weather ] " + elseif (lowerId == "function") then msg = msg .. "[ Function ] " elseif (lowerId == "alarm") then msg = msg .. "Alarm " .. fibaro:getValue(tonumber(entry[GEA.keys["ID"]][2]), "ui.lblAlarme.value") - else + else -- autre à venir end end end - end + end if (method and method ~= "") then msg = msg .. string.format("%-20s", method) .. ": " @@ -1776,20 +1776,20 @@ if (not GEA) then msg = msg .. " (ID: " .. entry[GEA.keys["INDEX"]] .. ")" end - if (entry[GEA.keys["PARAMS"]] and type(entry[GEA.keys["PARAMS"]]) == "table" and #entry[GEA.keys["PARAMS"]] > 0) then - for i = 1, #entry[GEA.keys["PARAMS"]] do + if (entry[GEA.keys["PARAMS"]] and type(entry[GEA.keys["PARAMS"]]) == "table" and #entry[GEA.keys["PARAMS"]] > 0) then + for i = 1, #entry[GEA.keys["PARAMS"]] do msg = msg .. " [" local paramToIterate = entry[GEA.keys["PARAMS"]][i] if (type(paramToIterate) == "table") then for j = 1, #paramToIterate do if (string.lower(paramToIterate[1]) == "if") then - if (j == 1) then - msg = msg .. "If..." + if (j == 1) then + msg = msg .. "If..." end elseif (string.lower(paramToIterate[1]) == "function") then - if (j == 1) then - msg = msg .. "Function..." + if (j == 1) then + msg = msg .. "Function..." end else msg = msg .. paramToIterate[j] .. "," @@ -1798,7 +1798,7 @@ if (not GEA) then end msg = msg:sub(1, msg:len()-1) .. "]" - end + end end end diff --git a/GEA.min.lua b/GEA.min.lua index 3d546ad..71283df 100644 --- a/GEA.min.lua +++ b/GEA.min.lua @@ -9,7 +9,7 @@ -- ================================================== -- GEA : Gestionnaire d'Evénements Automatique -- ================================================== --- [FR] Scénario permettant de contrôler si un périphérique est +-- [FR] Scénario permettant de contrôler si un périphérique est -- activé depuis trop longtemps ou lancer un push d'avertissement. -- Ce scénario permet une annotation plus simple que le code LUA -- il nécessite néanmoins quelques connaissances. @@ -34,7 +34,7 @@ -- Paramétrage de GEA / GEA configuration function config() - GEA.isVersionFour = true -- On est en version 4.017 Beta ou supérieure / + GEA.isVersionFour = true -- On est en version 4.017 Beta ou supérieure / GEA.language = "FR" -- Votre langue : FR (default) / Your language : EN GEA.checkEvery = 30 -- On vérifie toutes les X secondes (default : 30) / Check every X seconds GEA.portables = {179} -- Liste des portables devant recevoir une notification {70, 71} / Smartphones you want to be notified @@ -44,13 +44,13 @@ function config() GEA.optimize = GEA.typeOptimize["IMMEDIATE_ONLY"] -- option : GEA.typeOptimize["NONE"], GEA.typeOptimize["IMMEDIATE_ONLY"], GEA.typeOptimize["ALL"] -- permet d'optimiser les soucis liés au getName et getRoom de fibaro mais n'affiche plus le nom des modules concernés. -end +end -- Ajouter ici les événements à exécuter / Add here events to schedule -- Une liste d'exemples est disponible dans un fichier annexe samples.lua / A samples list is available in another file called samples.lua -function setEvents() +function setEvents() @@ -67,4 +67,4 @@ end -- SCRIPT GEA PRINCIPAL / GEA MAIN SCRIPT -- -- ================================================== -if not GEA then GEA={}GEA.version="5.40"GEA.language="FR"GEA.checkEvery=30;GEA.index=0;GEA.isVersionFour=true;GEA.globalTasks="GEA_Tasks"GEA.regexFullAllow=false;GEA.portables={}GEA.todo={}GEA.power="valueSensor"GEA.suspended=""GEA.keys={ID=1,SECONDES=2,MESSAGE=3,ISREPEAT=4,PARAMS=5,NAME=6,NBRUN=7,DONE=8,VALUE=9,GROUPS=10,OK=11,TOTALRUNS=12,INDEX=13,MAXTIME=14,ROOM=15}GEA.debug=false;GEA.catchError=true;GEA.pos=1;GEA.useTasksGlobal=true;GEA.tasks=""GEA.typeOptimize={NONE=0,IMMEDIATE_ONLY=1,ALL=2}GEA.optimize=GEA.typeOptimize["NONE"]GEA.getGlobalForActivation={}GEA.source=fibaro:getSourceTrigger()GEA.translate={true,true}GEA.translate["FR"]={ACTIONS="traitement des actions",ACTIVATED="activé",ACTIVATED_SINCE="activé depuis ",ADDED_DIRECT="ajout de la tâche pour lancement instantané",ADDED_FOR="ajout de la tâche pour",ALWAYS="Toujours",BATTERIE="Pile faible",CHECKING="vérification",CHECKING_DATE="vérification des dates",CHECKING_TIME="vérification plage horaire",CHECK_IF="vérification de l'exception",CHECK_IF_FAILED="désactivé par exception",CHECK_MAIN="vérification de l'activation",CHECK_STARTED="démarrage vérification",CURRENT_TIME="L'heure actuelle",DATE_NOT_ALLOWED="n'est pas dans la plage de dates spécifiées",DESACTIVATED="désactivé",DEVICE_NOT_FOUND="ID non trouvé",DONE="tâche effectuée et suspendue",ERROR="!!! ERREUR !!!",ERROR_IF="IF malformé",GEA_SUSPENDED="Scénario suspendu par la variable globale ",HOUR="heure",HOURS="heures",MINUTE="minute",MINUTES="minutes",NOTHING_TODO="aucun traitement à effectuer",NOTHING_TODOID="aucun traitement à effectuer pour l'ID :",NOT_INCLUDED="n'est pas inclus dans",REQUIRED="attendu",RESTART="Redémarrage",RUN="En cours",RUNNING="en exécution",RUN_FOR="Durée des traitements : ",RUN_NEW="nouveau délai : ",RUN_SINCE="tourne depuis",SECOND="seconde",SECONDS="secondes",SLEEPING="Endormi pendant",SUPSENDED="Arrêtée",SUSPEND_ERROR="ERROR GEA.Suspend demande un tableau en paramètre 2",TIME_IN="vérification contrôlée car dans la plage horaire spécifiée ",TIME_NOT_ALLOWED="n'est pas autorisée",TIME_OUT="vérification ignorée car en dehors de la plage horaire : ",TODAY="Aujourd'hui ",TODAY_NOT_DST="Aujourd'hui n'est pas en mode DST",VALUE="valeur",WILL_SUSPEND="entrainera la suspension de"}GEA.translate["EN"]={ACTIONS="doing actions",ACTIVATED="activated",ACTIVATED_SINCE="activated since ",ADDED_DIRECT="task added for instant run",ADDED_FOR="task added for",ALWAYS="Always",BATTERIE="Low batterie",CHECKING="checking",CHECKING_DATE="checking dates",CHECKING_TIME="checking time range",CHECK_IF="'if' checking",CHECK_IF_FAILED="'if' stop the check",CHECK_MAIN="activation checking",CHECK_STARTED="starting checking",CURRENT_TIME="Current hour",DATE_NOT_ALLOWED="is not in the specified dates range",DESACTIVATED="desactivated",DEVICE_NOT_FOUND="Device ID not found",DONE="task done and suspended",ERROR="!!! ERROR !!!",ERROR_IF="IF malformed",GEA_SUSPENDED="Scene suspended by the global variable ",HOUR="hour",HOURS="hours",MINUTE="minute",MINUTES="minutes",NOTHING_TODO="nothing to do",NOTHING_TODOID="nothing to do for ID:",NOT_INCLUDED="is not included in",REQUIRED="excepted",RESTART="Restart",RUN="Run",RUNNING="Running",RUN_FOR="Duration : ",RUN_NEW="new delay : ",RUN_SINCE="running since",SECOND="second",SECONDS="seconds",SLEEPING="Sleeping for",SUPSENDED="Stopped",SUSPEND_ERROR="ERROR GEA.Suspend require a table as second parameter",TIME_IN="checking done time range is ok ",TIME_NOT_ALLOWED="is not allowed",TIME_OUT="checking abort because out of time range: ",TODAY="Today ",TODAY_NOT_DST="Today is not in DST mode",VALUE="value",WILL_SUSPEND="will suspend "}GEA.add=function(a,b,c,d)local e=false;local f=false;local g=-1;local h={}local i={}local j={}local k={}if d and#d>0 then for l=1,#d do lowCapsArg=string.lower(d[l][1])if lowCapsArg=="repeat"then e=true elseif lowCapsArg=="maxtime"then g=tonumber(d[l][2])elseif lowCapsArg=="group"then h[tonumber(d[l][2])]=true elseif lowCapsArg=="notstarted"then f=true end end;i=d end;if g>-1 then e=true end;GEA.index=GEA.index+1;if type(a)=="table"then if type(a[1])=="number"or type(a[1])=="table"then local m={}for l=2,#a do table.insert(m,a[l])j[l],k[l]=GEA.getName(a[l])end;a=a[1]if type(a)=="table"and type(a[1])=="string"and string.lower(a[1])=="alarm"then e=false;b=1 end;table.insert(i,{"If",m})elseif type(a[1])=="string"then if string.lower(a[1])=="global"and#a>2 and a[2]==""and a[3]==""then a=true elseif string.lower(a[1])=="alarm"then e=false;b=1 end end end;j[1],k[1]=GEA.getName(a)local n={a,b,c,e,i,j,0,false,{},h,false,0,GEA.index,g,k}if GEA.source["type"]=="autostart"and tonumber(n[GEA.keys["SECONDES"]])>=0 then GEA.insert(n)GEA.log("Add Autostart",n,GEA.translate[GEA.language]["ADDED_FOR"].." "..b.." "..GEA.translate[GEA.language]["SECONDS"],true,"grey")if f then local o=GEA.getCode("S",n[GEA.keys["INDEX"]])if GEA.suspended~=nil then GEA.suspended=string.gsub(GEA.suspended,o,"")end;GEA.suspended=GEA.suspended..o end elseif GEA.source["type"]=="global"and tonumber(n[GEA.keys["SECONDES"]])<0 then if type(n[GEA.keys["ID"]])=="table"and GEA.match(string.lower(n[GEA.keys["ID"]][1]),"global|global.")and n[GEA.keys["ID"]][2]==GEA.source["name"]then GEA.insert(n)GEA.log("Add Global",n,GEA.translate[GEA.language]["ADDED_DIRECT"],true,"grey")end elseif GEA.source["type"]=="property"and tonumber(n[GEA.keys["SECONDES"]])<0 then local a=0;if type(n[GEA.keys["ID"]])=="number"then a=n[GEA.keys["ID"]]elseif type(n[GEA.keys["ID"]])=="table"then a=n[GEA.keys["ID"]][2]if string.lower(n[GEA.keys["ID"]][1])=="sceneactivation"and#n[GEA.keys["ID"]]>2 then if tonumber(fibaro:getValue(a,"sceneActivation"))~=tonumber(n[GEA.keys["ID"]][3])then a=-1 end end end;if tonumber(a)==tonumber(GEA.source["deviceID"])then GEA.insert(n)GEA.log("Add Property",n,GEA.translate[GEA.language]["ADDED_DIRECT"],true,"grey")end end;return n[GEA.keys["INDEX"]]end;GEA.insert=function(n)GEA.todo[GEA.pos]=n;GEA.pos=GEA.pos+1;return n[GEA.keys["INDEX"]]end;GEA.addOrRemoveTask=function(p,index,add)local q=nil;local o=GEA.getCode(p,index)if GEA.useTasksGlobal then q=fibaro:getGlobalValue(GEA.globalTasks)else q=GEA.tasks end;if q~=nil then q=string.gsub(q,o,"")end;if add then if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,q..o)else GEA.tasks=q..o end else if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,q)else GEA.tasks=q end end end;GEA.isTask=function(p,index)local q=nil;local o=GEA.getCode(p,index)if GEA.useTasksGlobal then q=fibaro:getGlobalValue(GEA.globalTasks)else q=GEA.tasks end;if q~=nil then return string.match(q,o)end;return nil end;GEA.getCode=function(p,index)return"|"..p.."_"..index.."|"end;GEA.getName=function(a)if GEA.optimize==GEA.typeOptimize["ALL"]or GEA.source["type"]~="autostart"and GEA.optimize==GEA.typeOptimize["IMMEDIATE_ONLY"]then return"n/a","n/a"end;local k=""if type(a)=="nil"or type(a)=="boolean"then return GEA.translate[GEA.language]["ALWAYS"],""elseif type(a)=="number"then return fibaro:getName(tonumber(a)),GEA.getRoom(tonumber(a))elseif type(a)=="table"and GEA.match(string.lower(a[1]),"global|global.")then return a[2],""elseif type(a)=="table"then lowerCaps=string.lower(a[1])if a[2]then idNumeric=tonumber(a[2])end;if lowerCaps=="batteries"then return"Batteries <= "..a[1],""elseif lowerCaps=="sceneactivation"then return"Scene ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor+"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] > "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor-"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] < "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor!"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] ~= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="battery"then return"["..a[2].."|"..fibaro:getName(idNumeric).."] <= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value+"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] > "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value-"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] < "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value!"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] ~= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="dead"then return"Dead ["..a[2].."|"..fibaro:getName(idNumeric).."]",GEA.getRoom(idNumeric)elseif lowerCaps=="slider"then return"Slider ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider+"then return"Slider ["..a[2].."|"..a[3].."] > "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider-"then return"Slider ["..a[2].."|"..a[3].."] < "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider!"then return"Slider ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="label"then return"Label ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="label!"then return"Label ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="function"then return"Function",""elseif lowerCaps=="weather"then return"Weather",""elseif lowerCaps=="alarm"then return"Alarm "..fibaro:getValue(idNumeric,"ui.lblAlarme.value"),""elseif lowerCaps=="property"then return"Property ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="property!"then return"Property ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="group"then return"Group ["..a[2].."]",""else end end end;GEA.getRoom=function(a)local r=fibaro:getRoomID(a)if type(r)=="number"then local s=fibaro:getRoomName(r)if type(s)=="string"then return s end end;return""end;GEA.checkDay=function(t)local u=false;jours=t;jours=string.gsub(jours,"All","Weekday,Weekend")jours=string.gsub(jours,"Weekday","Monday,Tuesday,Wednesday,Thursday,Friday")jours=string.gsub(jours,"Weekend","Saturday,Sunday")if string.find(string.lower(jours),string.lower(os.date("%A")))then u=true end;return u end;GEA.checkTimes=function(n)GEA.log("Check",n,GEA.translate[GEA.language]["CHECKING_DATE"],false)if not n[GEA.keys["PARAMS"]]then return true end;local v=true;local u=true;local w=true;local x=true;local jours=""if type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local y=n[GEA.keys["PARAMS"]][l]if type(y)=="table"then if string.lower(y[1])=="days"then u=GEA.checkDay(y[2])elseif string.lower(y[1])=="dst"then x=os.date("*t",os.time()).isdst elseif string.lower(y[1])=="notdst"then x=not os.date("*t",os.time()).isdst elseif string.lower(y[1])=="dates"then w=false;local z=os.date("%Y%m%d")local A=y[2]if string.len(A)==5 then A=A.."/"..os.date("%Y")end;A=string.format("%04d",GEA.split(A,"/")[3])..string.format("%02d",GEA.split(A,"/")[2])..string.format("%02d",GEA.split(A,"/")[1])local B=y[3]if string.len(B)==5 then B=B.."/"..os.date("%Y")end;B=string.format("%04d",GEA.split(B,"/")[3])..string.format("%02d",GEA.split(B,"/")[2])..string.format("%02d",GEA.split(B,"/")[1])w=tonumber(z)>=tonumber(A)and tonumber(z)<=tonumber(B)end end end end;if u and x then local C=false;for l=1,#n[GEA.keys["PARAMS"]]do local y=n[GEA.keys["PARAMS"]][l]if type(y)=="table"and string.lower(y[1])=="dates"then if not C then w=false end;local z=os.date("%Y%m%d")local A=y[2]if string.len(A)==5 then A=A.."/"..os.date("%Y")end;A=string.format("%04d",GEA.split(A,"/")[3])..string.format("%02d",GEA.split(A,"/")[2])..string.format("%02d",GEA.split(A,"/")[1])local B=y[3]if string.len(B)==5 then B=B.."/"..os.date("%Y")end;B=string.format("%04d",GEA.split(B,"/")[3])..string.format("%02d",GEA.split(B,"/")[2])..string.format("%02d",GEA.split(B,"/")[1])if tonumber(A)>tonumber(B)and tonumber(A)>tonumber(z)then A=tonumber(A)-10000 end;if tonumber(z)>=tonumber(A)and tonumber(z)<=tonumber(B)then w=true;C=true end end end end;if u and x and w then for l=1,#n[GEA.keys["PARAMS"]]do local y=n[GEA.keys["PARAMS"]][l]if type(y)=="table"and string.lower(y[1])=="time"then v=false;if GEA.checkTime(n,GEA.flatTime(y[2]).."-"..GEA.flatTime(y[3]))then return true end end end else if not u then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY"].." "..os.date("%A").." "..GEA.translate[GEA.language]["NOT_INCLUDED"].." "..jours,false,"yellow")elseif not x then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY_NOT_DST"],false,"yellow")elseif not w then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY"].." "..os.date("%x").." "..GEA.translate[GEA.language]["DATE_NOT_ALLOWED"],false,"yellow")end end;if not v then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["CURRENT_TIME"].." "..os.date("%H:%M").." "..GEA.translate[GEA.language]["TIME_NOT_ALLOWED"],false,"yellow")end;return v and w and u and x end;GEA.flatTime=function(time)local D=string.lower(time)D=string.gsub(D," ","")D=string.gsub(D,"h",":")D=string.gsub(D,"sunset",fibaro:getValue(1,"sunsetHour"))D=string.gsub(D,"sunrise",fibaro:getValue(1,"sunriseHour"))if string.find(D,"<")then D=GEA.flatTime(GEA.split(D,"<")[1]).."<"..GEA.flatTime(GEA.split(D,"<")[2])end;if string.find(D,">")then D=GEA.flatTime(GEA.split(D,">")[1])..">"..GEA.flatTime(GEA.split(D,">")[2])end;if string.find(D,"+")then local time=GEA.split(D,"+")[1]local add=GEA.split(D,"+")[2]local E=os.date("*t")local F=GEA.split(time,":")[2]local G=os.time{year=E.year,month=E.month,day=E.day,hour=tonumber(GEA.split(time,":")[1]),min=tonumber(GEA.split(time,":")[2]),sec=0}G=G+add*60;D=os.date("*t",G)D=string.format("%02d",D.hour)..":"..string.format("%02d",D.min)elseif string.find(D,"-")then local time=GEA.split(D,"-")[1]local add=GEA.split(D,"-")[2]local E=os.date("*t")local G=os.time{year=E.year,month=E.month,day=E.day,hour=tonumber(GEA.split(time,":")[1]),min=tonumber(GEA.split(time,":")[2]),sec=0}G=G-add*60;D=os.date("*t",G)D=string.format("%02d",D.hour)..":"..string.format("%02d",D.min)elseif string.find(D,"<")then local H=GEA.split(D,"<")[1]local I=GEA.split(D,"<")[2]H=string.format("%02d",GEA.split(H,":")[1])..":"..string.format("%02d",GEA.split(H,":")[2])I=string.format("%02d",GEA.split(I,":")[1])..":"..string.format("%02d",GEA.split(I,":")[2])if H")then local H=GEA.split(D,">")[1]local I=GEA.split(D,">")[2]H=string.format("%02d",GEA.split(H,":")[1])..":"..string.format("%02d",GEA.split(H,":")[2])I=string.format("%02d",GEA.split(I,":")[1])..":"..string.format("%02d",GEA.split(I,":")[2])if H>I then D=H else D=I end else D=string.format("%02d",GEA.split(D,":")[1])..":"..string.format("%02d",GEA.split(D,":")[2])end;return D end;GEA.checkTime=function(n,J)GEA.log("CheckTime",n,GEA.translate[GEA.language]["CHECKING_TIME"].." "..J,false)if not J or J==""then return true end;local A=string.sub(J,1,5)local B=string.sub(J,7,11)local z=os.date("%H:%M")local K=false;if B=A or z<=B else K=z>=A and z<=B end;if not K then GEA.log("CheckTime",n,GEA.translate[GEA.language]["TIME_OUT"]..J,false,"yellow")else GEA.log("CheckTime",n,GEA.translate[GEA.language]["TIME_IN"]..J,false)end;return K end;GEA.split=function(L,M)local M,N=M or":",{}local O=string.format("([^%s]+)",M)L:gsub(O,function(P)N[#N+1]=P end)return N end;GEA.trim=function(Q)return Q:gsub("^%s*(.-)%s*$","%1")end;GEA.match=function(Q,R)if type(Q)=="nil"then return type(R)=="nil"end;Q=tostring(Q)R=tostring(R):gsub("%%","%%%%"):gsub("-","%%-")local S=GEA.split(R,"|")for l=1,#S do if not GEA.regexFullAllow then S[l]="^"..S[l].."$"end;if string.match(Q,GEA.trim(S[l]))then return true end end;return false end;GEA.check=function(n,index)GEA.log("Check",n,GEA.translate[GEA.language]["CHECK_STARTED"],false)if GEA.isTask("R",n[GEA.keys["INDEX"]])~=nil then GEA.log("Check",n,GEA.translate[GEA.language]["RESTART"],true)n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false;GEA.addOrRemoveTask("R",n[GEA.keys["INDEX"]],false)GEA.addOrRemoveTask("S",n[GEA.keys["INDEX"]],false)end;if GEA.isTask("S",n[GEA.keys["INDEX"]])~=nil then GEA.log("Check",n,GEA.translate[GEA.language]["SUPSENDED"],true)return end;if not n[GEA.keys["DONE"]]then n[GEA.keys["OK"]]=false end;if GEA.checkTimes(n)then if GEA.isActivated(n,1,n)then if n[GEA.keys["SECONDES"]]<0 then local T=GEA.isTask("M",n[GEA.keys["INDEX"]].."{(%d+)}")if T~=nil then n[GEA.keys["TOTALRUNS"]]=tonumber(T)GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{(%d+)}",false)end end;if n[GEA.keys["NBRUN"]]then n[GEA.keys["NBRUN"]]=n[GEA.keys["NBRUN"]]+1;n[GEA.keys["TOTALRUNS"]]=n[GEA.keys["TOTALRUNS"]]+1 else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0 end;if not n[GEA.keys["DONE"]]then GEA.log("Check",n,GEA.translate[GEA.language]["ACTIVATED_SINCE"]..n[GEA.keys["TOTALRUNS"]]*GEA.checkEvery.."/"..n[GEA.keys["SECONDES"]],false)end;if n[GEA.keys["SECONDES"]]<0 and n[GEA.keys["MAXTIME"]]==-1 or n[GEA.keys["TOTALRUNS"]]-1-1 then GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{(%d+)}",false)if n[GEA.keys["TOTALRUNS"]]>=n[GEA.keys["MAXTIME"]]then GEA.addOrRemoveTask("S",n[GEA.keys["INDEX"]],true)else GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{"..n[GEA.keys["TOTALRUNS"]].."}",true)end end else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false end;if GEA.source["type"]=="autostart"and n[GEA.keys["NBRUN"]]*GEA.checkEvery>=n[GEA.keys["SECONDES"]]and not n[GEA.keys["DONE"]]and n[GEA.keys["MAXTIME"]]==-1 or n[GEA.keys["TOTALRUNS"]]-1=n[GEA.keys["MAXTIME"]]then GEA.log("Done",n,GEA.translate[GEA.language]["DONE"],true,"DarkSlateBlue")n[GEA.keys["DONE"]]=true end;n[GEA.keys["NBRUN"]]=0 end else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false end end;GEA.isActivated=function(n,U,V)if U==1 then GEA.log("isActivated",n,GEA.translate[GEA.language]["CHECK_MAIN"],false)else GEA.log("isActivated",n,GEA.translate[GEA.language]["CHECK_IF"],false)end;local W=-1;local a=n[GEA.keys["ID"]]local X=true;local Y=type(a)if Y=="nil"then X=true;V[GEA.keys["VALUE"]][U]="true"elseif Y=="boolean"then X=a;if X then V[GEA.keys["VALUE"]][U]="true"else V[GEA.keys["VALUE"]][U]="false"end elseif Y=="number"then local type=fibaro:getType(tonumber(a))GEA.log("isActivated",n,"type : "..type,false)if GEA.match(type,"door_sensor|water_sensor|motion_sensor|com.fibaro.FGMS001|com.fibaro.doorSensor|com.fibaro.waterSensor|com.fibaro.motionSensor")then X=tonumber(fibaro:getValue(tonumber(a),"value"))>=1;if not X and GEA.source["type"]=="autostart"and fibaro:getValue(tonumber(a),"lastBreached")~=""then X=os.time()-tonumber(fibaro:getValue(tonumber(a),"lastBreached"))0 or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 elseif GEA.match(type,"com.fibaro.FGRGBW441M")then X=tonumber(fibaro:getValue(tonumber(a),"value"))>0 and not fibaro:getValue(tonumber(a),"color")=="0,0,0,0"or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 else X=tonumber(fibaro:getValue(tonumber(a),"value"))>0 end;if not X and GEA.source["type"]=="autostart"and fibaro:getModificationTime(tonumber(a),"value")then X=os.time()-tonumber(fibaro:getModificationTime(tonumber(a),"value"))0 else X=tonumber(fibaro:getValue(tonumber(a),"value"))==1 end;W=tonumber(a)V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a),"value")elseif Y=="table"then local Z=string.lower(a[1])if Z=="global"and#a>2 then GEA.log("isActivated",n,"type : global variable",false)X=GEA.match(fibaro:getGlobalValue(a[2]),a[3])V[GEA.keys["VALUE"]][U]=fibaro:getGlobalValue(a[2])elseif Z=="global+"and#a>2 then GEA.log("isActivated",n,"type : Global+",false)X=tonumber(fibaro:getGlobalValue(a[2]))>tonumber(a[3])V[GEA.keys["VALUE"]][U]=fibaro:getGlobalValue(a[2])elseif Z=="global-"and#a>2 then GEA.log("isActivated",n,"type : Global-",false)X=tonumber(fibaro:getGlobalValue(a[2]))2 then GEA.log("isActivated",n,"type : Global!",false)X=not GEA.match(fibaro:getGlobalValue(a[2]),a[3])V[GEA.keys["VALUE"]][U]=fibaro:getGlobalValue(a[2])elseif Z=="slider"and#a>3 then GEA.log("isActivated",n,"type : Slider",false)X=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))==tonumber(a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif Z=="slider-"and#a>3 then GEA.log("isActivated",n,"type : Slider-",false)X=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))3 then GEA.log("isActivated",n,"type : Slider!",false)X=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))~=tonumber(a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif Z=="slider+"and#a>3 then GEA.log("isActivated",n,"type : Slider+",false)X=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))>tonumber(a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif Z=="label"and#a>3 then GEA.log("isActivated",n,"type : Label",false)X=GEA.match(fibaro:getValue(a[2],"ui."..a[3]..".value"),a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif Z=="label!"and#a>3 then GEA.log("isActivated",n,"type : Label!",false)X=not GEA.match(fibaro:getValue(a[2],"ui."..a[3]..".value"),a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif Z=="property"and#a>3 then GEA.log("isActivated",n,"type : Property",false)X=GEA.match(fibaro:getValue(a[2],a[3]),a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],a[3])elseif Z=="property!"and#a>3 then GEA.log("isActivated",n,"type : Property",false)X=not GEA.match(fibaro:getValue(a[2],a[3]),a[4])V[GEA.keys["VALUE"]][U]=fibaro:getValue(a[2],a[3])elseif Z=="batteries"and#a>1 then GEA.log("isActivated",n,"type : batteries",false)local _=""for l=1,1000 do local a0=fibaro:getValue(l,'batteryLevel')if type(a0)~=nil and tonumber(a0)~=nil and tonumber(a0)<=tonumber(a[2])or tonumber(a0)==255 then GEA.log("isActivated",n,"checking : batteries "..fibaro:getName(l),false)if not string.find(fibaro:getName(l),"Zwave_")then _=_..GEA.translate[GEA.language]["BATTERIE"].." ["..fibaro:getName(l).."] "..a0 .."%\n"X=true end end end;V[GEA.keys["VALUE"]][U]=a[2]n[GEA.keys["MESSAGE"]]=_ elseif(Z=="sensor"or Z=="power")and#a>2 then GEA.log("isActivated",n,"type : Sensor",false)X=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))==tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif(Z=="sensor+"or Z=="power+")and#a>2 then GEA.log("isActivated",n,"type : Sensor+",false)X=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))>tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif(Z=="sensor-"or Z=="power-")and#a>2 then GEA.log("isActivated",n,"type : Sensor-",false)X=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))2 then GEA.log("isActivated",n,"type : Sensor!",false)X=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))~=tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif Z=="battery"and#a>2 then GEA.log("isActivated",n,"type : Battery",false)X=false;local a0=fibaro:getValue(tonumber(a[2]),'batteryLevel')if type(a0)~=nil and tonumber(a0)<=tonumber(a[3])or tonumber(a0)==255 then X=true;V[GEA.keys["VALUE"]][U]=a0 end;W=tonumber(a[2])elseif Z=="value"and#a>2 then GEA.log("isActivated",n,"type : Value",false)X=tonumber(fibaro:getValue(tonumber(a[2]),"value"))==tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),"value")elseif Z=="value+"and#a>2 then GEA.log("isActivated",n,"type : Value+",false)X=tonumber(fibaro:getValue(tonumber(a[2]),"value"))>tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),"value")elseif Z=="value-"and#a>2 then GEA.log("isActivated",n,"type : Value-",false)X=tonumber(fibaro:getValue(tonumber(a[2]),"value"))2 then GEA.log("isActivated",n,"type : Value!",false)X=tonumber(fibaro:getValue(tonumber(a[2]),"value"))~=tonumber(a[3])W=tonumber(a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),"value")elseif Z=="dead"and#a>1 then GEA.log("isActivated",n,"type : isDead",false)X=tonumber(fibaro:getValue(tonumber(a[2]),"dead"))>=1;V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),"dead")elseif Z=="weather"and#a>1 then GEA.log("isActivated",n,"type : weather",false)X=GEA.match(fibaro:getValue(3,"WeatherConditionConverted"),a[2])V[GEA.keys["VALUE"]][U]=fibaro:getValue(3,"WeatherConditionConverted")elseif Z=="function"and#a>1 then GEA.log("isActivated",n,"type : Function",false)local a1,a2,a3=pcall(a[2])if a1 then X=a2;if a3 then V[GEA.keys["VALUE"]][U]=a3 end else X=false end elseif Z=="group"and#a>1 then GEA.log("isActivated",n,"type : Group",false)for l=1,#GEA.todo do if GEA.todo[l][GEA.keys["GROUPS"]][tonumber(a[2])]then if not GEA.todo[l][GEA.keys["OK"]]then X=false end end end;V[GEA.keys["VALUE"]][U]=fibaro:getValue(tonumber(a[2]),"")elseif Z=="alarm"then GEA.log("isActivated",n,"type : alarm",false)local time=fibaro:getValue(tonumber(a[2]),"ui.lblAlarme.value")if not(type(time)=="nil"or time==""or time=="--:--")then X=GEA.checkTime(n,GEA.flatTime(time).."-"..GEA.flatTime(time))if X then local jours=fibaro:getValue(tonumber(a[2]),"ui.lblJours.value")local t=""if string.find(jours,"Lu")or string.find(jours,"Mo")then t=t.."Monday"end;if string.find(jours,"Ma")or string.find(jours,"Tu")then t=t.."Tuesday"end;if string.find(jours,"Me")or string.find(jours,"We")then t=t.."Wednesday"end;if string.find(jours,"Je")or string.find(jours,"Th")then t=t.."Thursday"end;if string.find(jours,"Ve")or string.find(jours,"Fr")then t=t.."Friday"end;if string.find(jours,"Sa")or string.find(jours,"Sa")then t=t.."Saturday"end;if string.find(jours,"Di")or string.find(jours,"Su")then t=t.."Sunday"end;X=GEA.checkDay(t)end;V[GEA.keys["VALUE"]][U]=time else X=false end end else end;if U==1 then for l=1,#n[GEA.keys["PARAMS"]]do if string.lower(n[GEA.keys["PARAMS"]][l][1])=="inverse"then X=not X end end;if W>-1 and type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local y=n[GEA.keys["PARAMS"]][l]if string.lower(y[1])=="armed"then X=X and tonumber(fibaro:getValue(W,"armed"))>0;if#y>1 then X=X and tonumber(fibaro:getValue(y[2],"armed"))>0 end elseif string.lower(y[1])=="disarmed"then X=X and tonumber(fibaro:getValue(W,"armed"))==0;if#y>1 then X=X and tonumber(fibaro:getValue(y[2],"armed"))==0 end end end end;if X then for l=1,#n[GEA.keys["PARAMS"]]do local y=n[GEA.keys["PARAMS"]][l]if type(y)=="table"and string.lower(y[1])=="if"then local a4=true;for a5=1,#y[2]do if type(y[2])=="table"then if not GEA.isActivated({y[2][a5]},a5+1,n)then a4=false;GEA.log("!CANCEL! isActivated",n,GEA.translate[GEA.language]["CHECK_IF_FAILED"],false,"yellow")end else GEA.log(GEA.translate[GEA.language]["ERROR"],n,GEA.translate[GEA.language]["ERROR_IF"],true,"red")end end;X=a4 end end end end;if X then GEA.log("isActivated",n,GEA.translate[GEA.language]["ACTIVATED"],false)else GEA.log("!CANCEL! isActivated",n,GEA.translate[GEA.language]["DESACTIVATED"],false,"yellow")end;return X end;GEA.getMessage=function(n,c)local _=""if n[GEA.keys["MESSAGE"]]then _=n[GEA.keys["MESSAGE"]]end;if c and c~=""then _=c end;if n[GEA.keys["VALUE"]][1]then _=string.gsub(_,"#value#",n[GEA.keys["VALUE"]][1])_=string.gsub(_,"#value%[1%]#",n[GEA.keys["VALUE"]][1])end;if n[GEA.keys["VALUE"]][2]then _=string.gsub(_,"#value%[2%]#",n[GEA.keys["VALUE"]][2])end;if n[GEA.keys["VALUE"]][3]then _=string.gsub(_,"#value%[3%]#",n[GEA.keys["VALUE"]][3])end;if n[GEA.keys["VALUE"]][4]then _=string.gsub(_,"#value%[4%]#",n[GEA.keys["VALUE"]][4])end;if n[GEA.keys["VALUE"]][5]then _=string.gsub(_,"#value%[5%]#",n[GEA.keys["VALUE"]][5])end;if n[GEA.keys["VALUE"]][6]then _=string.gsub(_,"#value%[6%]#",n[GEA.keys["VALUE"]][6])end;if n[GEA.keys["VALUE"]][7]then _=string.gsub(_,"#value%[7%]#",n[GEA.keys["VALUE"]][7])end;if n[GEA.keys["VALUE"]][8]then _=string.gsub(_,"#value%[8%]#",n[GEA.keys["VALUE"]][8])end;if n[GEA.keys["VALUE"]][9]then _=string.gsub(_,"#value%[9%]#",n[GEA.keys["VALUE"]][9])end;_=string.gsub(_,"#time#",os.date("%X"))_=string.gsub(_,"#date#",os.date("%x"))if n[GEA.keys["NAME"]][1]then _=string.gsub(_,"#name#",n[GEA.keys["NAME"]][1])_=string.gsub(_,"#name%[1%]#",n[GEA.keys["NAME"]][1])end;if n[GEA.keys["NAME"]][2]then _=string.gsub(_,"#name%[2%]#",n[GEA.keys["NAME"]][2])end;if n[GEA.keys["NAME"]][3]then _=string.gsub(_,"#name%[3%]#",n[GEA.keys["NAME"]][3])end;if n[GEA.keys["NAME"]][4]then _=string.gsub(_,"#name%[4%]#",n[GEA.keys["NAME"]][4])end;if n[GEA.keys["NAME"]][5]then _=string.gsub(_,"#name%[5%]#",n[GEA.keys["NAME"]][5])end;if n[GEA.keys["NAME"]][6]then _=string.gsub(_,"#name%[6%]#",n[GEA.keys["NAME"]][6])end;if n[GEA.keys["NAME"]][7]then _=string.gsub(_,"#name%[7%]#",n[GEA.keys["NAME"]][7])end;if n[GEA.keys["NAME"]][8]then _=string.gsub(_,"#name%[8%]#",n[GEA.keys["NAME"]][8])end;if n[GEA.keys["NAME"]][9]then _=string.gsub(_,"#name%[9%]#",n[GEA.keys["NAME"]][9])end;if n[GEA.keys["ROOM"]][1]then _=string.gsub(_,"#room#",n[GEA.keys["ROOM"]][1])_=string.gsub(_,"#room%[1%]#",n[GEA.keys["ROOM"]][1])end;if n[GEA.keys["ROOM"]][2]then _=string.gsub(_,"#room%[2%]#",n[GEA.keys["ROOM"]][2])end;if n[GEA.keys["ROOM"]][3]then _=string.gsub(_,"#room%[3%]#",n[GEA.keys["ROOM"]][3])end;if n[GEA.keys["ROOM"]][4]then _=string.gsub(_,"#room%[4%]#",n[GEA.keys["ROOM"]][4])end;if n[GEA.keys["ROOM"]][5]then _=string.gsub(_,"#room%[5%]#",n[GEA.keys["ROOM"]][5])end;if n[GEA.keys["ROOM"]][6]then _=string.gsub(_,"#room%[6%]#",n[GEA.keys["ROOM"]][6])end;if n[GEA.keys["ROOM"]][7]then _=string.gsub(_,"#room%[7%]#",n[GEA.keys["ROOM"]][7])end;if n[GEA.keys["ROOM"]][8]then _=string.gsub(_,"#room%[8%]#",n[GEA.keys["ROOM"]][8])end;if n[GEA.keys["ROOM"]][9]then _=string.gsub(_,"#room%[9%]#",n[GEA.keys["ROOM"]][9])end;_=string.gsub(_,"#seconds#",n[GEA.keys["SECONDES"]])local a6=GEA.getDureeInString(n[GEA.keys["TOTALRUNS"]]*GEA.checkEvery)_=string.gsub(_,"#duration#",a6[1])_=string.gsub(_,"#durationfull#",a6[2])_=string.gsub(_,"#runs#",n[GEA.keys["TOTALRUNS"]])return _ end;GEA.getDureeInString=function(a7)local a7=a7;local a8=""nHours=math.floor(a7/3600)nMins=math.floor(a7/60-nHours*60)nSecs=math.floor(a7-nHours*3600-nMins*60)a7=""if nHours>0 then a7=a7 ..nHours.."h "a8=a8 ..nHours;if nHours>1 then a8=a8 .." "..GEA.translate[GEA.language]["HOURS"]else a8=a8 .." "..GEA.translate[GEA.language]["HOUR"]end end;if nMins>0 then a7=a7 ..nMins.."m "if nHours>0 then a8=a8 .." "end;if nSecs==0 and nHours>0 then a8=a8 .."et "end;a8=a8 ..nMins;if nMins>1 then a8=a8 .." "..GEA.translate[GEA.language]["MINUTES"]else a8=a8 .." "..GEA.translate[GEA.language]["MINUTE"]end end;if nSecs>0 then a7=a7 ..nSecs.."s"if nMins>0 then a8=a8 .." et "end;a8=a8 ..nSecs;if nSecs>1 then a8=a8 .." "..GEA.translate[GEA.language]["SECONDS"]else a8=a8 .." "..GEA.translate[GEA.language]["SECOND"]end end;return{a7,a8}end;GEA.sendActions=function(n)GEA.log("sendActions",n,GEA.translate[GEA.language]["ACTIONS"],true)local a9=false;if type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local aa=n[GEA.keys["PARAMS"]][l]if type(aa)=="table"then local Z=string.lower(aa[1])if Z=="turnoff"or Z=="turnon"or Z=="switch"then local a=GEA.getId(n,aa)if a>0 then local ab=fibaro:getValue(tonumber(a),"value")local ac=fibaro:getType(tonumber(a))if GEA.match(ac,"rgb_driver")and tonumber(fibaro:getValue(tonumber(a),"value"))>0 or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 then ab=1 elseif GEA.match(ac,"com.fibaro.FGRGBW441M")then if fibaro:getValue(tonumber(a),"color")~="0,0,0,0"or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 then ab=1 end end;if tonumber(ab)>=1 and Z=="turnoff"or tonumber(ab)==0 and Z=="turnon"then fibaro:call(tonumber(a),aa[1])elseif Z=="switch"then local ad="turnOff"if tonumber(ab)==0 then ad="turnOn"end;fibaro:call(tonumber(a),ad)end;GEA.log("sendActions",n,"!ACTION! : "..aa[1],true)end end;if Z=="global"and#aa>2 then local a3=string.match(aa[3],"(%d+)")if GEA.match(aa[3],"inc%+")then local ae=tonumber(fibaro:getGlobalValue(aa[2]))if type(a3)~="nil"then fibaro:setGlobal(aa[2],ae+a3)else fibaro:setGlobal(aa[2],ae+1)end elseif GEA.match(aa[3],"dec%-")then local ae=tonumber(fibaro:getGlobalValue(aa[2]))if type(a3)~="nil"then fibaro:setGlobal(aa[2],ae-a3)else fibaro:setGlobal(aa[2],ae-1)end else fibaro:setGlobal(aa[2],GEA.getMessage(n,aa[3]))end;GEA.log("sendActions",n,"!ACTION! : setGlobal "..aa[2]..","..GEA.getMessage(n,aa[3]),true)elseif Z=="portable"and#aa>1 then fibaro:call(tonumber(aa[2]),"sendPush",GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : pushed to "..aa[2],true)a9=true elseif Z=="email"and#aa>1 then local af="GEA Notification"if#aa>2 then af=aa[3]end;fibaro:call(tonumber(aa[2]),"sendEmail",GEA.getMessage(n,af),GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : email to "..aa[2],true)elseif Z=="picture"and#aa>2 then local ag=tonumber(aa[3])local ah=tonumber(aa[2])fibaro:call(ah,"sendPhotoToUser",ag)GEA.log("sendActions",n,"!ACTION! : email picture from camera "..ah.." to "..ag,true)elseif Z=="scenario"and#aa>1 then fibaro:startScene(aa[2])GEA.log("sendActions",n,"!ACTION! : Scene "..aa[2],true)elseif Z=="stopscenario"and#aa>1 then if fibaro:countScenes(aa[2])then fibaro:killScene(aa[2])GEA.log("sendActions",n,"!ACTION! : Stop Scene "..aa[2],true)else GEA.log("sendActions",n,"!ACTION! : No Stop Scene "..aa[2],true)end elseif Z=="enablescenario"and#aa>1 then fibaro:setSceneEnabled(aa[2],true)GEA.log("sendActions",n,"!ACTION! : Scene enabled "..aa[2],true)elseif Z=="disablescenario"and#aa>1 then fibaro:setSceneEnabled(aa[2],false)GEA.log("sendActions",n,"!ACTION! : Scene disabled "..aa[2],true)elseif Z=="function"then local a1,a2=pcall(aa[2])if a1 then GEA.log("sendActions",n,"!ACTION! : Function OK",true)else GEA.log("sendActions",n,"!ACTION! : Function "..tostring(a2 or"Inconnu."),true)end elseif Z=="setarmed"and#aa>1 then fibaro:call(aa[2],"setArmed",1)GEA.log("sendActions",n,"!ACTION! : setArmed "..aa[2],true)elseif Z=="setdisarmed"and#aa>1 then fibaro:call(aa[2],"setArmed",0)GEA.log("sendActions",n,"!ACTION! : setDisarmed "..aa[2],true)elseif Z=="currenticon"and#aa>2 then fibaro:call(aa[2],"setProperty","currentIcon",tostring(aa[3]))GEA.log("sendActions",n,"!ACTION! : CurrentIcon "..aa[2],true)elseif Z=="copyglobal"and#aa>2 then fibaro:setGlobal(aa[3],fibaro:getGlobalValue(aa[2]))GEA.log("sendActions",n,"!ACTION! : CopyGlobal "..aa[2],true)elseif Z=="restarttask"and#aa>1 then GEA.addOrRemoveTask("R",aa[2],true)GEA.log("sendActions",n,"!ACTION! : Restart "..aa[2],true)elseif Z=="stoptask"and#aa>1 then GEA.addOrRemoveTask("S",aa[2],true)GEA.log("sendActions",n,"!ACTION! : StopTask "..aa[2],true)elseif Z=="wakeup"and#aa>1 then fibaro:wakeUpDeadDevice(aa[2])GEA.log("sendActions",n,"!ACTION! : WakeUp "..aa[2],true)elseif Z=="virtualdevice"and#aa>2 then fibaro:call(aa[2],"pressButton",tostring(aa[3]))GEA.log("sendActions",n,"!ACTION! : VirtualDevice "..aa[2]..","..aa[3],true)elseif Z=="slider"and#aa>3 then fibaro:call(aa[2],"setSlider",aa[3],aa[4])GEA.log("sendActions",n,"!ACTION! : Slider "..aa[2]..","..aa[3].."="..aa[4],true)elseif Z=="label"and#aa>3 then fibaro:call(aa[2],"setProperty","ui."..aa[3]..".value",GEA.getMessage(n,aa[4]))GEA.log("sendActions",n,"!ACTION! : Label "..aa[2]..","..aa[3].." = "..GEA.getMessage(n,aa[4]),true)elseif Z=="rgb"and#aa>5 then if aa[3]==-1 or aa[4]==-1 or aa[5]==-1 or aa[6]==-1 then if aa[3]~=-1 then fibaro:call(aa[2],"setR",aa[3])end;if aa[4]~=-1 then fibaro:call(aa[2],"setG",aa[4])end;if aa[5]~=-1 then fibaro:call(aa[2],"setB",aa[5])end;if aa[6]~=-1 then fibaro:call(aa[2],"setW",aa[6])end else fibaro:call(aa[2],"setColor",aa[3],aa[4],aa[5],aa[6])end;GEA.log("sendActions",n,"!ACTION! : RGB "..aa[2]..", Color = "..aa[3]..","..aa[4]..","..aa[5]..","..aa[6])elseif Z=="program"and#aa>2 then if tonumber(fibaro:getValue(tonumber(aa[2]),"currentProgramID"))~=tonumber(aa[3])then fibaro:call(aa[2],"startProgram",aa[3])end;GEA.log("sendActions",n,"!ACTION! : startProgram "..aa[2]..", program = "..aa[3])elseif Z=="value"then local a=GEA.getId(n,aa)if a>0 then if#aa>2 then fibaro:call(a,"setValue",aa[3])GEA.log("sendActions",n,"!ACTION! : setValue "..aa[3],true)else fibaro:call(a,"setValue",aa[2])GEA.log("sendActions",n,"!ACTION! : setValue "..aa[2],true)end end elseif Z=="open"or Z=="close"then local a=GEA.getId(n,aa)if a>0 then local ai=100;if#aa>2 then if Z=="close"then ai=ai-aa[3]else ai=aa[3]end;fibaro:call(a,"setValue",ai)GEA.log("sendActions",n,"!ACTION! : setValue "..ai,true)elseif#aa>1 then if Z=="close"then ai=ai-aa[2]else ai=aa[2]end;fibaro:call(a,"setValue",ai)GEA.log("sendActions",n,"!ACTION! : setValue "..ai,true)else fibaro:call(a,aa[1])GEA.log("sendActions",n,"!ACTION! : "..aa[1],true)end end end end end end;if n[GEA.keys["MESSAGE"]]~=""and not a9 then if n[GEA.keys["MESSAGE"]]=="debug"then fibaro:debug("=============="..os.time().."=====================")else for l=1,#GEA.portables do fibaro:call(tonumber(GEA.portables[l]),"sendPush",GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : sendPush "..GEA.getMessage(n,nil),true)end end end end;GEA.getId=function(n,aj)local a=0;if aj and type(aj)=="table"and#aj>1 and string.lower(aj[1])=="turnoff"or string.lower(aj[1])=="turnon"or string.lower(aj[1])=="switch"then a=tonumber(aj[2])elseif aj and type(aj)=="table"and#aj>2 and string.lower(aj[1])=="value"or string.lower(aj[1])=="open"or string.lower(aj[1])=="close"then a=tonumber(aj[2])elseif type(n[GEA.keys["ID"]])=="number"then a=n[GEA.keys["ID"]]elseif type(n[GEA.keys["ID"]])=="table"and string.lower(n[GEA.keys["ID"]][1])=="sensor+"or string.lower(n[GEA.keys["ID"]][1])=="sensor-"or string.lower(n[GEA.keys["ID"]][1])=="value-"or string.lower(n[GEA.keys["ID"]][1])=="value+"or string.lower(n[GEA.keys["ID"]][1])=="dead"then a=tonumber(n[GEA.keys["ID"]][2])end;if a==0 then fibaro:debug(GEA.translate[GEA.language]["DEVICE_NOT_FOUND"])end;return a end;GEA.pause=function()local ak=true;if#GEA.getGlobalForActivation>0 then ak=false;if fibaro:getGlobalValue(GEA.getGlobalForActivation[1])==GEA.getGlobalForActivation[2]then ak=true else GEA.log("Run",nil,GEA.translate[GEA.language]["GEA_SUSPENDED"].." "..GEA.getGlobalForActivation[1].." "..GEA.translate[GEA.language]["VALUE"].." "..fibaro:getGlobalValue(GEA.getGlobalForActivation[1]).." "..GEA.translate[GEA.language]["REQUIRED"].." "..GEA.getGlobalForActivation[2],true)end end;return not ak end;GEA.run=function()if config then config()end;if setEvents then setEvents()end;if GEA.isVersionFour then GEA.power="power"end;GEA.log("GEA Version "..GEA.version,nil," "..GEA.translate[GEA.language]["RUNNING"].."...",true,"green")if#GEA.todo==0 then if GEA.source["type"]~="property"then GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["NOTHING_TODO"],true)else GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["NOTHING_TODOID"]..GEA.source["deviceID"],true)end;return false end;local al=#GEA.todo;if GEA.source["type"]=="autostart"then if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,GEA.suspended)else GEA.tasks=GEA.suspended end;local am=GEA.checkEvery;local an=1;local ao=true;local ap=os.time()while true do GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["SLEEPING"].." "..GEA.checkEvery.." "..GEA.translate[GEA.language]["SECONDS"],false)fibaro:sleep(am*1000)local aq=os.time()local ar=GEA.checkAllToDo(al)local as=ar-aq;if ao then as=as*2;ao=false end;am=GEA.checkEvery-as;if an>=20 then local _=GEA.translate[GEA.language]["RUN_FOR"]..as.."s "..GEA.translate[GEA.language]["RUN_NEW"]..am.."s / "..GEA.translate[GEA.language]["RUN_SINCE"].." "..GEA.getDureeInString(os.time()-ap)[1]fibaro:debug("".._.."")an=0 end;an=an+1 end else GEA.checkAllToDo(al)end end;GEA.checkAllToDo=function(al)if not GEA.pause()then for l=1,al do GEA.log(GEA.translate[GEA.language]["RUN"],GEA.todo[l],GEA.translate[GEA.language]["CHECKING"],false)if GEA.catchError then if not pcall(function()GEA.check(GEA.todo[l],l)end)then GEA.log(GEA.translate[GEA.language]["ERROR"],GEA.todo[l],GEA.translate[GEA.language]["CHECKING"],true,red)end else GEA.check(GEA.todo[l],l)end end end;return os.time()end;GEA.log=function(at,n,c,au,av)if au or GEA.debug then local _=""local j="If"if not n and not au then return elseif n then local aw=type(n[GEA.keys["ID"]])if n[GEA.keys["NAME"]]then j=n[GEA.keys["NAME"]]if type(j)=="table"then j=j[1]end;j=j.." ] "if aw=="nil"or aw=="boolean"then _=_.."[ "..j elseif aw=="number"then _=_.."[ "..n[GEA.keys["ID"]].." | "..j elseif aw=="table"then lowerId=string.lower(n[GEA.keys["ID"]][1])if GEA.match(lowerId,"global|global.")then _=_.."[ "..n[GEA.keys["ID"]][2].."="..n[GEA.keys["ID"]][3].." ] "elseif lowerId=="batteries"then _=_.."[ "..n[GEA.keys["ID"]][2].." ] "elseif lowerId=="group"then _=_.."[ "..j elseif GEA.match(lowerId,"sensor|sensor.|value|value.|dead|sceneactivation|battery")then _=_.."[ "..j elseif GEA.match(lowerId,"slider|slider.|label|label.|property|property.")then _=_.."[ "..j elseif lowerId=="weather"then _=_.."[ Weather ] "elseif lowerId=="function"then _=_.."[ Function ] "elseif lowerId=="alarm"then _=_.."Alarm "..fibaro:getValue(tonumber(n[GEA.keys["ID"]][2]),"ui.lblAlarme.value")else end end end end;if at and at~=""then _=_..string.format("%-20s",at)..": "end;if c and c~=""then _=_..string.format("%-20s",c)end;if n then if n[GEA.keys["INDEX"]]then _=_.." (ID: "..n[GEA.keys["INDEX"]]..")"end;if n[GEA.keys["PARAMS"]]and type(n[GEA.keys["PARAMS"]])=="table"and#n[GEA.keys["PARAMS"]]>0 then for l=1,#n[GEA.keys["PARAMS"]]do _=_.." ["local ax=n[GEA.keys["PARAMS"]][l]if type(ax)=="table"then for a5=1,#ax do if string.lower(ax[1])=="if"then if a5==1 then _=_.."If..."end elseif string.lower(ax[1])=="function"then if a5==1 then _=_.."Function..."end else _=_..ax[a5]..","end end end;_=_:sub(1,_:len()-1).."]"end end end;fibaro:debug("".._.."")end end end;GEA.run() \ No newline at end of file +if not GEA then GEA={}GEA.version="5.40"GEA.language="FR"GEA.checkEvery=30;GEA.index=0;GEA.isVersionFour=true;GEA.globalTasks="GEA_Tasks"GEA.regexFullAllow=false;GEA.portables={}GEA.todo={}GEA.power="valueSensor"GEA.suspended=""GEA.keys={ID=1,SECONDES=2,MESSAGE=3,ISREPEAT=4,PARAMS=5,NAME=6,NBRUN=7,DONE=8,VALUE=9,GROUPS=10,OK=11,TOTALRUNS=12,INDEX=13,MAXTIME=14,ROOM=15}GEA.debug=false;GEA.catchError=true;GEA.pos=1;GEA.useTasksGlobal=true;GEA.tasks=""GEA.typeOptimize={NONE=0,IMMEDIATE_ONLY=1,ALL=2}GEA.optimize=GEA.typeOptimize["NONE"]GEA.getGlobalForActivation={}GEA.source=fibaro:getSourceTrigger()GEA.translate={true,true}GEA.translate["FR"]={ACTIONS="traitement des actions",ACTIVATED="activé",ACTIVATED_SINCE="activé depuis ",ADDED_DIRECT="ajout de la tâche pour lancement instantané",ADDED_FOR="ajout de la tâche pour",ALWAYS="Toujours",BATTERIE="Pile faible",CHECKING="vérification",CHECKING_DATE="vérification des dates",CHECKING_TIME="vérification plage horaire",CHECK_IF="vérification de l'exception",CHECK_IF_FAILED="désactivé par exception",CHECK_MAIN="vérification de l'activation",CHECK_STARTED="démarrage vérification",CURRENT_TIME="L'heure actuelle",DATE_NOT_ALLOWED="n'est pas dans la plage de dates spécifiées",DESACTIVATED="désactivé",DEVICE_NOT_FOUND="ID non trouvé",DONE="tâche effectuée et suspendue",ERROR="!!! ERREUR !!!",ERROR_IF="IF malformé",GEA_SUSPENDED="Scénario suspendu par la variable globale ",HOUR="heure",HOURS="heures",MINUTE="minute",MINUTES="minutes",NOTHING_TODO="aucun traitement à effectuer",NOTHING_TODOID="aucun traitement à effectuer pour l'ID :",NOT_INCLUDED="n'est pas inclus dans",REQUIRED="attendu",RESTART="Redémarrage",RUN="En cours",RUNNING="en exécution",RUN_FOR="Durée des traitements : ",RUN_NEW="nouveau délai : ",RUN_SINCE="tourne depuis",SECOND="seconde",SECONDS="secondes",SLEEPING="Endormi pendant",SUPSENDED="Arrêtée",SUSPEND_ERROR="ERROR GEA.Suspend demande un tableau en paramètre 2",TIME_IN="vérification contrôlée car dans la plage horaire spécifiée ",TIME_NOT_ALLOWED="n'est pas autorisée",TIME_OUT="vérification ignorée car en dehors de la plage horaire : ",TODAY="Aujourd'hui ",TODAY_NOT_DST="Aujourd'hui n'est pas en mode DST",VALUE="valeur",WILL_SUSPEND="entrainera la suspension de"}GEA.translate["EN"]={ACTIONS="doing actions",ACTIVATED="activated",ACTIVATED_SINCE="activated since ",ADDED_DIRECT="task added for instant run",ADDED_FOR="task added for",ALWAYS="Always",BATTERIE="Low batterie",CHECKING="checking",CHECKING_DATE="checking dates",CHECKING_TIME="checking time range",CHECK_IF="'if' checking",CHECK_IF_FAILED="'if' stop the check",CHECK_MAIN="activation checking",CHECK_STARTED="starting checking",CURRENT_TIME="Current hour",DATE_NOT_ALLOWED="is not in the specified dates range",DESACTIVATED="desactivated",DEVICE_NOT_FOUND="Device ID not found",DONE="task done and suspended",ERROR="!!! ERROR !!!",ERROR_IF="IF malformed",GEA_SUSPENDED="Scene suspended by the global variable ",HOUR="hour",HOURS="hours",MINUTE="minute",MINUTES="minutes",NOTHING_TODO="nothing to do",NOTHING_TODOID="nothing to do for ID:",NOT_INCLUDED="is not included in",REQUIRED="excepted",RESTART="Restart",RUN="Run",RUNNING="Running",RUN_FOR="Duration : ",RUN_NEW="new delay : ",RUN_SINCE="running since",SECOND="second",SECONDS="seconds",SLEEPING="Sleeping for",SUPSENDED="Stopped",SUSPEND_ERROR="ERROR GEA.Suspend require a table as second parameter",TIME_IN="checking done time range is ok ",TIME_NOT_ALLOWED="is not allowed",TIME_OUT="checking abort because out of time range: ",TODAY="Today ",TODAY_NOT_DST="Today is not in DST mode",VALUE="value",WILL_SUSPEND="will suspend "}GEA.add=function(a,b,c,d)local e=false;local f=false;local g=-1;local h={}local i={}local j={}local k={}if d and#d>0 then for l=1,#d do lowCapsArg=string.lower(d[l][1])if lowCapsArg=="repeat"then e=true elseif lowCapsArg=="maxtime"then g=tonumber(d[l][2])elseif lowCapsArg=="group"then h[tonumber(d[l][2])]=true elseif lowCapsArg=="notstarted"then f=true end end;i=d end;if g>-1 then e=true end;GEA.index=GEA.index+1;if type(a)=="table"then if type(a[1])=="number"or type(a[1])=="table"then local m={}for l=2,#a do table.insert(m,a[l])j[l],k[l]=GEA.getName(a[l])end;a=a[1]if type(a)=="table"and type(a[1])=="string"and string.lower(a[1])=="alarm"then e=false;b=1 end;table.insert(i,{"If",m})elseif type(a[1])=="string"then if string.lower(a[1])=="global"and#a>2 and a[2]==""and a[3]==""then a=true elseif string.lower(a[1])=="alarm"then e=false;b=1 end end end;j[1],k[1]=GEA.getName(a)local n={a,b,c,e,i,j,0,false,{},h,false,0,GEA.index,g,k}if GEA.source["type"]=="autostart"and tonumber(n[GEA.keys["SECONDES"]])>=0 then GEA.insert(n)GEA.log("Add Autostart",n,GEA.translate[GEA.language]["ADDED_FOR"].." "..b.." "..GEA.translate[GEA.language]["SECONDS"],true,"grey")if f then local o=GEA.getCode("S",n[GEA.keys["INDEX"]])if GEA.suspended~=nil then GEA.suspended=string.gsub(GEA.suspended,o,"")end;GEA.suspended=GEA.suspended..o end elseif GEA.source["type"]=="global"and tonumber(n[GEA.keys["SECONDES"]])<0 then if type(n[GEA.keys["ID"]])=="table"and GEA.match(string.lower(n[GEA.keys["ID"]][1]),"global|global.")and n[GEA.keys["ID"]][2]==GEA.source["name"]then GEA.insert(n)GEA.log("Add Global",n,GEA.translate[GEA.language]["ADDED_DIRECT"],true,"grey")end elseif GEA.source["type"]=="property"and tonumber(n[GEA.keys["SECONDES"]])<0 then local a=0;if type(n[GEA.keys["ID"]])=="number"then a=n[GEA.keys["ID"]]elseif type(n[GEA.keys["ID"]])=="table"then a=n[GEA.keys["ID"]][2]if string.lower(n[GEA.keys["ID"]][1])=="sceneactivation"and#n[GEA.keys["ID"]]>2 then if tonumber(fibaro:getValue(a,"sceneActivation"))~=tonumber(n[GEA.keys["ID"]][3])then a=-1 end end end;if tonumber(a)==tonumber(GEA.source["deviceID"])then GEA.insert(n)GEA.log("Add Property",n,GEA.translate[GEA.language]["ADDED_DIRECT"],true,"grey")end end;return n[GEA.keys["INDEX"]]end;GEA.insert=function(n)GEA.todo[GEA.pos]=n;GEA.pos=GEA.pos+1;return n[GEA.keys["INDEX"]]end;GEA.addOrRemoveTask=function(p,q,r)local s=nil;local o=GEA.getCode(p,q)if GEA.useTasksGlobal then s=fibaro:getGlobalValue(GEA.globalTasks)else s=GEA.tasks end;if s~=nil then s=string.gsub(s,o,"")end;if r then if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,s..o)else GEA.tasks=s..o end else if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,s)else GEA.tasks=s end end end;GEA.isTask=function(p,q)local s=nil;local o=GEA.getCode(p,q)if GEA.useTasksGlobal then s=fibaro:getGlobalValue(GEA.globalTasks)else s=GEA.tasks end;if s~=nil then return string.match(s,o)end;return nil end;GEA.getCode=function(p,q)return"|"..p.."_"..q.."|"end;GEA.getName=function(a)if GEA.optimize==GEA.typeOptimize["ALL"]or GEA.source["type"]~="autostart"and GEA.optimize==GEA.typeOptimize["IMMEDIATE_ONLY"]then return"n/a","n/a"end;local k=""if type(a)=="nil"or type(a)=="boolean"then return GEA.translate[GEA.language]["ALWAYS"],""elseif type(a)=="number"then return fibaro:getName(tonumber(a)),GEA.getRoom(tonumber(a))elseif type(a)=="table"and GEA.match(string.lower(a[1]),"global|global.")then return a[2],""elseif type(a)=="table"then lowerCaps=string.lower(a[1])if a[2]then idNumeric=tonumber(a[2])end;if lowerCaps=="batteries"then return"Batteries <= "..a[1],""elseif lowerCaps=="sceneactivation"then return"Scene ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor+"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] > "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor-"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] < "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="sensor!"then return"Sensor ["..a[2].."|"..fibaro:getName(idNumeric).."] ~= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="battery"then return"["..a[2].."|"..fibaro:getName(idNumeric).."] <= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] = "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value+"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] > "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value-"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] < "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="value!"then return"Value ["..a[2].."|"..fibaro:getName(idNumeric).."] ~= "..a[3],GEA.getRoom(idNumeric)elseif lowerCaps=="dead"then return"Dead ["..a[2].."|"..fibaro:getName(idNumeric).."]",GEA.getRoom(idNumeric)elseif lowerCaps=="slider"then return"Slider ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider+"then return"Slider ["..a[2].."|"..a[3].."] > "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider-"then return"Slider ["..a[2].."|"..a[3].."] < "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="slider!"then return"Slider ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="label"then return"Label ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="label!"then return"Label ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="function"then return"Function",""elseif lowerCaps=="weather"then return"Weather",""elseif lowerCaps=="alarm"then return"Alarm "..fibaro:getValue(idNumeric,"ui.lblAlarme.value"),""elseif lowerCaps=="property"then return"Property ["..a[2].."|"..a[3].."] = "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="property!"then return"Property ["..a[2].."|"..a[3].."] ~= "..a[4],GEA.getRoom(idNumeric)elseif lowerCaps=="group"then return"Group ["..a[2].."]",""else end end end;GEA.getRoom=function(a)local t=fibaro:getRoomID(a)if type(t)=="number"then local u=fibaro:getRoomName(t)if type(u)=="string"then return u end end;return""end;GEA.checkDay=function(v)local w=false;jours=v;jours=string.gsub(jours,"All","Weekday,Weekend")jours=string.gsub(jours,"Weekday","Monday,Tuesday,Wednesday,Thursday,Friday")jours=string.gsub(jours,"Weekend","Saturday,Sunday")if string.find(string.lower(jours),string.lower(os.date("%A")))then w=true end;return w end;GEA.checkTimes=function(n)GEA.log("Check",n,GEA.translate[GEA.language]["CHECKING_DATE"],false)if not n[GEA.keys["PARAMS"]]then return true end;local x=true;local w=true;local y=true;local z=true;local jours=""if type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local A=n[GEA.keys["PARAMS"]][l]if type(A)=="table"then if string.lower(A[1])=="days"then w=GEA.checkDay(A[2])elseif string.lower(A[1])=="dst"then z=os.date("*t",os.time()).isdst elseif string.lower(A[1])=="notdst"then z=not os.date("*t",os.time()).isdst elseif string.lower(A[1])=="dates"then y=false;local B=os.date("%Y%m%d")local C=A[2]if string.len(C)==5 then C=C.."/"..os.date("%Y")end;C=string.format("%04d",GEA.split(C,"/")[3])..string.format("%02d",GEA.split(C,"/")[2])..string.format("%02d",GEA.split(C,"/")[1])local D=A[3]if string.len(D)==5 then D=D.."/"..os.date("%Y")end;D=string.format("%04d",GEA.split(D,"/")[3])..string.format("%02d",GEA.split(D,"/")[2])..string.format("%02d",GEA.split(D,"/")[1])y=tonumber(B)>=tonumber(C)and tonumber(B)<=tonumber(D)end end end end;if w and z then local E=false;for l=1,#n[GEA.keys["PARAMS"]]do local A=n[GEA.keys["PARAMS"]][l]if type(A)=="table"and string.lower(A[1])=="dates"then if not E then y=false end;local B=os.date("%Y%m%d")local C=A[2]if string.len(C)==5 then C=C.."/"..os.date("%Y")end;C=string.format("%04d",GEA.split(C,"/")[3])..string.format("%02d",GEA.split(C,"/")[2])..string.format("%02d",GEA.split(C,"/")[1])local D=A[3]if string.len(D)==5 then D=D.."/"..os.date("%Y")end;D=string.format("%04d",GEA.split(D,"/")[3])..string.format("%02d",GEA.split(D,"/")[2])..string.format("%02d",GEA.split(D,"/")[1])if tonumber(C)>tonumber(D)and tonumber(C)>tonumber(B)then C=tonumber(C)-10000 end;if tonumber(B)>=tonumber(C)and tonumber(B)<=tonumber(D)then y=true;E=true end end end end;if w and z and y then for l=1,#n[GEA.keys["PARAMS"]]do local A=n[GEA.keys["PARAMS"]][l]if type(A)=="table"and string.lower(A[1])=="time"then x=false;if GEA.checkTime(n,GEA.flatTime(A[2]).."-"..GEA.flatTime(A[3]))then return true end end end else if not w then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY"].." "..os.date("%A").." "..GEA.translate[GEA.language]["NOT_INCLUDED"].." "..jours,false,"yellow")elseif not z then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY_NOT_DST"],false,"yellow")elseif not y then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["TODAY"].." "..os.date("%x").." "..GEA.translate[GEA.language]["DATE_NOT_ALLOWED"],false,"yellow")end end;if not x then GEA.log("!CANCEL! CheckTimes",n,GEA.translate[GEA.language]["CURRENT_TIME"].." "..os.date("%H:%M").." "..GEA.translate[GEA.language]["TIME_NOT_ALLOWED"],false,"yellow")end;return x and y and w and z end;GEA.flatTime=function(F)local G=string.lower(F)G=string.gsub(G," ","")G=string.gsub(G,"h",":")G=string.gsub(G,"sunset",fibaro:getValue(1,"sunsetHour"))G=string.gsub(G,"sunrise",fibaro:getValue(1,"sunriseHour"))if string.find(G,"<")then G=GEA.flatTime(GEA.split(G,"<")[1]).."<"..GEA.flatTime(GEA.split(G,"<")[2])end;if string.find(G,">")then G=GEA.flatTime(GEA.split(G,">")[1])..">"..GEA.flatTime(GEA.split(G,">")[2])end;if string.find(G,"+")then local F=GEA.split(G,"+")[1]local r=GEA.split(G,"+")[2]local H=os.date("*t")local I=GEA.split(F,":")[2]local J=os.time{year=H.year,month=H.month,day=H.day,hour=tonumber(GEA.split(F,":")[1]),min=tonumber(GEA.split(F,":")[2]),sec=0}J=J+r*60;G=os.date("*t",J)G=string.format("%02d",G.hour)..":"..string.format("%02d",G.min)elseif string.find(G,"-")then local F=GEA.split(G,"-")[1]local r=GEA.split(G,"-")[2]local H=os.date("*t")local J=os.time{year=H.year,month=H.month,day=H.day,hour=tonumber(GEA.split(F,":")[1]),min=tonumber(GEA.split(F,":")[2]),sec=0}J=J-r*60;G=os.date("*t",J)G=string.format("%02d",G.hour)..":"..string.format("%02d",G.min)elseif string.find(G,"<")then local K=GEA.split(G,"<")[1]local L=GEA.split(G,"<")[2]K=string.format("%02d",GEA.split(K,":")[1])..":"..string.format("%02d",GEA.split(K,":")[2])L=string.format("%02d",GEA.split(L,":")[1])..":"..string.format("%02d",GEA.split(L,":")[2])if K")then local K=GEA.split(G,">")[1]local L=GEA.split(G,">")[2]K=string.format("%02d",GEA.split(K,":")[1])..":"..string.format("%02d",GEA.split(K,":")[2])L=string.format("%02d",GEA.split(L,":")[1])..":"..string.format("%02d",GEA.split(L,":")[2])if K>L then G=K else G=L end else G=string.format("%02d",GEA.split(G,":")[1])..":"..string.format("%02d",GEA.split(G,":")[2])end;return G end;GEA.checkTime=function(n,M)GEA.log("CheckTime",n,GEA.translate[GEA.language]["CHECKING_TIME"].." "..M,false)if not M or M==""then return true end;local C=string.sub(M,1,5)local D=string.sub(M,7,11)local B=os.date("%H:%M")local N=false;if D=C or B<=D else N=B>=C and B<=D end;if not N then GEA.log("CheckTime",n,GEA.translate[GEA.language]["TIME_OUT"]..M,false,"yellow")else GEA.log("CheckTime",n,GEA.translate[GEA.language]["TIME_IN"]..M,false)end;return N end;GEA.split=function(O,P)local P,Q=P or":",{}local R=string.format("([^%s]+)",P)O:gsub(R,function(S)Q[#Q+1]=S end)return Q end;GEA.trim=function(T)return T:gsub("^%s*(.-)%s*$","%1")end;GEA.match=function(T,U)if type(T)=="nil"then return type(U)=="nil"end;T=tostring(T)U=tostring(U):gsub("%%","%%%%"):gsub("-","%%-")local V=GEA.split(U,"|")for l=1,#V do if not GEA.regexFullAllow then V[l]="^"..V[l].."$"end;if string.match(T,GEA.trim(V[l]))then return true end end;return false end;GEA.check=function(n,q)GEA.log("Check",n,GEA.translate[GEA.language]["CHECK_STARTED"],false)if GEA.isTask("R",n[GEA.keys["INDEX"]])~=nil then GEA.log("Check",n,GEA.translate[GEA.language]["RESTART"],true)n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false;GEA.addOrRemoveTask("R",n[GEA.keys["INDEX"]],false)GEA.addOrRemoveTask("S",n[GEA.keys["INDEX"]],false)end;if GEA.isTask("S",n[GEA.keys["INDEX"]])~=nil then GEA.log("Check",n,GEA.translate[GEA.language]["SUPSENDED"],true)return end;if not n[GEA.keys["DONE"]]then n[GEA.keys["OK"]]=false end;if GEA.checkTimes(n)then if GEA.isActivated(n,1,n)then if n[GEA.keys["SECONDES"]]<0 then local W=GEA.isTask("M",n[GEA.keys["INDEX"]].."{(%d+)}")if W~=nil then n[GEA.keys["TOTALRUNS"]]=tonumber(W)GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{(%d+)}",false)end end;if n[GEA.keys["NBRUN"]]then n[GEA.keys["NBRUN"]]=n[GEA.keys["NBRUN"]]+1;n[GEA.keys["TOTALRUNS"]]=n[GEA.keys["TOTALRUNS"]]+1 else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0 end;if not n[GEA.keys["DONE"]]then GEA.log("Check",n,GEA.translate[GEA.language]["ACTIVATED_SINCE"]..n[GEA.keys["TOTALRUNS"]]*GEA.checkEvery.."/"..n[GEA.keys["SECONDES"]],false)end;if n[GEA.keys["SECONDES"]]<0 and(n[GEA.keys["MAXTIME"]]==-1 or n[GEA.keys["TOTALRUNS"]]-1-1 then GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{(%d+)}",false)if n[GEA.keys["TOTALRUNS"]]>=n[GEA.keys["MAXTIME"]]then GEA.addOrRemoveTask("S",n[GEA.keys["INDEX"]],true)else GEA.addOrRemoveTask("M",n[GEA.keys["INDEX"]].."{"..n[GEA.keys["TOTALRUNS"]].."}",true)end end else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false end;if GEA.source["type"]=="autostart"and n[GEA.keys["NBRUN"]]*GEA.checkEvery>=n[GEA.keys["SECONDES"]]and not n[GEA.keys["DONE"]]and(n[GEA.keys["MAXTIME"]]==-1 or n[GEA.keys["TOTALRUNS"]]-1=n[GEA.keys["MAXTIME"]]then GEA.log("Done",n,GEA.translate[GEA.language]["DONE"],true,"DarkSlateBlue")n[GEA.keys["DONE"]]=true end;n[GEA.keys["NBRUN"]]=0 end else n[GEA.keys["NBRUN"]]=0;n[GEA.keys["TOTALRUNS"]]=0;n[GEA.keys["DONE"]]=false;n[GEA.keys["OK"]]=false end end;GEA.isActivated=function(n,X,Y)if X==1 then GEA.log("isActivated",n,GEA.translate[GEA.language]["CHECK_MAIN"],false)else GEA.log("isActivated",n,GEA.translate[GEA.language]["CHECK_IF"],false)end;local Z=-1;local a=n[GEA.keys["ID"]]local _=true;local a0=type(a)if a0=="nil"then _=true;Y[GEA.keys["VALUE"]][X]="true"elseif a0=="boolean"then _=a;if _ then Y[GEA.keys["VALUE"]][X]="true"else Y[GEA.keys["VALUE"]][X]="false"end elseif a0=="number"then local type=fibaro:getType(tonumber(a))GEA.log("isActivated",n,"type : "..type,false)if GEA.match(type,"door_sensor|water_sensor|motion_sensor|com.fibaro.FGMS001|com.fibaro.doorSensor|com.fibaro.waterSensor|com.fibaro.motionSensor")then _=tonumber(fibaro:getValue(tonumber(a),"value"))>=1;if not _ and GEA.source["type"]=="autostart"and fibaro:getValue(tonumber(a),"lastBreached")~=""then _=os.time()-tonumber(fibaro:getValue(tonumber(a),"lastBreached"))0 or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 elseif GEA.match(type,"com.fibaro.FGRGBW441M")then _=tonumber(fibaro:getValue(tonumber(a),"value"))>0 and not fibaro:getValue(tonumber(a),"color")=="0,0,0,0"or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 else _=tonumber(fibaro:getValue(tonumber(a),"value"))>0 end;if not _ and GEA.source["type"]=="autostart"and fibaro:getModificationTime(tonumber(a),"value")then _=os.time()-tonumber(fibaro:getModificationTime(tonumber(a),"value"))0 else _=tonumber(fibaro:getValue(tonumber(a),"value"))==1 end;Z=tonumber(a)Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a),"value")elseif a0=="table"then local a1=string.lower(a[1])if a1=="global"and#a>2 then GEA.log("isActivated",n,"type : global variable",false)_=GEA.match(fibaro:getGlobalValue(a[2]),a[3])Y[GEA.keys["VALUE"]][X]=fibaro:getGlobalValue(a[2])elseif a1=="global+"and#a>2 then GEA.log("isActivated",n,"type : Global+",false)_=tonumber(fibaro:getGlobalValue(a[2]))>tonumber(a[3])Y[GEA.keys["VALUE"]][X]=fibaro:getGlobalValue(a[2])elseif a1=="global-"and#a>2 then GEA.log("isActivated",n,"type : Global-",false)_=tonumber(fibaro:getGlobalValue(a[2]))2 then GEA.log("isActivated",n,"type : Global!",false)_=not GEA.match(fibaro:getGlobalValue(a[2]),a[3])Y[GEA.keys["VALUE"]][X]=fibaro:getGlobalValue(a[2])elseif a1=="slider"and#a>3 then GEA.log("isActivated",n,"type : Slider",false)_=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))==tonumber(a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif a1=="slider-"and#a>3 then GEA.log("isActivated",n,"type : Slider-",false)_=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))3 then GEA.log("isActivated",n,"type : Slider!",false)_=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))~=tonumber(a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif a1=="slider+"and#a>3 then GEA.log("isActivated",n,"type : Slider+",false)_=tonumber(fibaro:getValue(a[2],"ui."..a[3]..".value"))>tonumber(a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif a1=="label"and#a>3 then GEA.log("isActivated",n,"type : Label",false)_=GEA.match(fibaro:getValue(a[2],"ui."..a[3]..".value"),a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif a1=="label!"and#a>3 then GEA.log("isActivated",n,"type : Label!",false)_=not GEA.match(fibaro:getValue(a[2],"ui."..a[3]..".value"),a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],"ui."..a[3]..".value")elseif a1=="property"and#a>3 then GEA.log("isActivated",n,"type : Property",false)_=GEA.match(fibaro:getValue(a[2],a[3]),a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],a[3])elseif a1=="property!"and#a>3 then GEA.log("isActivated",n,"type : Property",false)_=not GEA.match(fibaro:getValue(a[2],a[3]),a[4])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(a[2],a[3])elseif a1=="batteries"and#a>1 then GEA.log("isActivated",n,"type : batteries",false)local a2=""for l=1,1000 do local a3=fibaro:getValue(l,'batteryLevel')if type(a3)~=nil and tonumber(a3)~=nil and tonumber(a3)<=tonumber(a[2])or tonumber(a3)==255 then GEA.log("isActivated",n,"checking : batteries "..fibaro:getName(l),false)if not string.find(fibaro:getName(l),"Zwave_")then a2=a2 ..GEA.translate[GEA.language]["BATTERIE"].." ["..fibaro:getName(l).."] "..a3 .."%\n"_=true end end end;Y[GEA.keys["VALUE"]][X]=a[2]n[GEA.keys["MESSAGE"]]=a2 elseif(a1=="sensor"or a1=="power")and#a>2 then GEA.log("isActivated",n,"type : Sensor",false)_=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))==tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif(a1=="sensor+"or a1=="power+")and#a>2 then GEA.log("isActivated",n,"type : Sensor+",false)_=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))>tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif(a1=="sensor-"or a1=="power-")and#a>2 then GEA.log("isActivated",n,"type : Sensor-",false)_=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))2 then GEA.log("isActivated",n,"type : Sensor!",false)_=tonumber(fibaro:getValue(tonumber(a[2]),GEA.power))~=tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),GEA.power)elseif a1=="battery"and#a>2 then GEA.log("isActivated",n,"type : Battery",false)_=false;local a3=fibaro:getValue(tonumber(a[2]),'batteryLevel')if type(a3)~=nil and tonumber(a3)<=tonumber(a[3])or tonumber(a3)==255 then _=true;Y[GEA.keys["VALUE"]][X]=a3 end;Z=tonumber(a[2])elseif a1=="value"and#a>2 then GEA.log("isActivated",n,"type : Value",false)_=tonumber(fibaro:getValue(tonumber(a[2]),"value"))==tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),"value")elseif a1=="value+"and#a>2 then GEA.log("isActivated",n,"type : Value+",false)_=tonumber(fibaro:getValue(tonumber(a[2]),"value"))>tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),"value")elseif a1=="value-"and#a>2 then GEA.log("isActivated",n,"type : Value-",false)_=tonumber(fibaro:getValue(tonumber(a[2]),"value"))2 then GEA.log("isActivated",n,"type : Value!",false)_=tonumber(fibaro:getValue(tonumber(a[2]),"value"))~=tonumber(a[3])Z=tonumber(a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),"value")elseif a1=="dead"and#a>1 then GEA.log("isActivated",n,"type : isDead",false)_=tonumber(fibaro:getValue(tonumber(a[2]),"dead"))>=1;Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),"dead")elseif a1=="weather"and#a>1 then GEA.log("isActivated",n,"type : weather",false)_=GEA.match(fibaro:getValue(3,"WeatherConditionConverted"),a[2])Y[GEA.keys["VALUE"]][X]=fibaro:getValue(3,"WeatherConditionConverted")elseif a1=="function"and#a>1 then GEA.log("isActivated",n,"type : Function",false)local a4,a5,a6=pcall(a[2])if a4 then _=a5;if a6 then Y[GEA.keys["VALUE"]][X]=a6 end else _=false end elseif a1=="group"and#a>1 then GEA.log("isActivated",n,"type : Group",false)for l=1,#GEA.todo do if GEA.todo[l][GEA.keys["GROUPS"]][tonumber(a[2])]then if not GEA.todo[l][GEA.keys["OK"]]then _=false end end end;Y[GEA.keys["VALUE"]][X]=fibaro:getValue(tonumber(a[2]),"")elseif a1=="alarm"then GEA.log("isActivated",n,"type : alarm",false)local F=fibaro:getValue(tonumber(a[2]),"ui.lblAlarme.value")if not(type(F)=="nil"or F==""or F=="--:--")then _=GEA.checkTime(n,GEA.flatTime(F).."-"..GEA.flatTime(F))if _ then local jours=fibaro:getValue(tonumber(a[2]),"ui.lblJours.value")local v=""if string.find(jours,"Lu")or string.find(jours,"Mo")then v=v.."Monday"end;if string.find(jours,"Ma")or string.find(jours,"Tu")then v=v.."Tuesday"end;if string.find(jours,"Me")or string.find(jours,"We")then v=v.."Wednesday"end;if string.find(jours,"Je")or string.find(jours,"Th")then v=v.."Thursday"end;if string.find(jours,"Ve")or string.find(jours,"Fr")then v=v.."Friday"end;if string.find(jours,"Sa")or string.find(jours,"Sa")then v=v.."Saturday"end;if string.find(jours,"Di")or string.find(jours,"Su")then v=v.."Sunday"end;_=GEA.checkDay(v)end;Y[GEA.keys["VALUE"]][X]=F else _=false end end else end;if X==1 then for l=1,#n[GEA.keys["PARAMS"]]do if string.lower(n[GEA.keys["PARAMS"]][l][1])=="inverse"then _=not _ end end;if Z>-1 and type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local A=n[GEA.keys["PARAMS"]][l]if string.lower(A[1])=="armed"then _=_ and tonumber(fibaro:getValue(Z,"armed"))>0;if#A>1 then _=_ and tonumber(fibaro:getValue(A[2],"armed"))>0 end elseif string.lower(A[1])=="disarmed"then _=_ and tonumber(fibaro:getValue(Z,"armed"))==0;if#A>1 then _=_ and tonumber(fibaro:getValue(A[2],"armed"))==0 end end end end;if _ then for l=1,#n[GEA.keys["PARAMS"]]do local A=n[GEA.keys["PARAMS"]][l]if type(A)=="table"and string.lower(A[1])=="if"then local a7=true;for a8=1,#A[2]do if type(A[2])=="table"then if not GEA.isActivated({A[2][a8]},a8+1,n)then a7=false;GEA.log("!CANCEL! isActivated",n,GEA.translate[GEA.language]["CHECK_IF_FAILED"],false,"yellow")end else GEA.log(GEA.translate[GEA.language]["ERROR"],n,GEA.translate[GEA.language]["ERROR_IF"],true,"red")end end;_=a7 end end end end;if _ then GEA.log("isActivated",n,GEA.translate[GEA.language]["ACTIVATED"],false)else GEA.log("!CANCEL! isActivated",n,GEA.translate[GEA.language]["DESACTIVATED"],false,"yellow")end;return _ end;GEA.getMessage=function(n,c)local a2=""if n[GEA.keys["MESSAGE"]]then a2=n[GEA.keys["MESSAGE"]]end;if c and c~=""then a2=c end;if n[GEA.keys["VALUE"]][1]then a2=string.gsub(a2,"#value#",n[GEA.keys["VALUE"]][1])a2=string.gsub(a2,"#value%[1%]#",n[GEA.keys["VALUE"]][1])end;if n[GEA.keys["VALUE"]][2]then a2=string.gsub(a2,"#value%[2%]#",n[GEA.keys["VALUE"]][2])end;if n[GEA.keys["VALUE"]][3]then a2=string.gsub(a2,"#value%[3%]#",n[GEA.keys["VALUE"]][3])end;if n[GEA.keys["VALUE"]][4]then a2=string.gsub(a2,"#value%[4%]#",n[GEA.keys["VALUE"]][4])end;if n[GEA.keys["VALUE"]][5]then a2=string.gsub(a2,"#value%[5%]#",n[GEA.keys["VALUE"]][5])end;if n[GEA.keys["VALUE"]][6]then a2=string.gsub(a2,"#value%[6%]#",n[GEA.keys["VALUE"]][6])end;if n[GEA.keys["VALUE"]][7]then a2=string.gsub(a2,"#value%[7%]#",n[GEA.keys["VALUE"]][7])end;if n[GEA.keys["VALUE"]][8]then a2=string.gsub(a2,"#value%[8%]#",n[GEA.keys["VALUE"]][8])end;if n[GEA.keys["VALUE"]][9]then a2=string.gsub(a2,"#value%[9%]#",n[GEA.keys["VALUE"]][9])end;a2=string.gsub(a2,"#time#",os.date("%X"))a2=string.gsub(a2,"#date#",os.date("%x"))if n[GEA.keys["NAME"]][1]then a2=string.gsub(a2,"#name#",n[GEA.keys["NAME"]][1])a2=string.gsub(a2,"#name%[1%]#",n[GEA.keys["NAME"]][1])end;if n[GEA.keys["NAME"]][2]then a2=string.gsub(a2,"#name%[2%]#",n[GEA.keys["NAME"]][2])end;if n[GEA.keys["NAME"]][3]then a2=string.gsub(a2,"#name%[3%]#",n[GEA.keys["NAME"]][3])end;if n[GEA.keys["NAME"]][4]then a2=string.gsub(a2,"#name%[4%]#",n[GEA.keys["NAME"]][4])end;if n[GEA.keys["NAME"]][5]then a2=string.gsub(a2,"#name%[5%]#",n[GEA.keys["NAME"]][5])end;if n[GEA.keys["NAME"]][6]then a2=string.gsub(a2,"#name%[6%]#",n[GEA.keys["NAME"]][6])end;if n[GEA.keys["NAME"]][7]then a2=string.gsub(a2,"#name%[7%]#",n[GEA.keys["NAME"]][7])end;if n[GEA.keys["NAME"]][8]then a2=string.gsub(a2,"#name%[8%]#",n[GEA.keys["NAME"]][8])end;if n[GEA.keys["NAME"]][9]then a2=string.gsub(a2,"#name%[9%]#",n[GEA.keys["NAME"]][9])end;if n[GEA.keys["ROOM"]][1]then a2=string.gsub(a2,"#room#",n[GEA.keys["ROOM"]][1])a2=string.gsub(a2,"#room%[1%]#",n[GEA.keys["ROOM"]][1])end;if n[GEA.keys["ROOM"]][2]then a2=string.gsub(a2,"#room%[2%]#",n[GEA.keys["ROOM"]][2])end;if n[GEA.keys["ROOM"]][3]then a2=string.gsub(a2,"#room%[3%]#",n[GEA.keys["ROOM"]][3])end;if n[GEA.keys["ROOM"]][4]then a2=string.gsub(a2,"#room%[4%]#",n[GEA.keys["ROOM"]][4])end;if n[GEA.keys["ROOM"]][5]then a2=string.gsub(a2,"#room%[5%]#",n[GEA.keys["ROOM"]][5])end;if n[GEA.keys["ROOM"]][6]then a2=string.gsub(a2,"#room%[6%]#",n[GEA.keys["ROOM"]][6])end;if n[GEA.keys["ROOM"]][7]then a2=string.gsub(a2,"#room%[7%]#",n[GEA.keys["ROOM"]][7])end;if n[GEA.keys["ROOM"]][8]then a2=string.gsub(a2,"#room%[8%]#",n[GEA.keys["ROOM"]][8])end;if n[GEA.keys["ROOM"]][9]then a2=string.gsub(a2,"#room%[9%]#",n[GEA.keys["ROOM"]][9])end;a2=string.gsub(a2,"#seconds#",n[GEA.keys["SECONDES"]])local a9=GEA.getDureeInString(n[GEA.keys["TOTALRUNS"]]*GEA.checkEvery)a2=string.gsub(a2,"#duration#",a9[1])a2=string.gsub(a2,"#durationfull#",a9[2])a2=string.gsub(a2,"#runs#",n[GEA.keys["TOTALRUNS"]])return a2 end;GEA.getDureeInString=function(aa)local aa=aa;local ab=""nHours=math.floor(aa/3600)nMins=math.floor(aa/60-nHours*60)nSecs=math.floor(aa-nHours*3600-nMins*60)aa=""if nHours>0 then aa=aa..nHours.."h "ab=ab..nHours;if nHours>1 then ab=ab.." "..GEA.translate[GEA.language]["HOURS"]else ab=ab.." "..GEA.translate[GEA.language]["HOUR"]end end;if nMins>0 then aa=aa..nMins.."m "if nHours>0 then ab=ab.." "end;if nSecs==0 and nHours>0 then ab=ab.."et "end;ab=ab..nMins;if nMins>1 then ab=ab.." "..GEA.translate[GEA.language]["MINUTES"]else ab=ab.." "..GEA.translate[GEA.language]["MINUTE"]end end;if nSecs>0 then aa=aa..nSecs.."s"if nMins>0 then ab=ab.." et "end;ab=ab..nSecs;if nSecs>1 then ab=ab.." "..GEA.translate[GEA.language]["SECONDS"]else ab=ab.." "..GEA.translate[GEA.language]["SECOND"]end end;return{aa,ab}end;GEA.sendActions=function(n)GEA.log("sendActions",n,GEA.translate[GEA.language]["ACTIONS"],true)local ac=false;if type(n[GEA.keys["PARAMS"]])=="table"then for l=1,#n[GEA.keys["PARAMS"]]do local ad=n[GEA.keys["PARAMS"]][l]if type(ad)=="table"then local a1=string.lower(ad[1])if a1=="turnoff"or a1=="turnon"or a1=="switch"then local a=GEA.getId(n,ad)if a>0 then local ae=fibaro:getValue(tonumber(a),"value")local af=fibaro:getType(tonumber(a))if GEA.match(af,"rgb_driver")and(tonumber(fibaro:getValue(tonumber(a),"value"))>0 or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0)then ae=1 elseif GEA.match(af,"com.fibaro.FGRGBW441M")then if fibaro:getValue(tonumber(a),"color")~="0,0,0,0"or tonumber(fibaro:getValue(tonumber(a),"currentProgramID"))>0 then ae=1 end end;if tonumber(ae)>=1 and a1=="turnoff"or tonumber(ae)==0 and a1=="turnon"then fibaro:call(tonumber(a),ad[1])elseif a1=="switch"then local ag="turnOff"if tonumber(ae)==0 then ag="turnOn"end;fibaro:call(tonumber(a),ag)end;GEA.log("sendActions",n,"!ACTION! : "..ad[1],true)end end;if a1=="global"and#ad>2 then local a6=string.match(ad[3],"(%d+)")if GEA.match(ad[3],"inc%+")then local ah=tonumber(fibaro:getGlobalValue(ad[2]))if type(a6)~="nil"then fibaro:setGlobal(ad[2],ah+a6)else fibaro:setGlobal(ad[2],ah+1)end elseif GEA.match(ad[3],"dec%-")then local ah=tonumber(fibaro:getGlobalValue(ad[2]))if type(a6)~="nil"then fibaro:setGlobal(ad[2],ah-a6)else fibaro:setGlobal(ad[2],ah-1)end else fibaro:setGlobal(ad[2],GEA.getMessage(n,ad[3]))end;GEA.log("sendActions",n,"!ACTION! : setGlobal "..ad[2]..","..GEA.getMessage(n,ad[3]),true)elseif a1=="portable"and#ad>1 then fibaro:call(tonumber(ad[2]),"sendPush",GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : pushed to "..ad[2],true)ac=true elseif a1=="email"and#ad>1 then local ai="GEA Notification"if#ad>2 then ai=ad[3]end;fibaro:call(tonumber(ad[2]),"sendEmail",GEA.getMessage(n,ai),GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : email to "..ad[2],true)elseif a1=="picture"and#ad>2 then local aj=tonumber(ad[3])local ak=tonumber(ad[2])fibaro:call(ak,"sendPhotoToUser",aj)GEA.log("sendActions",n,"!ACTION! : email picture from camera "..ak.." to "..aj,true)elseif a1=="scenario"and#ad>1 then fibaro:startScene(ad[2])GEA.log("sendActions",n,"!ACTION! : Scene "..ad[2],true)elseif a1=="stopscenario"and#ad>1 then if fibaro:countScenes(ad[2])then fibaro:killScene(ad[2])GEA.log("sendActions",n,"!ACTION! : Stop Scene "..ad[2],true)else GEA.log("sendActions",n,"!ACTION! : No Stop Scene "..ad[2],true)end elseif a1=="enablescenario"and#ad>1 then fibaro:setSceneEnabled(ad[2],true)GEA.log("sendActions",n,"!ACTION! : Scene enabled "..ad[2],true)elseif a1=="disablescenario"and#ad>1 then fibaro:setSceneEnabled(ad[2],false)GEA.log("sendActions",n,"!ACTION! : Scene disabled "..ad[2],true)elseif a1=="function"then local a4,a5=pcall(ad[2])if a4 then GEA.log("sendActions",n,"!ACTION! : Function OK",true)else GEA.log("sendActions",n,"!ACTION! : Function "..tostring(a5 or"Inconnu."),true)end elseif a1=="setarmed"and#ad>1 then fibaro:call(ad[2],"setArmed",1)GEA.log("sendActions",n,"!ACTION! : setArmed "..ad[2],true)elseif a1=="setdisarmed"and#ad>1 then fibaro:call(ad[2],"setArmed",0)GEA.log("sendActions",n,"!ACTION! : setDisarmed "..ad[2],true)elseif a1=="currenticon"and#ad>2 then fibaro:call(ad[2],"setProperty","currentIcon",tostring(ad[3]))GEA.log("sendActions",n,"!ACTION! : CurrentIcon "..ad[2],true)elseif a1=="copyglobal"and#ad>2 then fibaro:setGlobal(ad[3],fibaro:getGlobalValue(ad[2]))GEA.log("sendActions",n,"!ACTION! : CopyGlobal "..ad[2],true)elseif a1=="restarttask"and#ad>1 then GEA.addOrRemoveTask("R",ad[2],true)GEA.log("sendActions",n,"!ACTION! : Restart "..ad[2],true)elseif a1=="stoptask"and#ad>1 then GEA.addOrRemoveTask("S",ad[2],true)GEA.log("sendActions",n,"!ACTION! : StopTask "..ad[2],true)elseif a1=="wakeup"and#ad>1 then fibaro:call(1,'wakeUpAllDevices',ad[2])GEA.log("sendActions",n,"!ACTION! : WakeUp "..ad[2],true)elseif a1=="virtualdevice"and#ad>2 then fibaro:call(ad[2],"pressButton",tostring(ad[3]))GEA.log("sendActions",n,"!ACTION! : VirtualDevice "..ad[2]..","..ad[3],true)elseif a1=="slider"and#ad>3 then fibaro:call(ad[2],"setSlider",ad[3],ad[4])GEA.log("sendActions",n,"!ACTION! : Slider "..ad[2]..","..ad[3].."="..ad[4],true)elseif a1=="label"and#ad>3 then fibaro:call(ad[2],"setProperty","ui."..ad[3]..".value",GEA.getMessage(n,ad[4]))GEA.log("sendActions",n,"!ACTION! : Label "..ad[2]..","..ad[3].." = "..GEA.getMessage(n,ad[4]),true)elseif a1=="rgb"and#ad>5 then if ad[3]==-1 or ad[4]==-1 or ad[5]==-1 or ad[6]==-1 then if ad[3]~=-1 then fibaro:call(ad[2],"setR",ad[3])end;if ad[4]~=-1 then fibaro:call(ad[2],"setG",ad[4])end;if ad[5]~=-1 then fibaro:call(ad[2],"setB",ad[5])end;if ad[6]~=-1 then fibaro:call(ad[2],"setW",ad[6])end else fibaro:call(ad[2],"setColor",ad[3],ad[4],ad[5],ad[6])end;GEA.log("sendActions",n,"!ACTION! : RGB "..ad[2]..", Color = "..ad[3]..","..ad[4]..","..ad[5]..","..ad[6])elseif a1=="program"and#ad>2 then if tonumber(fibaro:getValue(tonumber(ad[2]),"currentProgramID"))~=tonumber(ad[3])then fibaro:call(ad[2],"startProgram",ad[3])end;GEA.log("sendActions",n,"!ACTION! : startProgram "..ad[2]..", program = "..ad[3])elseif a1=="value"then local a=GEA.getId(n,ad)if a>0 then if#ad>2 then fibaro:call(a,"setValue",ad[3])GEA.log("sendActions",n,"!ACTION! : setValue "..ad[3],true)else fibaro:call(a,"setValue",ad[2])GEA.log("sendActions",n,"!ACTION! : setValue "..ad[2],true)end end elseif a1=="open"or a1=="close"then local a=GEA.getId(n,ad)if a>0 then local al=100;if#ad>2 then if a1=="close"then al=al-ad[3]else al=ad[3]end;fibaro:call(a,"setValue",al)GEA.log("sendActions",n,"!ACTION! : setValue "..al,true)elseif#ad>1 then if a1=="close"then al=al-ad[2]else al=ad[2]end;fibaro:call(a,"setValue",al)GEA.log("sendActions",n,"!ACTION! : setValue "..al,true)else fibaro:call(a,ad[1])GEA.log("sendActions",n,"!ACTION! : "..ad[1],true)end end end end end end;if n[GEA.keys["MESSAGE"]]~=""and not ac then if n[GEA.keys["MESSAGE"]]=="debug"then fibaro:debug("=============="..os.time().."=====================")else for l=1,#GEA.portables do fibaro:call(tonumber(GEA.portables[l]),"sendPush",GEA.getMessage(n,nil))GEA.log("sendActions",n,"!ACTION! : sendPush "..GEA.getMessage(n,nil),true)end end end end;GEA.getId=function(n,am)local a=0;if am and type(am)=="table"and#am>1 and(string.lower(am[1])=="turnoff"or string.lower(am[1])=="turnon"or string.lower(am[1])=="switch")then a=tonumber(am[2])elseif am and type(am)=="table"and#am>2 and(string.lower(am[1])=="value"or string.lower(am[1])=="open"or string.lower(am[1])=="close")then a=tonumber(am[2])elseif type(n[GEA.keys["ID"]])=="number"then a=n[GEA.keys["ID"]]elseif type(n[GEA.keys["ID"]])=="table"and string.lower(n[GEA.keys["ID"]][1])=="sensor+"or string.lower(n[GEA.keys["ID"]][1])=="sensor-"or string.lower(n[GEA.keys["ID"]][1])=="value-"or string.lower(n[GEA.keys["ID"]][1])=="value+"or string.lower(n[GEA.keys["ID"]][1])=="dead"then a=tonumber(n[GEA.keys["ID"]][2])end;if a==0 then fibaro:debug(GEA.translate[GEA.language]["DEVICE_NOT_FOUND"])end;return a end;GEA.pause=function()local an=true;if#GEA.getGlobalForActivation>0 then an=false;if fibaro:getGlobalValue(GEA.getGlobalForActivation[1])==GEA.getGlobalForActivation[2]then an=true else GEA.log("Run",nil,GEA.translate[GEA.language]["GEA_SUSPENDED"].." "..GEA.getGlobalForActivation[1].." "..GEA.translate[GEA.language]["VALUE"].." "..fibaro:getGlobalValue(GEA.getGlobalForActivation[1]).." "..GEA.translate[GEA.language]["REQUIRED"].." "..GEA.getGlobalForActivation[2],true)end end;return not an end;GEA.run=function()if config then config()end;if setEvents then setEvents()end;if GEA.isVersionFour then GEA.power="power"end;GEA.log("GEA Version "..GEA.version,nil," "..GEA.translate[GEA.language]["RUNNING"].."...",true,"green")if#GEA.todo==0 then if GEA.source["type"]~="property"then GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["NOTHING_TODO"],true)else GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["NOTHING_TODOID"]..GEA.source["deviceID"],true)end;return false end;local ao=#GEA.todo;if GEA.source["type"]=="autostart"then if GEA.useTasksGlobal then fibaro:setGlobal(GEA.globalTasks,GEA.suspended)else GEA.tasks=GEA.suspended end;local ap=GEA.checkEvery;local aq=1;local ar=true;local as=os.time()while true do GEA.log(GEA.translate[GEA.language]["RUN"],nil,GEA.translate[GEA.language]["SLEEPING"].." "..GEA.checkEvery.." "..GEA.translate[GEA.language]["SECONDS"],false)fibaro:sleep(ap*1000)local at=os.time()local au=GEA.checkAllToDo(ao)local av=au-at;if ar then av=av*2;ar=false end;ap=GEA.checkEvery-av;if aq>=20 then local a2=GEA.translate[GEA.language]["RUN_FOR"]..av.."s "..GEA.translate[GEA.language]["RUN_NEW"]..ap.."s / "..GEA.translate[GEA.language]["RUN_SINCE"].." "..GEA.getDureeInString(os.time()-as)[1]fibaro:debug(""..a2 .."")aq=0 end;aq=aq+1 end else GEA.checkAllToDo(ao)end end;GEA.checkAllToDo=function(ao)if not GEA.pause()then for l=1,ao do GEA.log(GEA.translate[GEA.language]["RUN"],GEA.todo[l],GEA.translate[GEA.language]["CHECKING"],false)if GEA.catchError then if not pcall(function()GEA.check(GEA.todo[l],l)end)then GEA.log(GEA.translate[GEA.language]["ERROR"],GEA.todo[l],GEA.translate[GEA.language]["CHECKING"],true,red)end else GEA.check(GEA.todo[l],l)end end end;return os.time()end;GEA.log=function(aw,n,c,ax,ay)if ax or GEA.debug then local a2=""local j="If"if not n and not ax then return elseif n then local az=type(n[GEA.keys["ID"]])if n[GEA.keys["NAME"]]then j=n[GEA.keys["NAME"]]if type(j)=="table"then j=j[1]end;j=j.." ] "if az=="nil"or az=="boolean"then a2=a2 .."[ "..j elseif az=="number"then a2=a2 .."[ "..n[GEA.keys["ID"]].." | "..j elseif az=="table"then lowerId=string.lower(n[GEA.keys["ID"]][1])if GEA.match(lowerId,"global|global.")then a2=a2 .."[ "..n[GEA.keys["ID"]][2].."="..n[GEA.keys["ID"]][3].." ] "elseif lowerId=="batteries"then a2=a2 .."[ "..n[GEA.keys["ID"]][2].." ] "elseif lowerId=="group"then a2=a2 .."[ "..j elseif GEA.match(lowerId,"sensor|sensor.|value|value.|dead|sceneactivation|battery")then a2=a2 .."[ "..j elseif GEA.match(lowerId,"slider|slider.|label|label.|property|property.")then a2=a2 .."[ "..j elseif lowerId=="weather"then a2=a2 .."[ Weather ] "elseif lowerId=="function"then a2=a2 .."[ Function ] "elseif lowerId=="alarm"then a2=a2 .."Alarm "..fibaro:getValue(tonumber(n[GEA.keys["ID"]][2]),"ui.lblAlarme.value")else end end end end;if aw and aw~=""then a2=a2 ..string.format("%-20s",aw)..": "end;if c and c~=""then a2=a2 ..string.format("%-20s",c)end;if n then if n[GEA.keys["INDEX"]]then a2=a2 .." (ID: "..n[GEA.keys["INDEX"]]..")"end;if n[GEA.keys["PARAMS"]]and type(n[GEA.keys["PARAMS"]])=="table"and#n[GEA.keys["PARAMS"]]>0 then for l=1,#n[GEA.keys["PARAMS"]]do a2=a2 .." ["local aA=n[GEA.keys["PARAMS"]][l]if type(aA)=="table"then for a8=1,#aA do if string.lower(aA[1])=="if"then if a8==1 then a2=a2 .."If..."end elseif string.lower(aA[1])=="function"then if a8==1 then a2=a2 .."Function..."end else a2=a2 ..aA[a8]..","end end end;a2=a2:sub(1,a2:len()-1).."]"end end end;fibaro:debug(""..a2 .."")end end end;GEA.run() \ No newline at end of file