i use a simple dzvents script to turn my irrigation pump on if one or more of the zones is on and turn it off when all the zones are off.
Only one slight problem, i wanted to lower the wear on the relays and the pump by waiting 5 seconds before turning the pump off because most of the time when we switch zones we first turn the ones that are on off and then the new one on but that results in unnecessary power cycles of the pump and i do believe that that can not be good so i wanted to set a 5 to 10 second delay between all the zones off and the pump off but how i did it it apparently does not work.
my code:
Code: Select all
return {
on = {
devices = {
'Irrigatie zone 1',
'Irrigatie zone 2',
'Irrigatie zone 3',
'Irrigatie zone 4',
'Irrigatie zone 5',
'Irrigatie zone 6'
}
},
execute = function(dz, device)
local zone1 = dz.devices("Irrigatie zone 1")
local zone2 = dz.devices("Irrigatie zone 2")
local zone3 = dz.devices("Irrigatie zone 3")
local zone4 = dz.devices("Irrigatie zone 4")
local zone5 = dz.devices("Irrigatie zone 5")
local zone6 = dz.devices("Irrigatie zone 6")
local pomp = dz.devices("Irrigatie pomp")
if (pomp.state == "Off") and (zone1.state == "On") or (zone2.state == "On") or (zone3.state == "On") or (zone4.state == "On") or (zone5.state == "On") or (zone6.state == "On") then
pomp.switchOn()
elseif (pomp.state == "On") and (zone1.state == "Off") or (zone2.state == "Off") or (zone3.state == "Off") or (zone4.state == "Off") or (zone5.state == "Off") or (zone6.state == "Off") and pomp.lastUpdate.secondsAgo > 5 then
pomp.switchOff()
end
end
}