This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Help example on simple light controll, lux
#12
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
Reply


Messages In This Thread
RE: Help example on simple light controll, lux - by admin - 28.03.2024, 11:01

Forum Jump: