Page 1 of 1

Dzvents as sprinkler controler

Posted: Friday 18 May 2018 8:41
by devros
hello,
i would like to control my sprinkler system (4 valves visible as switches in domoticz)
what would be best approach to create dummy switch controlled with dzvents
i want to run (on switch)
1 valve (x min on then switch off)
2 valve (x min on then switch off)
3 valve (x min on then switch off)
4 valve (x min on then switch off)
it even possible to run script for so long?
problem is that i want to be able switch off at anytime and interrupt program and disable valves anytime....?

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 12:19
by waaren
@devros,

I am not sure I completely understand you requirements but this might be a start.
Create a virtual selector switch with level 0 = Off and other levels are the names of your Valve switches.

If you choose a valve it will be switched to On for 30 seconds by the script or until you manually switch it to Off
Spoiler: show

Code: Select all

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

    execute = function(dz, trigger)


        local choice = trigger.levelName
        local myValves = {"Valve 1", "Valve 2","Valve 3","Valve 4"}
        if choice ==  "Off" then
            for k,v in ipairs(myValves) do
                dz.devices(v).switchOff().checkFirst()
            end
        else
            dz.devices(choice).switchOn().forSec(30)
            trigger.switchOff().silent()
        end
    end
}

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 14:02
by devros
Wow thanks so simple :)
this should be as example how dzvents is powerful
thats even better then i wanted...
now only figure out how to add another choice to switch, to run all 4 valves consecutive
and maybe create dummy text variable with time (for easy change) :)

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 14:36
by waaren
Add another level to selector with name "All" and add requested time in the description field in seconds like

SprinklerTime: 40

or modify the script a little bit to get different times per valve; you got the idea :D
Spoiler: show

Code: Select all

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

    execute = function(dz, trigger)

        local choice = trigger.levelName
        local sprinklerTime
        
        local description = trigger.description
        if description ~= nil and description ~= "" then
              _, _, sprinklerTime = string.find(description,"SprinklerTime: (%d+)") 
        end
        sprinklerTime = sprinklerTime or 30
        
        local myValves = {"Valve 1", "Valve 2","Valve 3","Valve 4"}
        if choice ==  "All" then
            for k,v in ipairs(myValves) do
                dz.devices(v).switchOn().forSec(sprinklerTime)
            end
        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
}

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 14:59
by devros
great :)
last question how to handle stop when i run 4 valves consecutive switch
my idea is add next switch selector with stop and use cancelQueuedCommands() function and then disable all valves, or is more elegant way how to interrupt for loop?

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 16:16
by waaren
Just press the Off selection button; the script will react to that even if the Off was already selected

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 16:46
by devros
ooh thanks, will have to study your code

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 17:54
by randytsuch
FWIW, I implemented a sprinkler controller with Dzvents, and I'm pleased with it.

I use ESP's running ESPEasy to actually control the relays which turn on the sprinkler valves. I have a front and back, so I have two ESP's (Wemos D1 mini's) to handle this.
Dzvents is used to send the commands to turn on and off the sprinklers.

Randy

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 20:24
by devros
Yes im also using esp easy - used rflink relay, but esp easy is better :-)

Re: Dzvents as sprinkler controler

Posted: Friday 18 May 2018 21:08
by devros
waaren wrote: Friday 18 May 2018 14:36 Add another level to selector with name "All" and add requested time in the description field in seconds like

SprinklerTime: 40

or modify the script a little bit to get different times per valve; you got the idea :D
Spoiler: show
all works great
BTW nice trick with description value :o

edit: one thing in program (all) are trigered all switches in same time (i want to triger them one after the other)
somehow to modify for loop, dam time to start study Lua :)

tried this but thats not working

Code: Select all

            for k,v in ipairs(myValves) do
                dz.devices(v).switchOn().forSec(sprinklerTime).switchOff().afterSec(sprinklerTime)
            end

Re: Dzvents as sprinkler controler

Posted: Friday 25 May 2018 9:44
by waaren
can you try (not tested)

Code: Select all

            local delay = 1
            for k,v in ipairs(myValves) do
                dz.devices(v).switchOn().afterSec(delay).forSec(sprinklerTime)
                delay = delay + 1
            end