Logic Machine Forum
Help example on simple light controll, lux - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Help example on simple light controll, lux (/showthread.php?tid=1807)



Help example on simple light controll, lux - kenjirosama - 22.12.2018

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!


RE: Help example on simple light controll, lux - Daniel - 22.12.2018

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



RE: Help example on simple light controll, lux - kenjirosama - 22.12.2018

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.


RE: Help example on simple light controll, lux - Daniel - 22.12.2018

Yes there was stupid mistake in line 3 corrected the original script


RE: Help example on simple light controll, lux - kenjirosama - 22.12.2018

(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!!!


RE: Help example on simple light controll, lux - Joep - 14.03.2024

(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?


RE: Help example on simple light controll, lux - admin - 14.03.2024

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.


RE: Help example on simple light controll, lux - Joep - 14.03.2024

(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



RE: Help example on simple light controll, lux - admin - 14.03.2024

Either use storage to save the time when the script was run previously. Or use a scheduled script instead of event.


RE: Help example on simple light controll, lux - Joep - 14.03.2024

(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.


RE: Help example on simple light controll, lux - manos@dynamitec - 28.03.2024

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.


RE: Help example on simple light controll, lux - admin - 28.03.2024

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