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.

shutter timer based on detector
#1
Hello guys i need your help with a script!
i want if movement detector not trigger  after 5 minutes to close a a shutter but if trigger on with in the 5 minutes timer restarts 
anyone can help me ?
Thank You in advance !
Reply
#2
https://kb.logicmachine.net/scripting/staircase-timer/
------------------------------
Ctrl+F5
Reply
#3
Also this: https://forum.logicmachine.net/showthread.php?tid=5700
Reply
#4
(03.02.2025, 09:50)admin Wrote: Also this: https://forum.logicmachine.net/showthread.php?tid=5700

i only want the detector only to close it. 
Thank you in advance!
Reply
#5
Resident script with 0 sleep time. Modify input/output objects (0/0/1 and 0/0/3 in this example) and offvalue value as needed.
Code:
if not client then
  timers = {
    ['0/0/1'] = {
      output = '0/0/3', -- output value object
      timeout = 300, -- timeout in seconds
      onvalue = nil, -- value to send when timer is turned on (nil to disable)
      offvalue = true, -- value to send when timer is turned off (nil to disable)
    },
  }

  function timerset(timer, value, ticks)
    timer.ticks = ticks
    grp.write(timer.output, value)
  end

  grp.sender = 'tm'

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    local timer = timers[ event.dst ]
    if timer and event.sender ~= grp.sender then
      local value = tonumber(event.datahex, 16) or 0
      if value == 1 then
        timerset(timer, timer.onvalue, timer.timeout)
      end
    end
  end)
end

client:loop(1)

for _, timer in pairs(timers) do
  if timer.ticks then
    timer.ticks = timer.ticks - 1

    if timer.ticks == 0 then
      timerset(timer, timer.offvalue)
    end
  end
end
Reply


Forum Jump: