irrigation pump  [Solved]

Easy to use, 100% Lua-based event scripting framework.
Post Reply
snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

irrigation pump

Post by snellejellep » Wednesday 13 June 2018 19:36

Hi,
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
}
i hope someone can help me figure this out.
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: irrigation pump

Post by snellejellep » Thursday 14 June 2018 21:23

i already found one mistake i made, that is in the elseif, i used or but that needs to be and.
i have a second problem now and that is that even if the pomp.state = on it does turn it on again and since that is a virtual switch with a http command attached to it it messes up the sync. i need it to turn on if one or more of the zones are on but if i switch zones for example i have 1,2 and 3 on and i switch 1 off and 4 on it magically updates the switch from on to on and sends the on http command again, unfortunately with the relay board i am using the on and off command are the same so it turns the pump off.

by the way, the above issue/wish is still " a thing".

my updated, still not perfect, 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")  and (zone2.state == "Off")  and (zone3.state == "Off")  and (zone4.state == "Off")  and (zone5.state == "Off")  and (zone6.state == "Off")  and pomp.lastUpdate.secondsAgo > 5 then
	        pomp.switchOff()
	    end
	    
	end
}
i hope someone can help, maby @waaren ?
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

devros
Posts: 174
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: irrigation pump

Post by devros » Thursday 14 June 2018 21:33

waaren did this great script for my irrigation, works great,

Code: Select all

--[[ Sprinkler.lua
 ]]--
 
return {
    on =        {   devices = { "zavlaha"  }  },
      
    logging =   {   level   = domoticz.LOG_DEBUG, 
                    marker = "zavlaha"},  

    execute = function(dz, trigger)

        local choice = trigger.levelName
        local sprinklerTime
        local delay = 1 --
        local description = trigger.description
        if description ~= nil and description ~= "" then
              _, _, sprinklerTime = string.find(description,"cas: (%d+)") 
        end
        sprinklerTime = sprinklerTime or 30
        
        local myValves = {"1Z", "2Z","3Z","4Z"}
        if choice ==  "Program" then
            for k,v in ipairs(myValves) do
                dz.devices(v).switchOn().afterSec(delay).forSec(sprinklerTime)
                delay = delay + 1
            end
            -- dz.devices("1Z").switchOn().forSec(sprinklerTime)
            -- dz.devices("2Z").switchOn().forSec(sprinklerTime).afterSec(sprinklerTime)
            -- dz.devices("3Z").switchOn().forSec(sprinklerTime).afterSec(sprinklerTime * 2)
            -- dz.devices("4Z").switchOn().forSec(sprinklerTime).afterSec(sprinklerTime * 3)
        elseif choice ==  "Off" then
            for k,v in ipairs(myValves) do
                dz.devices(v).switchOff().checkFirst()
            end
        else
            dz.devices(choice).switchOn().forSec(sprinklerTime)
        end
        trigger.switchOff().silent()
    end
}

snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: irrigation pump

Post by snellejellep » Thursday 14 June 2018 21:39

devros wrote:
Thursday 14 June 2018 21:33
waaren did this great script for my irrigation, works great,
i guess you are using a selector switch to select sprinkler zones and something to set a duration?
also i do not see a water pump being activated, you do use tap water?

for as far i can tell this is not really what i am looking for, i think, but thanks anyway! maby it is handy for someone?
or if you can explain a little how to implement based on my situation that would help.
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

FrankVZ
Posts: 35
Joined: Sunday 27 May 2018 12:01
Target OS: -
Domoticz version:
Contact:

Re: irrigation pump

Post by FrankVZ » Thursday 14 June 2018 23:00

I'm not your local script hero, but in general:
Don't switch pumps too often. It is bad for the pump (bearings, motorwindings/electornics). The relays are not the problem, normal relays are designed to switch over 10^6 times or so.
Normally your pump is completely worn out at that time.

Also: pumps do have huge startup amps. So think about what the savings really will be by switching them often.
If it is no pos displacement pump, please also take note that the current drawn is much less if there is no flow. Its consumed power depends on pressure, flow, medium. So if you really need that short irrigation periods, you better think of using valves with electrical actuators for each zone.

In general design, a maximum of 6 switch cycles per hour is a maximum. So far the engineering talk :)

With that in mind, you could leave your pump running a few minutes after one of the zones has been triggered OFF- that makes it much easier E.g. ".switchOff().afterSec(nn)"

hth.

User avatar
waaren
Posts: 709
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: irrigation pump  [Solved]

Post by waaren » Friday 15 June 2018 2:26

snellejellep wrote:
Wednesday 13 June 2018 19:36
... a 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.
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
@snellejellep,

can you try this one ?
description and setup in the commentlines

Code: Select all

--[[ irrigation.lua dzVents >= 2.4

requirements:  I use a 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. 

1.  Create a group "Irrigatie zones" with all the Irrigation zones in and nothing else. This group will only 
    be used to enable the script to loop over all the devices in that group. Effectively creating a set.
2.  Create a variable "Irrigatiepomp  vertraging"   setup -> more options -> uservariables (as integer)  
    This will be used to enable a delay when all zones stopped and make sure the pump only stops when no zones active


]]--

return {
    on  = {     devices   = { "Irrigatie zone *" },            -- Use wildcard to catch all zones
                variables = { "Irrigatiepomp  vertraging" }},  -- Need to be defined once via setup -> more options -> uservariables (as integer)
    
    logging =   {   level     =   domoticz.LOG_INFO,           -- Change to LOG_DEBUG to check what happens
                    marker    =   "irrigation"    },
                
    execute = function(dz, trigger)
        local irrigationActive
        local offDelay  =  60               -- Adjust to your needs
        local onDelay   =  2                -- Adjust to your needs 
        local delayVar  = dz.variables("Irrigatiepomp  vertraging")
        local pump      = dz.devices("Irrigatie pomp")
        
        local function activeZones()
            dz.groups("Irrigatie zones").devices().forEach(function(device) -- loop over all zones; all Irrigation zones must be defined in this group
                dz.log("Checking: " .. device.name .. " ; state: " .. device.state,dz.LOG_DEBUG) 
                if device.state == "On" then 
                    irrigationActive = true
                    return false                                            -- break out forEach if we found an active device
                end
            end)
            return irrigationActive
        end
       
        if trigger.isVariable and delayVar.value == 1 and not(activeZones()) then     -- No active zones for offDelay seconds ; switch pump Off
            dz.log("All zones still Off; I will switch pump off now",dz.LOG_DEBUG)  
            pump.switchOff().checkFirst()
            delayVar.set(0).silent()
        elseif trigger.isDevice and activeZones() then         -- At least 1 active zone' start pump when not already on
            dz.log("At least 1 zone active; I will switch pump on after " .. onDelay .. " sceonds if not already active" ,dz.LOG_DEBUG) 
            pump.switchOn().checkFirst().afterSec(onDelay) 
            delayVar.set(1).silent()
        elseif trigger.isDevice then                         -- Last active zone stopped
           dz.log("All zones Off; I will switch pump off after " ..  offDelay .. " seconds",dz.LOG_DEBUG)           
           delayVar.set(1).afterSec(offDelay)               -- Change var after offDelay seconds causing the script 
        end                                                  -- to come back after offDelay seconds 
    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: irrigation pump

Post by snellejellep » Friday 15 June 2018 8:11

@FrankVZ that is exactly why i wanted the delay, so i do not switch the pump too often.

@waaren thanks again, i have imported the script and created the user variable. i will try it and report back the results.
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: irrigation pump

Post by snellejellep » Friday 15 June 2018 15:27

I tested it, it works really well, i did change the timeout form 60 to 10 because 60 was a bit too long for me but now it works perfect.
thanks!
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests