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.

not working script with timer
#1
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
Reply
#2
If your light status object is inverse you need to add not:
Code:
if obj and not obj.data then
Reply
#3
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?
Reply
#4
Is it a resident or a scheduled script?
Reply
#5
sorry it is event-based... It shoudbe resident?
Reply
#6
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
------------------------------
Ctrl+F5
Reply
#7
Daniel,

BIG THANKS!

All is working as needed!
Reply


Forum Jump: