Logic Machine Forum
Set / reset circuit with timer - 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: Set / reset circuit with timer (/showthread.php?tid=2788)



Set / reset circuit with timer - tennung - 11.08.2020

Hi
Im looking for a simple script.

Input 1 - KNX 0/2/5
Input 2 - KNX 0/2/6
Input 3 - KNX 0/2/7 (same as output)
Output - KNX 0/2/7 (same as input 3)

If input 1 sends 1 to the bus it will set the output to 1 and start a timer for 2 hours. After the timer ends the output is set to 0. A new input will restart the timer.
If input 2 sends 1 to the bus it will stop the timer.
If input 3 sends 0 to the bus it will stop the timer.

Can someone point me in the right direction?


RE: Set / reset circuit with timer - admin - 12.08.2020

For the timer you need a scheduled script that runs every minute. It check if the object is in ON state and sends off if the object has not been updated in 2 hour time.
Code:
obj = grp.find('0/2/7')
now = os.time() -- current timestamp in seconds
delta = now - obj.updatetime -- last object update relative time

if obj.value and delta > (2 * 60 * 60) then
  obj:write(false)
end

You will need two event scripts.

0/2/5 (turn 0/2/7 ON when ON is received):
Code:
value = event.getvalue()
if value then
  grp.write('0/2/7', true)
end

0/2/6 (turn 0/2/7 OFF when ON is received):
Code:
value = event.getvalue()
if value then
  grp.write('0/2/7', false)
end



RE: Set / reset circuit with timer - tennung - 23.08.2020

Thank you for the reply! This script is for my garden gate.
I've been playing with this and the code provided is that this is supposed to integrate with an existing KNX installation where 0/2/6 is a telegram that "locks" the gate in an unlocked state, and 0/2/7 is a telegram that removes this lock and returns the operation to normal.
0/2/5 is a spare trigger that first sends a 1, then a 0 when operated - currently not doing anything.

So what I' m trying to do is use this spare trigger to make a 2 hour unlocked gate function if that makes sense? I need to be able to reset the timer and bring the gate back to normal operation or to permanent unlock during the timer period.


RE: Set / reset circuit with timer - Daniel - 24.08.2020

For irrigation you may want to use this
https://forum.logicmachine.net/showthread.php?tid=362&pid=8161#pid8161


RE: Set / reset circuit with timer - tennung - 24.08.2020

If I adjust the first code, will this work?
Code:
obj1 = grp.find('0/2/6') -- "lock"
obj2 = grp.find('0/2/7') -- "normal"
obj3 = grp.find('0/2/5') -- "2 hour lock"

now = os.time() -- current timestamp in seconds
delta1 = now - obj1.updatetime -- last object update relative time
delta2 = now - obj2.updatetime -- last object update relative time
delta3 = now - obj3.updatetime -- last object update relative time

if (delta1 > delta3) and (obj2.value and delta2 > (2 * 60 * 60))  then
  obj2:write(false)
end



RE: Set / reset circuit with timer - admin - 25.08.2020

Your code does not check 0/2/6 and 0/2/5 values, only their update time. Some extra if's are needed there. You need to correctly define the logic of operation then it will be easy to write a script for that.


RE: Set / reset circuit with timer - Dré - 21.03.2021

(12.08.2020, 09:33)admin Wrote: For the timer you need a scheduled script that runs every minute. It check if the object is in ON state and sends off if the object has not been updated in 2 hour time.
Code:
obj = grp.find('0/2/7')
now = os.time() -- current timestamp in seconds
delta = now - obj.updatetime -- last object update relative time

if obj.value and delta > (2 * 60 * 60) then
  obj:write(false)
end

Sorry TS
Thank you this is exactly what i was looking for.
I will use this for occupancy detector, light go on by movement, and go to 20% dimming by no movement for 10 minutes.
But when burgely alarm is on (nobody is in the boulding) light need to turn off.
My question, is it possible to disable a 'scheduled script' by a knx object or do i have to implement it in the script?


Or is it better to open a new topic?


RE: Set / reset circuit with timer - admin - 22.03.2021

It's easier to implement this in the script like this:
Code:
lock = grp.getvalue('1/2/3')
if lock then
  return
end
But in this case I see no problem because this script turns off the light. And if the light is already turned off before that then nothing happens.


RE: Set / reset circuit with timer - Dré - 22.03.2021

Well almost, at day, the light need to go to 20% after no movement of 10 minutes.
When everybody is gone, and alarm turns on, all lights need to turn off.

But when it isnt posible i have to do it with a extra line in the script.
I have multiple of this, in the same project, so i have to copy past it for 40 times.