Page 1 of 1

irrigationtimer

Posted: Thursday 16 May 2019 15:10
by pvklink
Hi,

I have a irrigation timer that works very well! I like to kick this script also from a switch(Tuinirrigatie) and directly execute all irrigation activities,

Status
1. on timer works OK
2. i added ON devices = Tuinirrigatie (this is a switch i can activate manual)

But no irrigation starts when i click the switch...
The switch has nothing to do with switch.state or switch2.state when i push it it must execute the rules below "switch2.state = off"

Code: Select all

local Tuinirrigatie = 'at 18:30 on mon,tue,wed,thu,fri,sat,sun'

return {
	on =    {timer = {Tuinirrigatie}},
            {devices = {'Tuinirrigatie'}},    

    logging =   { level   = domoticz.LOG_INFO ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz,item,info)
    local switch        = dz.devices('Irrigatietimers')
    local switch2       = dz.devices('hetregent')
    local now           = os.time(os.date('*t'))      
    local devpauze      = 1

    if switch.state == 'Off' then                                                       
        dz.log("Script: " .. info.scriptName .. " is niet aangezet, switch: " .. switch.name .. " staat uit", dz.LOG_INFO)
    else
        if switch2.state == 'Off' then                                                       
    
                dz.devices('usb lamp').switchSelector(20)               -- anders gaat t wel aan maar staat de selector niet op aan
                dz.variables('ledlampkleur').set('blauw')
    
                local devtimer1 = tonumber(dz.devices('Tuinirrigatie_border_links_waarde').levelName)
                dz.devices('Tuinirrigatie_border_links').switchOn().checkFirst()                            --.forMin(devtimer1) wordt in DZ_irrigatie_source bepaalt
                dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_links, aangezet, om:" .. dz.time.rawTime .. " voor " .. devtimer1 .. " minuten....", dz.LOG_INFO)    
    
                local devtimer2 = tonumber(dz.devices('Tuinirrigatie_border_rechts_waarde').levelName)
                local aftertimer = devtimer1 + devpauze
                dz.devices('Tuinirrigatie_border_rechts').switchOn().checkFirst().afterMin(aftertimer) 
                dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_rechts, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer2 .. " minuten....", dz.LOG_INFO)    

                local devtimer3 = tonumber(dz.devices('Tuinirrigatie_gazon_waarde').levelName)
                local aftertimer = aftertimer+devtimer2 + devpauze
                dz.devices('Tuinirrigatie_gazon').switchOn().checkFirst().afterMin(aftertimer) 
                dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_gazon, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer3 .. " minuten....", dz.LOG_INFO)    

                local devtimer4 = tonumber(dz.devices('Tuinirrigatie_planten_waarde').levelName)
                local aftertimer = aftertimer+devtimer3 + devpauze
                dz.devices('Tuinirrigatie_planten').switchOn().checkFirst().afterMin(aftertimer) 
                dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_planten, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer4 .. " minuten....", dz.LOG_INFO)    

                dz.devices('usb lamp').switchSelector(dz.variables('ledlampkleuroud').value)
    
        else
    
            dz.log("Script: " .. info.scriptName .. " is niet aangezet, het is aan t regenen... ", dz.LOG_INFO)
        end
    end

end
}

Re: irrigationtimer

Posted: Thursday 16 May 2019 15:26
by waaren
pvklink wrote: Thursday 16 May 2019 15:10 I added ON devices = Tuinirrigatie (this is a switch i can activate manual)
But no irrigation starts when i click the switch...
You left a small error in the on = section. Try to replace that part with

Code: Select all

	on =    { timer = {Tuinirrigatie},
             devices = {'Tuinirrigatie'}},

Re: irrigationtimer

