26.07.2017, 10:03
os.sleep does not produce any CPU load. The problem is that each event runs separately and you can end with many copies running at the same time.
One of possible solutions:
Put the latest PIR trigger timer into storage (event script, add a check if PIR is ON):
Check timer expiration (resident script, tune sleep time as needed)
One of possible solutions:
Put the latest PIR trigger timer into storage (event script, add a check if PIR is ON):
Code:
storage.set('pir_timer', os.time())
Check timer expiration (resident script, tune sleep time as needed)
Code:
delta = os.time() - storage.get('pir_timer', 0)
if delta >= 120 then
-- do some action here
end