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.

Staircase timer
#9
Create an event script for each PIR. It will only react when PIR sends true. In this case it will store current time in storage under unique key and will set output value to 90% if it's not already 90%. This is done by using checkwrite which does not pollute the bus with telegrams with duplicate values. Adjust output group address for each PIR script as needed.
Code:
if event.getvalue() then
  key = 'pir_timer_' .. event.dst
  now = os.time()
  storage.set(key, now)
  grp.checkwrite('2/1/1', 90)
end

Create a resident script which will monitor PIR timers and will set output values as needed. Tune sleep interval as needed, don't use 0, otherwise it will consume all system resources. If you really need to wait 30/60 minutes after last movement detection then you can use maximum sleep time of 60 seconds. You can add as many elements to pirs table as needed, input is PIR group address, output is your dimmer. You need to disable/enable the script if you change pirs table.
Code:
if not pirs then
  pirs = {
    { input = '1/1/1', output = '2/1/1' },
    { input = '1/1/2', output = '2/1/2' },
  }
end

now = os.time()
for _, pir in ipairs(pirs) do
  key = 'pir_timer_' .. pir.input
  delta = now - storage.get(key, 0)

  -- set output to 0% after 1 hour
  if delta > 60 * 60 then
    grp.checkwrite(pir.output, 0)
  -- set output to 20% after 30 minutes
  elseif delta > 30 * 60 then
    grp.checkwrite(pir.output, 20)
  end
end
Reply


Messages In This Thread
Staircase timer - by Kuronen - 03.08.2017, 08:05
RE: Staircase timer - by AEK - 03.08.2017, 08:45
RE: Staircase timer - by Kuronen - 03.08.2017, 10:42
RE: Staircase timer - by Erwin van der Zwart - 03.08.2017, 11:05
RE: Staircase timer - by Kuronen - 03.08.2017, 12:19
RE: Staircase timer - by Kuronen - 03.08.2017, 17:30
RE: Staircase timer - by Erwin van der Zwart - 03.08.2017, 20:03
RE: Staircase timer - by Kuronen - 03.08.2017, 20:36
RE: Staircase timer - by admin - 04.08.2017, 08:06

Forum Jump: