28.03.2024, 11:01
Try this (untested):
Code:
min = 10
max = 100
hysteresis = 20
delay = 0.1
lights = {
{ active = '0/0/211', current = '3/0/11', setpoint = '3/1/11', status = '2/4/11', output = '3/3/11' },
{ active = '0/0/212', current = '3/0/12', setpoint = '3/1/12', status = '2/4/12', output = '3/3/12' },
}
function lightcontrol(opts)
if not grp.getvalue(opts.active) then
return
end
local current = grp.getvalue(opts.current) -- Area Lux Value
local setpoint = grp.getvalue(opts.setpoint) -- Area Lux Setpoint Value
if math.abs(current - setpoint) < hysteresis then
return
end
local status = grp.getvalue(opts.status) -- Status dim value
if status == 0 then
return
end
local diva_up = math.min(status + 5, max)
local diva_down = math.max(status - 5, min)
if current < setpoint then
grp.checkwrite(output, diva_up)
elseif current > setpoint then
grp.checkwrite(output, diva_down)
end
end
for _, light in ipairs(lights) do
lightcontrol(light)
os.sleep(delay)
end