Logic Machine Forum
not working script with timer - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: not working script with timer (/showthread.php?tid=1354)



not working script with timer - AlexLV - 24.04.2018

Hello,

please help me find error. Task - when light in bathroom is off - i want swith on ventilation for 10 minutes. Found timer script at forum, but something is wrong in my script. Group 0/2/1 is 1 when light is Off and 0/2/1 is 0  when light is On. 6/0/1 and 6/0/2 switch On/Off ventilator. When light is off, ventilator starting but not switching off... May be problem is that 0/2/1 is always =1 till light is Off??

-- group address or name Vanna light on/off
addr = '0/2/1'
 
-- find required object
obj = grp.find(addr)
 
-- object exists and current state is "on"
if obj and obj.data then -- I think my problem is here but how to change correctly?
  -- delta is in seconds
  delta = os.time() - obj.updatetime
 grp.write('6/0/1', 1)
 grp.write('6/0/2', 1)
  -- switch off when timer expires
  if delta >= 10 * 60 then
    log(os.time())
  log(delta)
  log(obj.updatetime)
 grp.write('6/0/1', 0)
 grp.write('6/0/2', 0)
  end
end


RE: not working script with timer - admin - 25.04.2018

If your light status object is inverse you need to add not:
Code:
if obj and not obj.data then



RE: not working script with timer - AlexLV - 25.04.2018

I added inverse, but anyway something is not correct - timer not working.When light is off, ventilator starting, but not stopping...I put less time, 1 minute, but the same..

What could be wrong?


RE: not working script with timer - admin - 25.04.2018

Is it a resident or a scheduled script?


RE: not working script with timer - AlexLV - 25.04.2018

sorry it is event-based... It shoudbe resident?


RE: not working script with timer - Daniel - 25.04.2018

Hi
Do it like that.
Resident script with interval as you want. This will decide how fast it will switch on and off from receiving false
Code:
addr = '0/2/1'
addrVent1 = '6/0/1'
addrVent2 = '6/0/2'
timer = 600
-----------------------------------------------
obj = grp.find(addr)
delta = os.time() - obj.updatetime
if obj and not obj.data and delta < timer then
 grp.checkwrite(addrVent1, true)
 grp.checkwrite(addrVent2, true)
elseif obj and not obj.data and delta >= timer then  
 grp.checkwrite(addrVent1, false)
 grp.checkwrite(addrVent2, false)
end
BR


RE: not working script with timer - AlexLV - 25.04.2018

Daniel,

BIG THANKS!

All is working as needed!