Aller au contenu

jang

Membres confirmés
  • Compteur de contenus

    162
  • Inscription

  • Dernière visite

Réputation sur la communauté

176 Excellent

2 abonnés

À propos de jang

  • Rang
    Membre passionné

Profile Information

  • Sexe :
    Homme
  • Ville :
    Home
  • Box
    Home Center 2
  • Version
    HC3

Visiteurs récents du profil

1 175 visualisations du profil
  1. jang

    Table Json

    You see in the output above that uid versions uid#5 and uid#7 both has key 'TemperatureState' and then the question is which should be choosen? Now we can get both with keys["5#uid"] and keys["7#uid"]
  2. jang

    Table Json

    How about this? local function find(uid,expr) local res,device = {} local function find_aux(expr) if type(expr) == 'table' then if expr[1] then -- array for _,e in ipairs(expr) do find_aux(e) end else -- key/value if expr.deviceURL then device = expr.deviceURL:match(uid) if device then device = device.."#" end end if device and expr.name and (expr.name:sub(1,3)=='io:' or expr.name:sub(1,5)=='core:') and expr.value then local key = device..expr.name if res[key] and res[key]~=expr.value then error("Duplicate key:"..key) end res[key]=expr.value else for k,v in pairs(expr) do find_aux(v) end end end end end uid = uid:gsub("%-","%%-").."#(%d+)$" find_aux(expr) return res end local uid = "io://0810-4343-0200/13610533" keys = find(uid,jsonResponse.devices) for k,v in pairs(keys) do print(k,"=",json.encode(v):sub(1,80)) end and output [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:LuminanceState = 4 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:RSSILevelState = 36 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:DryingDurationMaxState = 120 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:BoostDurationMaxState = 60 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:FilterFanCloggingErrorState = 12 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:PriorityLockTimerState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:SetpointLoweringTemperatureInProgModeState = 2.5 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:BoostModeDurationState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:IdentifierState = "00000000" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:TemperatureState = 20.5 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:DiscreteRSSILevelState = "low" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:MeasuredValueType = "core:LuminanceInLux" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:TemperatureState = 23.5 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:TargetTemperatureState = 17 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:MeasuredValueType = "core:TemperatureInCelcius" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:MaximumHeatingLevelState = "unknown" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:MeasuredValueType = "core:TemperatureInCelcius" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:MeasuredValueType = "core:RelativeValueInPercentage" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:DateTimeState = {"month":12,"weekday":3,"day":1,"second":50,"year":2022,"minute":48,"hour":11} [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:DerogatedTargetTemperatureState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:ComfortRoomTemperatureState = 17 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:TimeProgramState = [{"monday":[{"start":"04:45","end":"05:45"},{"start":"00:00","end":"00:00"},{"st [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:CumulatedLoweringState = 18 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:CurrentWorkingRateState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:TimerForTransitoryStateState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:LocalLeadTimeState = 3268 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:OperatingModeState = "external" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:VersionState = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:OnOffState = "on" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:NameState = "I2G_Actuator" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:RegulationModeState = "none" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:ModelState = "Symphonik Gauche" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:TemperatureProbeCalibrationOffsetState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 2#core:OccupancyState = "noPersonInside" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 2#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:RelativeHumidityState = 44 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:EffectiveTemperatureSetpointState = 17 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:PowerState = 1750 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:TowelDryerTemporaryStateState = "permanentHeating" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:MeasuredValueType = "core:ElectricalEnergyInWh" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 2#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:ControllerAddressState = 13610532 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:ElectricEnergyConsumptionState = 1011000 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 5#core:StatusState = "available" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:EcoRoomTemperatureState = 2.5 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:TensionState = 235 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:DryingDurationState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:DryingDurationUserParameterState = 60 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:BoostDurationUserParameterState = 30 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 4#core:PowerSourceType = "mainSupply" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:OccupancyState = 0 [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:ManufacturerNameState = "Thermor" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:TargetHeatingLevelState = "comfort" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 3#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 2#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 2#core:Manufacturer = "Atlantic Group" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 7#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 6#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [16:29:00] [DEBUG] [QUICKAPP1001]: 1#io:AutoProgramState = {"saturday":["CONF_3_NIV1","CONF_3_NIV1","CONF_3_NIV1","CONF_3_NIV1","CONF_3_NIV It only collects keys with the uid and prefixes the keys with the number after # Then you can do print(keys['1#core:ComfortRoomTemperatureState']) The problem with the previous statement ssConsi = (find('name','core:ComfortRoomTemperatureState',find('deviceURL','io://0810%-4343%-0200/13610533..',jsonResponse.devices).states).value) -- #1 OK is that if <uid>#1 and <uid>#2 both have the key 'core:ComfortRoomTemperatureState' we just get the first random - but we should return both. With the new find taking the uid you can ask for the specfic uid number in the result Ex. '1#core:ComfortRoomTemperatureState' of uid "io://0810-4343-0200/13610533" Will that work?
  3. jang

    Table Json

    or if you want to see all keys keys = find(jsonResponse.devices) for k,v in pairs(keys) do print(k,"=",json.encode(v)) end output [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:TimeProgramState = [{"monday":[{"end":"19:30","start":"18:15"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"tuesday":[{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"wednesday":[{"end":"19:30","start":"18:15"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"thursday":[{"end":"19:30","start":"18:15"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"friday":[{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"saturday":[{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]},{"sunday":[{"end":"19:30","start":"18:00"},{"end":"00:00","start":"00:00"},{"end":"00:00","start":"00:00"}]}] [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:LocalLeadTimeState = 3154 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:FirmwareRevision = "2d202020ffffff210002" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:VersionState = "2d202020ffffff210002" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:ComfortRoomTemperatureState = 19 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:LocalIPv4AddressState = "192.168.1.15" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:RegulationModeState = "none" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:DryingDurationState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:RSSILevelState = 76 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:TensionState = 235 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:MaximumHeatingLevelState = "unknown" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:RelativeHumidityState = 49 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:AutoProgramState = {"thursday":["CONF_3_NIV1",....} [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:ElectricEnergyConsumptionState = 1748000 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:StatusState = "available" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:TemperatureState = 20.5 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:InternalExternalSchedulingTypeState = "internal" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:NameState = "I2G_Actuator" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:OperatingModeState = "external" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:BoostDurationUserParameterState = 60 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:CountryCodeState = "FR" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:ManufacturerNameState = "Thermor" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:MeasuredValueType = "core:TemperatureInCelcius" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:PowerSourceType = "mainSupply" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:FilterFanCloggingErrorState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:DerogatedTargetTemperatureState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:EffectiveTemperatureSetpointState = 14 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:BoostModeDurationState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:OccupancyState = "noPersonInside" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:OnOffState = "on" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:EcoRoomTemperatureState = 5 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:CurrentWorkingRateState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:TowelDryerTemporaryStateState = "permanentHeating" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:ModelState = "Symphonik Gauche" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:DryingDurationMaxState = 120 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:DryingDurationUserParameterState = 90 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:BoostDurationMaxState = 60 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:TargetTemperatureState = 19 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:TargetHeatingLevelState = "eco" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:LuminanceState = 21 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:TimerForTransitoryStateState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:ControllerAddressState = 15984323 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:IdentifierState = "00000000" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:CumulatedLoweringState = 19 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:DiscreteRSSILevelState = "normal" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:PriorityLockTimerState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:TemperatureProbeCalibrationOffsetState = 0 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:Manufacturer = "Atlantic Group" [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:PowerState = 1750 [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: core:DateTimeState = {"weekday":3,"hour":11,"second":48,"minute":48,"month":12,"year":2022,"day":1} [03.12.2022] [10:30:53] [DEBUG] [QUICKAPP1001]: io:SetpointLoweringTemperatureInProgModeState = 5
  4. jang

    Table Json

    Maybe just collect all the keys starting with "io:" and "core:" ? local function find(expr) local res = {} local function find_aux(expr) if type(expr) == 'table' then if expr[1] then -- array for _,e in ipairs(expr) do find_aux(e) end else -- key/value if expr.name and (expr.name:sub(1,3)=='io:' or expr.name:sub(1,5)=='core:') and expr.value then res[expr.name]=expr.value else for k,v in pairs(expr) do find_aux(v) end end end end end find_aux(expr) return res end keys = find(jsonResponse.devices) print('io:TargetHeatingLevelState=',keys['io:TargetHeatingLevelState']) print('core:RSSILevelState=',keys['core:RSSILevelState']) print('core:LuminanceState=',keys['core:LuminanceState']) print('core:RelativeHumidityState=',keys['core:RelativeHumidityState']) print('core:TemperatureState=',keys['core:TemperatureState']) print('core:ElectricEnergyConsumptionState=',keys['core:ElectricEnergyConsumptionState']) Output [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: io:TargetHeatingLevelState= eco [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: core:RSSILevelState= 76.0 [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: core:LuminanceState= 21 [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: core:RelativeHumidityState= 49.0 [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: core:TemperatureState= 20.5 [02.12.2022] [23:33:07] [DEBUG] [QUICKAPP1001]: core:ElectricEnergyConsumptionState= 1748000
  5. jang

    Table Json

    local function find(key,val,list) for _,e in ipairs(list) do if tostring(e[key]):match( then return e end end end print(find('name','io:TargetHeatingLevelState',find('deviceURL','io://0810%-4343%-0200/13610533..',jsonResponse.devices).states).value) You need to quote '-' in the val string ex. '%-' Also, you match any character is with '.' dot, so '..' will match "#1" Is this what you need?
  6. jang

    Table Json

    local function find(key,val,list) for _,e in ipairs(list) do if e[key]==val then return e end end end print(find('name','io:TargetHeatingLevelState',find('deviceURL','io://0810-4343-0200/13610533#1',jsonResponse.devices).states).value)
  7. jang

    Fonction globale/centrale sous HC3

    This kind of works - it's not super efficient but for functions used once in a while it's ok. The library, ex QA with id 1061 function foo(a,b) return a+b end function bar(a,b) return a*b end -------------------------------------------------- function QuickApp:RPC_CALL(path2,var2,n2,fun,args,qaf) local res if qaf then res = {n2,pcall(self[fun],self,table.unpack(args))} else res = {n2,pcall(_G[fun],table.unpack(args))} end api.put(path2,{name=var2, value=res}) end function print() end Then the client QA do -- could be hidden in a separate QA file local var,cid,n = "RPC"..plugin.mainDeviceId,plugin.mainDeviceId,0 local vinit,path = { name=var, value=""},"/plugins/"..cid.."/variables/"..var api.post("/plugins/"..cid.."/variables",{ name=var, value=""}) -- create var if not exist function fibaro._rpc(id,fun,args,timeout,qaf) n = n + 1 api.put(path,vinit) fibaro.call(id,"RPC_CALL",path,var,n,fun,args,qaf) timeout = os.time()+(timeout or 3) while os.time() < timeout do local r,_ = api.get(path) if r and r.value~="" then r = r.value if r[1] == n then if not r[2] then error(r[3],3) else return select(3,table.unpack(r)) end end end end error(string.format("RPC timeout %s:%d",fun,id),3) end function fibaro.rpc(id,name,timeout) return function(...) return fibaro._rpc(id,name,{...},timeout) end end end local foo = fibaro.rpc(1061,'foo') -- create function for remote function in QA 1061 with name foo local bar = fibaro.rpc(1061,'bar') -- create function for remote function in QA 1061 with name bar function QuickApp:onInit() self:debug("onInit") print(foo(2,4)) print(bar(2,4)) end 100 calls to foo(10,29) takes ~3s, so around 0.03s per call...
  8. jang

    Requete HTTP pour modifier une variable globale

    For a given event it becomes <time to select relevant rule(s)> + <time to execute rule(s)> time-to-execute may be hard to do something about, but If you have a lot of trigger rules, time-to-select will increase, even if the event doesn't trigger any rule at all. It could be optimized by some smart hash-function with the event as the key and possible matching rules as the value, reducing the number of rules needed to be searched through and filtered. Another thing about GEA as I understand it, is that it runs the non-trigger rules every 30s. I guess that every 30s then there is a peak when all rules evaluate their tests - a peak that increase with the number of rules? Here again, and it's a bit more complicated, one could analyze the rule tests when the rules are defined to see what events they depend on. ...and then only invoke the rules that have tests that depends on what events have happened the last 30s. (treating also time as an event...)
  9. jang

    Questions de débutant en Quick Apps sur HC3

    -- TEST QA function QuickApp:onInit() self:debug("onInit") end local timer function QuickApp:Cligno_ON() self:setVariable("ClignoRouge", "ON") self.cligno = self:getVariable("ClignoRouge") self:trace("var cligno = "..cligno) if not timer then self:loop() end self:trace("Mise en marche du cligno via le bouton") end function QuickApp:Cligno_OFF() self:setVariable("ClignoRouge", "OFF") self.cligno = self:getVariable("ClignoRouge") self:trace("var cligno = "..cligno) if timer then timer=fibaro.clearTimeout(timer) end self:trace("Mise en arret du cligno via le bouton") end ---------------------------------------------------------- --- Boucle loop ---------------------------------------------------------- function QuickApp:loop() self:trace("loop") hub.sleep(1000) hub.call(79, 'turnOn') hub.sleep(1000) hub.call(79, 'turnOff') timer = fibaro.setTimeout(2000, function() self:loop() end) end
  10. jang

    Les variables dans un Quick App

    function fibaro.getQAVariable(id,name) __assert_type(id,"number") __assert_type(name,"string") local props = (api.get("/devices/"..id) or {}).properties or {} for _, v in ipairs(props.quickAppVariables or {}) do if v.name==name then return v.value end end end function fibaro.setQAVariable(id,name,value) __assert_type(id,"number") __assert_type(name,"string") return fibaro.call(id,"setVariable",name,value) end function fibaro.getAllQAVariables(id) __assert_type(id,"number") local props = (api.get("/devices/"..id) or {}).properties or {} local res = {} for _, v in ipairs(props.quickAppVariables or {}) do res[v.name]=v.value end return res end Can be used from both Scenes and QuickApps
  11. jang

    Questions de débutant en Quick Apps sur HC3

    Your while loop will not give any time for button callbacks to call your Lua functions or update UI i.e. function QuickApp:Cligno_ON() and function QuickApp:Cligno_OFF() You need to use something like setTimeout to give time to your button handlers...
  12. jang

    Déclencheur Event QA HC3

    If you want "sourceTriggers" in your QA you can use https://forum.fibaro.com/topic/62600-detect-keyid-andor-keyattribute-in-a-qa-loop-from-a-device/?do=findComment&amp;comment=255490 Ex. for customEvents function QuickApp:sourceTrigger(event) -- callback for subscribed events print("Event:",event.name) end function QuickApp:onInit() self:debug("Started") self:clearSubscriptions() -- Every restart, re-subscribe self:subscribe({type='custom-event', name='E1'}) -- Subscribe to custom event self:subscribe({type='custom-event', name='E2'}) -- Subscribe to custom event end ----------- Helper functions -------------- function QuickApp:clearSubscriptions() self:setVariable('TRIGGER_SUB',{}) end function QuickApp:subscribe(event) local s = self:getVariable('TRIGGER_SUB') if type(s)~='table' then s = {} end s[#s+1]=event self:setVariable('TRIGGER_SUB',s) end
  13. jang

    tonumber et variable globale

    Sorry, 'time' was not necessary in the last example (cut&paste error...) Another example is json.decode that takes a second optional value in QAs, not in Scenes! They have different implementations. In QAs this will then give an error a = json.decode(fibaro.getGlobalVariable("X")) as json.decode will expect the second argument to be a table with parsing options, and in this case gets the modification time, and will throw an error. Solution, like the last example is a = json.decode((fibaro.getGlobalVariable("X")))
  14. jang

    tonumber et variable globale

    fibaro.getGlobalVariable returns 2 values. String value of variable and time it was last changed. Both these values are then passed to tonumber as arguments The problem is that tonumber can take a second argument, the base for the string->number conversion. In this case it will interpret the change time as the base which is probably out of range. You can throw away all but the first returned value by putting the expression within parentheses. UserIDA = tonumber (( fibaro.getGlobalVariable ( " UserIDA " ))) This will work...
  15. jang

    requette curl en fonction lua

    function QuickApp:pipup() self:debug("envoi du pipup") local data = { duration = "30", position = "2", -- 0 à 4 title = "Test PIPUP", titleColor = "#0066cc", titleSize = "20", message = "Message de Test Pipup", messageColor = "#000000", messageSize = "14", backgroundColor = "#ffffff", media = { image = { uri="https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png", width=480 } } } local pipup = net.HTTPClient():request("http://192.168.0.22:7979/notify",{ options = { method = "POST", headers = { ["Content-Type"] = "application/json" }, data = (json.encode(data)) }, success = function(response) self:debug(json.encode(response)) self:debug(json.encode(data)) end, error = function(err) self:error(err) end }) end
×