I recently added a lot (10?) of virtual sensors, and I started to have a system less stable than before. Someone remember that I had to completely turn off my virtual RGB lights from being sync’d, because sending the color every 15 minutes will cause luup reloads.
Anyway, this is true with general variableset as well. So, I wrote this simple handler:
function lr_updateVar(lul_request, lul_parameters, lul_outputformat)
local serviceId = lul_parameters["serviceId"]
local variable = lul_parameters["Variable"]
local value = lul_parameters["Value"] or ''
local devNum = tonumber(lul_parameters["DeviceNum"], 10)
local updated, newValue = setVar(serviceId, variable, value, devNum)
luup.log(string.format('[lr_updateVar] %s - %s - %s - %s - %s - %s', serviceId, variable, tostring(devNum), value, newValue or '', tostring(updated)))
return tostring(updated), "application/json"
end
Where setVar is preventing from writing the current value again:
function setVar(sid, name, val, devNum)
val = (val == nil) and "" or tostring(val)
local s = (luup.variable_get(sid, name, devNum)) or ""
if s ~= val then
luup.variable_set(sid, name, val, devNum)
return true, s
end
return false, s
end
And then the handler is registered at your startup:
luup.register_handler("lr_updateVar", "updateVar")
This could be called as variableset (same parameters):
After 2 days, I have a stable system again (12+ hours of luup engine uptime, vs 2-3 before). There’s memory leak for sure in this area with frequent writes. Hope this helps someone else.