Dzvents as sprinkler controler

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

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

Dzvents as sprinkler controler

Post 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....?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Dzvents as sprinkler controler

Post 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) :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Dzvents as sprinkler controler

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post by waaren »

Just press the Off selection button; the script will react to that even if the Off was already selected
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Dzvents as sprinkler controler

Post by devros »

ooh thanks, will have to study your code
randytsuch
Posts: 90
Joined: Sunday 20 March 2016 18:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: Dzvents as sprinkler controler

Post 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
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Dzvents as sprinkler controler

Post by devros »

Yes im also using esp easy - used rflink relay, but esp easy is better :-)
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Dzvents as sprinkler controler

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest