22.01.2016, 07:58
Another timer example.
Task: If there is 0 sent to grp address AND it stays for 30 min at this value, switch on relay for 3 min. This is used in sauna installation to drain water after sauning is finished.
Event script, input is binary object:
Scheduled script - run every minute:
Task: If there is 0 sent to grp address AND it stays for 30 min at this value, switch on relay for 3 min. This is used in sauna installation to drain water after sauning is finished.
Event script, input is binary object:
Code:
value = event.getvalue()
-- turn off timer and turn relay off
if value then
storage.delete('timer')
grp.write('1/1/1', false)
-- start timer if not already started
else
timer = storage.get('timer')
if not timer then
storage.set('timer', 0)
end
end
Scheduled script - run every minute:
Code:
-- check if timer is running
timer = storage.get('timer')
if timer then
timer = timer + 1
timer.set('timer', timer)
-- turn relay on after 30 minutes
if timer == 30 then
grp.write('1/1/1', true)
-- turn relay off after 33 minutes
elseif timer == 33 then
grp.write('1/1/1', false)
end
end