08.03.2018, 12:46
1. Add tag valve to your valve objects. Create an event script that is mapped to valve tag:
2. Create either a resident script with large sleep time or a scheduled script that runs every minute:
In both scripts replace pump with pump object name or group address.
Code:
-- get OR'ed value of all tagged objects
value = false
objects = grp.tag('valve')
for _, object in ipairs(objects) do
value = value or object.value
end
if value then
-- save pump timer if timer has not been started yet
time = storage.get('pump_on_time', 0)
if time == 0 then
storage.set('pump_on_time', os.time())
end
else
-- turn pump off
storage.set('pump_on_time', 0)
grp.checkwrite('pump', false)
end
2. Create either a resident script with large sleep time or a scheduled script that runs every minute:
Code:
-- turn pump on when time delta >= 5 minutes
time = storage.get('pump_on_time', 0)
if time > 0 then
delta = os.time() - time
if delta >= 5 * 60 then
grp.checkwrite('pump', true)
end
else
grp.checkwrite('pump', false)
end
In both scripts replace pump with pump object name or group address.