04.08.2017, 08:06
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.
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 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