Posted: Thursday 16 May 2019 15:37
by pvklink
mmm, changed and it is rolling!
Also added some checks istimer etc..
now check what happens when i start the timer manually ( 4 devices have to start after each other and i am curious what happens when i stop the first one manually...

@update:
The selecting device is stopt, but the rest is continuing... and thats ok!
but when select switch Tuinirrigatie to OFF is has to stop the whole script... how can i do that ? some devices are already activated with afterMin?
I already have made an entry in my if then else structure below and added
dz.devices(Tuinirrigatie_gazon).cancelQueuedCommands()
dz.devices(Tuinirrigatie_border_links).cancelQueuedCommands()
dz.devices(Tuinirrigatie_planten).cancelQueuedCommands()
dz.devices(Tuinirrigatie_border_rechts).cancelQueuedCommands()

I get an error, i think you cant delete the switch queue from within another switch ?
i will switch the 4 devices to off (in the correspomding script the queue command does work...

Code: Select all

local Tuinirrigatietimer = 'at 18:30 on mon,tue,wed,thu,fri,sat,sun'

return {
    on =    { timer = {Tuinirrigatie},
              devices = {'Tuinirrigatie'}},

    logging =   { level   = domoticz.LOG_INFO ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz,item,info)
    local switch        = dz.devices('Irrigatietimers')
    local switch2       = dz.devices('hetregent')
    local switch3       = dz.devices('Tuinirrigatie')
    local now           = os.time(os.date('*t'))      
    local devpauze      = 1

    if (item.isTimer) and switch.state == 'Off' then

        dz.log("Script: " .. info.scriptName .. " is niet aangezet, switch: " .. switch.name .. " staat uit", dz.LOG_INFO)

    elseif ((item.isTimer) and switch2.state == 'Off') or ((item.isDevice) and switch3.state == 'On') then                                                       
    
        --dz.devices('usb lamp').switchSelector(20)               -- anders gaat t wel aan maar staat de selector niet op aan
        --dz.variables('ledlampkleur').set('blauw')
    
        local devtimer1 = tonumber(dz.devices('Tuinirrigatie_border_links_waarde').levelName)
        dz.devices('Tuinirrigatie_border_links').switchOn().checkFirst()                            --.forMin(devtimer1) wordt in DZ_irrigatie_source bepaalt
        dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_links, aangezet, om:" .. dz.time.rawTime .. " voor " .. devtimer1 .. " minuten....", dz.LOG_INFO)    
    
        local devtimer2 = tonumber(dz.devices('Tuinirrigatie_border_rechts_waarde').levelName)
        local aftertimer = devtimer1 + devpauze
        dz.devices('Tuinirrigatie_border_rechts').switchOn().checkFirst().afterMin(aftertimer) 
        dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_rechts, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer2 .. " minuten....", dz.LOG_INFO)    

        local devtimer3 = tonumber(dz.devices('Tuinirrigatie_gazon_waarde').levelName)
        local aftertimer = aftertimer+devtimer2 + devpauze
        dz.devices('Tuinirrigatie_gazon').switchOn().checkFirst().afterMin(aftertimer) 
        dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_gazon, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer3 .. " minuten....", dz.LOG_INFO)    

        local devtimer4 = tonumber(dz.devices('Tuinirrigatie_planten_waarde').levelName)
        local aftertimer = aftertimer+devtimer3 + devpauze
        dz.devices('Tuinirrigatie_planten').switchOn().checkFirst().afterMin(aftertimer) 
        dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_planten, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer4 .. " minuten....", dz.LOG_INFO)    

        --dz.devices('usb lamp').switchSelector(dz.variables('ledlampkleuroud').value)
    
    elseif switch3.state == 'Off' then                                                       
        --dz.devices(Tuinirrigatie_gazon).cancelQueuedCommands()
        --dz.devices(Tuinirrigatie_border_links).cancelQueuedCommands()
        --dz.devices(Tuinirrigatie_planten).cancelQueuedCommands()
        --dz.devices(Tuinirrigatie_border_rechts).cancelQueuedCommands()
        dz.devices('Tuinirrigatie_gazon').switchOff() -- staat waarschijnlijk al uit, maar it het bijbehorende script wordt de queue geleegd
        dz.devices('Tuinirrigatie_border_links').switchOff()
        dz.devices('Tuinirrigatie_planten').switchOff()
        dz.devices('Tuinirrigatie_border_rechts').switchOff()
        dz.log("Script: " .. info.scriptName .. " irrigatie timers verwijderd... ", dz.LOG_INFO)
    
    else
    
        dz.log("Script: " .. info.scriptName .. " is niet aangezet, het is aan t regenen... ", dz.LOG_INFO)
    end

end
}

Re: irrigationtimer

Posted: Thursday 16 May 2019 17:29
by waaren
pvklink wrote: Thursday 16 May 2019 15:37 I already have made an entry in my if then else structure below and added
dz.devices(Tuinirrigatie_gazon).cancelQueuedCommands()
dz.devices(Tuinirrigatie_border_links).cancelQueuedCommands()
dz.devices(Tuinirrigatie_planten).cancelQueuedCommands()
dz.devices(Tuinirrigatie_border_rechts).cancelQueuedCommands()
I get an error
It would be easier to understand what happens if you post the error as well
I think you cant delete the switch queue from within another switch ?
It should but from what I see in your script is that you left out the quotes before and after the device names.

Re: irrigationtimer

Posted: Thursday 16 May 2019 18:40
by pvklink
it works!
I copied the command without quotes from this forum...

Re: irrigationtimer

Posted: Thursday 16 May 2019 20:40
by waaren
pvklink wrote: Thursday 16 May 2019 18:40 it works!
I copied the command without quotes from this forum...
A string without quotes is considered to be a variable by Lua / dzVents

Re: irrigationtimer

Posted: Thursday 16 May 2019 21:03
by pvklink
The irrigation, four zones with sunboilervalves works awsome... Timer, manual for all four and each separate....
I can also cancel and adjust the watering time for each device!
Thanks @waaren

My lamp can turn blue when watering, but i disabled broadlink plugin since the latest updates of domoticz and rasbian...
my system is getting froozen

Re: irrigationtimer

Posted: Saturday 18 May 2019 15:39
by pvklink
I want to expand my timer. A prof timer has more timers, i have one, but works more then great!
What is the best way to do this, please advise... this would be wonderful when going on holiday

i made a test script, is this is the way to do it?

action 1: i change the timerswitch irrigatietimer in a timerswitch with selector (menu) with the different programms in it
are these timers ok?

my testscript

Code: Select all

local Tuinirrigatietimer10 = 'every day 10 minutes after sunset'
local Tuinirrigatietimer20 = 'every other day 10 minutes after sunset'
local Tuinirrigatietimer30 = '10 minutes after sunset on mon,thu,sun'
local Tuinirrigatietimer40 = 'every saturday 10 minutes after sunset'
local Tuinirrigatietimer50 = 'every month on the first 10 minutes after sunset'

return {
    on =    { timer = {Tuinirrigatietimer10,Tuinirrigatietimer20,Tuinirrigatietimer30,Tuinirrigatietimer40,Tuinirrigatietimer50},
              devices = {'irrigatietimer'}},

    logging =   { level   = domoticz.LOG_INFO ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz,item,info)
   local switch = dz.devices('test')

    if (item.isTimer) and ((switch.level) ~= 0) then
        if (switch.level) == 10 and (item.trigger == Tuinirrigatietimer10) 
        or (switch.level) == 20 and (item.trigger == Tuinirrigatietimer20) then
        or (switch.level) == 30 and (item.trigger == Tuinirrigatietimer30) then
        or (switch.level) == 40 and (item.trigger == Tuinirrigatietimer40) then
        or (switch.level) == 50 and (item.trigger == Tuinirrigatietimer50) then
            -- irrigation rules
        else
            dz.log("Script: timers worden uitgevoerd, betreft een onbekende timer")
        end
    end
  
end
}

--> disadvantage is that the script is running on each timer
--> advantage, easy to script and to maintain?

if also pushed these programs in a backup of my irrigation script... is this looking ok?

Code: Select all

local Tuinirrigatietimer10 = 'every day 10 minutes after sunset'
local Tuinirrigatietimer20 = 'every other day 10 minutes after sunset'
local Tuinirrigatietimer30 = '10 minutes after sunset on mon,thu,sun'
local Tuinirrigatietimer40 = 'every saturday 10 minutes after sunset'
local Tuinirrigatietimer50 = 'every month on the first 10 minutes after sunset'

return {
    on =    { timer = {Tuinirrigatietimer10,Tuinirrigatietimer20,Tuinirrigatietimer30,Tuinirrigatietimer40,Tuinirrigatietimer50},
              devices = {'Tuinirrigatie','Irrigatietimers_test'}},

    logging =   { level   = domoticz.LOG_INFO ,                  
                  marker  = "Timers irrigatie"},
              
    execute = function(dz,item,info)
        
    local switch        = dz.devices('Irrigatietimers_test')
    local switch2       = dz.devices('hetregent')
    local switch3       = dz.devices('Tuinirrigatie')
    local now           = os.time(os.date('*t'))      
    local devpauze      = 1

    if (item.isTimer) and switch.level == 0 then

        dz.log("Script: " .. info.scriptName .. " is niet aangezet, switch: " .. switch.name .. " staat uit", dz.LOG_INFO)

    elseif ((item.isTimer and switch.level ~= 0 and switch2.state == 'Off')  or (item.isDevice and switch3.state == 'On')) then     
    
        --dz.devices('usb lamp').switchSelector(20)               -- anders gaat t wel aan maar staat de selector niet op aan
        --dz.variables('ledlampkleur').set('blauw')
    
        if 
            ((switch.level == 10 and item.trigger == Tuinirrigatietimer10) or (item.isDevice and switch3.state == 'On')) or
            ((switch.level == 20 and item.trigger == Tuinirrigatietimer20) or (item.isDevice and switch3.state == 'On')) or
            ((switch.level == 30 and item.trigger == Tuinirrigatietimer30) or (item.isDevice and switch3.state == 'On')) or
            ((switch.level == 40 and item.trigger == Tuinirrigatietimer40) or (item.isDevice and switch3.state == 'On')) or
            ((switch.level == 50 and item.trigger == Tuinirrigatietimer50) or (item.isDevice and switch3.state == 'On')) then

            local devtimer1 = tonumber(dz.devices('Tuinirrigatie_border_links_waarde').levelName)
            dz.devices('Tuinirrigatie_border_links').switchOn().checkFirst()                            --.forMin(devtimer1) wordt in DZ_irrigatie_source bepaalt
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_links, aangezet, om:" .. dz.time.rawTime .. " voor " .. devtimer1 .. " minuten....", dz.LOG_INFO)    
    
            local devtimer2 = tonumber(dz.devices('Tuinirrigatie_border_rechts_waarde').levelName)
            local aftertimer = devtimer1 + devpauze
            dz.devices('Tuinirrigatie_border_rechts').switchOn().checkFirst().afterMin(aftertimer) 
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_border_rechts, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer2 .. " minuten....", dz.LOG_INFO)    

            local devtimer3 = tonumber(dz.devices('Tuinirrigatie_gazon_waarde').levelName)
            local aftertimer = aftertimer+devtimer2 + devpauze
            dz.devices('Tuinirrigatie_gazon').switchOn().checkFirst().afterMin(aftertimer) 
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_gazon, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer3 .. " minuten....", dz.LOG_INFO)    

            local devtimer4 = tonumber(dz.devices('Tuinirrigatie_planten_waarde').levelName)
            local aftertimer = aftertimer+devtimer3 + devpauze
            dz.devices('Tuinirrigatie_planten').switchOn().checkFirst().afterMin(aftertimer) 
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie_planten, wordt aangezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " en voor " .. devtimer4 .. " minuten....", dz.LOG_INFO)    

        else
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie heeft onbekende timers ", dz.LOG_INFO)    
        end

        if switch3.state == 'On' then
            local aftertimer = aftertimer+devtimer4 + devpauze
            switch3.switchOff().checkFirst().afterMin(aftertimer) 
            dz.log("Script: " .. info.scriptName .. ", device: Tuinirrigatie, wordt uitgezet " .. tostring(aftertimer) .. " min na " .. dz.time.rawTime .. " ", dz.LOG_INFO)    
        end    

        --dz.devices('usb lamp').switchSelector(dz.variables('ledlampkleuroud').value)
    
    elseif (switch3.state == 'Off' or switch.level == 0) then                                                       
        dz.devices('Tuinirrigatie_gazon').cancelQueuedCommands()
        dz.devices('Tuinirrigatie_border_links').cancelQueuedCommands()
        dz.devices('Tuinirrigatie_planten').cancelQueuedCommands()
        dz.devices('Tuinirrigatie_border_rechts').cancelQueuedCommands()
        dz.devices('Tuinirrigatie_border_links').switchOff().checkFirst() -- nadeel is ook 4 maal spraak dat het uit gaat en die had je al gehoord bij t autom uitgaan
        dz.devices('Tuinirrigatie_border_rechts').switchOff().checkFirst() -- nadeel is ook 4 maal spraak dat het uit gaat en die had je al gehoord bij t autom uitgaan
        dz.devices('Tuinirrigatie_gazon').switchOff().checkFirst() -- staat waarschijnlijk al uit, maar it het bijbehorende script wordt de queue geleegd en device ook uit als dit niet zo was
        dz.devices('Tuinirrigatie_planten').switchOff().checkFirst() -- voordeel is als je halverwege afbreekt, dat ook de switches direct uitgaan, nu moet je zelf n switch die loopt uitzetten
        dz.log("Script: " .. info.scriptName .. " irrigatie timers verwijderd... ", dz.LOG_INFO)
    
    else
    
        dz.log("Script: " .. info.scriptName .. " is niet aangezet, het is aan t regenen... ", dz.LOG_INFO)
    end
end
}