Dzvents as sprinkler controler

Easy to use, 100% Lua-based event scripting framework.
Post Reply
devros
Posts: 175
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 8:41

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: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post by waaren » Friday 18 May 2018 12:19

@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
}
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

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

Re: Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 14:02

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: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post by waaren » 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

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
}
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

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

Re: Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 14:59

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: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post by waaren » Friday 18 May 2018 16:16

Just press the Off selection button; the script will react to that even if the Off was already selected
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

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

Re: Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 16:46

ooh thanks, will have to study your code

randytsuch
Posts: 98
Joined: Sunday 20 March 2016 19:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: Dzvents as sprinkler controler

Post by randytsuch » Friday 18 May 2018 17:54

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

Re: Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 20:24

Yes im also using esp easy - used rflink relay, but esp easy is better :-)

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

Re: Dzvents as sprinkler controler

Post by devros » Friday 18 May 2018 21:08

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: 807
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents as sprinkler controler

Post by waaren » Friday 25 May 2018 9:44

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
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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests