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
#1
Hi.

I am new to this type of programming and had no problem with the block programing they used before but the fb is simply not working for me. 

I am trying to controll my light to go on below X LUX and of above Y lux. 
I simply doesnt get it to work. 

Any ideas? Huh

Thanks!
Reply
#2
Try this

Code:
lux = grp.getvalue('1/1/1')
setpoint = grp.getvalue('1/1/2')
output = '1/1/3'
hysteresis = 20 --in %

 
Limit_ON = setpoint - ((hysteresis/100)*setpoint)
Limit_OFF = setpoint + ((hysteresis/100)*setpoint)
 
if (lux >= Limit_OFF) then
   grp.checkwrite(output, false)
elseif  (lux <= Limit_ON) then
     grp.checkwrite(output, true)
end
------------------------------
Ctrl+F5
Reply
#3
Thank you very much for your reply!

Unfortunately I dont get it to work. 
created a resident script with the code and changed the adresses but doesnt look like the output changes regarldess of lux or input. 
I am probably doing something wrong but I dont know what.
Reply
#4
Yes there was stupid mistake in line 3 corrected the original script
------------------------------
Ctrl+F5
Reply
#5
(22.12.2018, 18:36)Daniel. Wrote: Yes there was stupid mistake in line 3 corrected the original script

Works perfectly! Thank you so much!!!
Reply
#6
(22.12.2018, 17:54)Daniel Wrote: Try this

Code:
lux = grp.getvalue('1/1/1')
setpoint = grp.getvalue('1/1/2')
output = '1/1/3'
hysteresis = 20 --in %

 
Limit_ON = setpoint - ((hysteresis/100)*setpoint)
Limit_OFF = setpoint + ((hysteresis/100)*setpoint)
 
if (lux >= Limit_OFF) then
   grp.checkwrite(output, false)
elseif  (lux <= Limit_ON) then
     grp.checkwrite(output, true)
end

I would like to replace the hysteresis from this script for a time period. So let's say i want an hysteresis for 30 minutes how can this be done?
Reply
#7
You can use grp.find() and updatetime field to check when the last telegram was sent to this specific object. Then use os.time() to calculate the delta.
Alternative solution is to use a scheduled script that runs every X minutes.
Reply
#8
(14.03.2024, 09:26)admin Wrote: You can use grp.find() and updatetime field to check when the last telegram was sent to this specific object. Then use os.time() to calculate the delta.
Alternative solution is to use a scheduled script that runs every X minutes.

Hi admin that will not work for me as the updatetime of the object is changing all the time.
Code:
lux = grp.getvalue('1/0/3')
azimut = grp.getvalue('5/5/2')
alarm = grp.getvalue('4/0/1')

hysterese = 10

if alarm == false then
    if lux > 700 then
      if azimut > 95 and azimut < 150 then
        grp.write('2/3/1', 100)
        grp.write('2/3/2', 0)
        grp.write('2/3/6', 0)
      elseif azimut > 180 and azimut < 230 then
        grp.write('2/3/1', 0)
        grp.write('2/3/2', 100)
        grp.write('2/3/6', 0)
      elseif azimut > 230 and azimut < 280 then
        grp.write('2/3/1', 0)
        grp.write('2/3/2', 0)
        grp.write('2/3/6', 100)
      else
        grp.write('2/3/1', 0)
        grp.write('2/3/2', 0)
        grp.write('2/3/6', 0)
      end
    elseif lux < 500 then

          object = grp.find('1/0/3')
          time = object.updatetime -- time will change every time the object is updated

      grp.write('2/3/1', 0)
      grp.write('2/3/2', 0)
      grp.write('2/3/6', 0)
    end
end
Reply
#9
Either use storage to save the time when the script was run previously. Or use a scheduled script instead of event.
Reply
#10
(14.03.2024, 09:49)admin Wrote: Either use storage to save the time when the script was run previously. Or use a scheduled script instead of event.

ok clear thanks.
Reply
#11
Hello Admin,

I have a project where I want to use the script below to do a simple light control in steps. Can you please help me to achieve the same functionality but for multiple lights groups.
This will be a resident script with sleep time 10sec. I was thinking if I can create a table to map all variables and then a function to execute every 10sec. Or any better idea

Code:
------Global Settings---------
min = 10
max = 100
hysteresis = 20

--------Light Group 1---------
local current = grp.getvalue('3/0/11')    --Area Lux Value
local setpoint = grp.getvalue('3/1/11')    --Area Lux Setpoint Value
local output = '3/3/11'            --Dim output
local active = grp.getvalue('0/0/211')    --Light Control is active or not
local disv = grp.getvalue('2/4/11')    --Status dim value
local deltasc = setpoint - current            
local deadband = math.abs(deltasc) < hysteresis
local diva_up = disv + 5
local diva_down = disv - 5
local diva_up = math.min(diva_up, max)
local diva_down = math.max(diva_down, min)


if active and not deadband then
  if disv ~= 0 then
      if current < setpoint then
    grp.checkwrite(output, diva_up)
    elseif current > setpoint then
    grp.checkwrite(output, diva_down)
    end 
  end
end


--------Light Group 2----------
local current = grp.getvalue('3/0/12')
local setpoint = grp.getvalue('3/1/12')
local output = '3/3/12'
local active = grp.getvalue('0/0/212')
local disv = grp.getvalue('2/4/12')
local deltasc = setpoint - current
local deadband = math.abs(deltasc) < hysteresis
local    diva_up = disv + 5
local    diva_down = disv - 5
local diva_up = math.min(diva_up, max)
local diva_down = math.max(diva_down, min)

if active and not deadband then
  if disv ~= 0 then
      if current < setpoint then
    grp.checkwrite(output, diva_up)

    elseif current > setpoint then
    grp.checkwrite(output, diva_down)
    end 
  end
end

Thank you in advance.
Reply
#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


Forum Jump: