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.

Script Guidance - Auto / On / Off, Lux Condition
#1
Hi,

Looking to script a setup that includes the following, any guidance appreciated...

Mode 0/0/1 -> Off (0) / Auto (127) / On (255) group address (with level noted in brackets).
Lux 0/0/2 -> from brightness sensor.
Setpoint 0/0/3 -> group address set via LM interface.
Output or Lights 0/0/4 -> group address for relay or dimmer etc.
Delay in seconds -> variable set above script.

Function/Script:

When Mode at 'Off' level (0), turn Output Off.

When Mode at 'Auto' level (127) it contentiously loops with comparing Setpoint to Lux group address... 
  When Lux below Setpoint, Output group immediately On if Output currently Off.
  When Lux above Setpoint, after a Delay if Setpoint continues to stay above Lux, Output group Off if Output currently On.

When Mode at 'On' level (255), turn Output On.

Thank you
Reply
#2
Hello

Here will be two event scripts
first - mode script

Code:
local mode = event.getvalue()

local output_addr = '0/0/4'

if mode == 0 then
  grp.write(output_addr, false)
elseif mode == 255 then
  grp.write(output_addr, true)
end

second - lux script

Code:
local lux = event.getvalue()

local delay = 3 -- seconds

local mode_addr = '0/0/1'
local lux_addr = '0/0/2'
local setpoint_addr = '0/0/3'
local output_addr = '0/0/4'

local mode = grp.getvalue(mode_addr)
local setpoint_lux = grp.getvalue(setpoint_addr)

if mode == 127 then
  if lux < setpoint_lux then
    grp.write(output_addr, true)
  elseif lux > setpoint_lux then
    os.sleep(delay)
   
    lux = grp.getvalue(lux_addr)
    setpoint_lux = grp.getvalue(setpoint_addr)
    if lux > setpoint_lux then
      grp.checkwrite(output_addr, false)
    end
  end
end
Reply
#3
Thanks, that looks quite concise.
Is it difficult to script it so the delay starts again whenever the Lux drops below the Setpoint?
Reply
#4
Do you mean something like this?

Code:
local lux = event.getvalue()

local delay = 3 -- seconds

local mode_addr = '49/1/1'
local lux_addr = '49/1/2'
local setpoint_addr = '49/1/3'
local output_addr = '49/1/4'

local mode = grp.getvalue(mode_addr)
local setpoint_lux = grp.getvalue(setpoint_addr)

if mode == 127 then
  if lux < setpoint_lux then
    os.sleep(delay) 

    lux = grp.getvalue(lux_addr)
    setpoint_lux = grp.getvalue(setpoint_addr)
    if lux < setpoint_lux then
      grp.write(output_addr, true)
    end
  elseif lux > setpoint_lux then
    os.sleep(delay)
   
    lux = grp.getvalue(lux_addr)
    setpoint_lux = grp.getvalue(setpoint_addr)
    if lux > setpoint_lux then
      grp.checkwrite(output_addr, false)
    end
  end
end
Reply


Forum Jump: