UPD: i moved all my rules to the new application (54 total) hope it won't break anything :-D
so regarding throttle, the following approach seems to be working, with the knowledge that i should use unique names per each script
"In" event:
user library:
SUGGESTION:
1) in error log make it obvious which script contains error, so i can fix it easily. For example this error does not have information where to look:
so regarding throttle, the following approach seems to be working, with the knowledge that i should use unique names per each script
"In" event:
Code:
ls_bedroom_throttle = ls_bedroom_throttle or require('user.mqttclient_common').throttle(60)
local data = json.pdecode(payload)
if type(data) == 'table' then
return ls_bedroom_throttle(data.illuminance)
end
user library:
Code:
return {
throttle = function(timeout)
local last_update = 0
return function(val)
if(val ~= nil) then
local now = os.time()
if((now - last_update) < timeout) then
return nil
else
last_update = now
return val
end
end
end
end
}
SUGGESTION:
1) in error log make it obvious which script contains error, so i can fix it easily. For example this error does not have information where to look:
Quote:error: failed to run script - [string "in-26"]:9: attempt to compare nil with number2) output errors in global error log so they can be noticed in time