Logic Machine Forum
Gate opener optimization - 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: Gate opener optimization (/showthread.php?tid=4672)



Gate opener optimization - Novodk - 23.03.2023

Hey

I have made this script to open and close my gate, it works almost all the time Smile

I'm not a programmer at all, so maybe someone can tell me if there is a better/easier/more correct way to make it work 100% all the time.

I have a 4x knx relay where I only use 3 relays

First one (2/2/0) is to control a contactor that  supplies power to a big 3x400vAC to 24vDC transformer.

Second one (2/2/2) is to tell my actuators to close.

Third one (2/2/4) is to tell my actuators to open.

32/1/1 is just to open a widget with the controls.
32/1/4 is to show the status of the gate, open or closed

There is mechanical stops on the gate if it hits something.

Code:
close = event.getvalue()
status = grp.getvalue('32/1/4')


if close== true and
  status== false then
  grp.write('2/2/0', 'true')
  os.sleep(1.5)
  grp.write('2/2/2', 'true')
  os.sleep(12)
  grp.write('2/2/2', false)
  os.sleep(1.5)
  grp.write('2/2/0', false)
  grp.update('32/1/2', false)
  grp.update('32/1/4', true)

    elseif
 
  grp.getvalue('32/1/2')
 
  then
 
  grp.update('32/1/2', false)
 
  end

Code:
open = event.getvalue()
status = grp.getvalue('32/1/4')


if open== true and
  status== true then
  grp.write('2/2/0', 'true')
  os.sleep(1.5)
  grp.write('2/2/4', 'true')
  os.sleep(12)
  grp.write('2/2/4', false)
  os.sleep(1.5)
  grp.write('2/2/0', false)
  grp.update('32/1/3', false)
  grp.update('32/1/4', false)
 
  elseif
 
  grp.getvalue('32/1/3')
 
  then
 
  grp.update('32/1/3', false)
 
  end


[Image: rwd9zEx.png]


RE: Gate opener optimization - admin - 24.03.2023

What happens when the script is not working correctly? Maybe the start-up time for the power supply needs to be longer? The delay after the movement can be shorter.
The code looks correct, apart from 'true' in quotes. It works because non-empty string evaluates as boolean true. But if you write 'false' you will get true instead.