switch off and repeat
Posted: Friday 16 August 2019 10:19
Hi,
During my holidat my irrigiation switches (some zones) (sometimes) did not went OFF because of a signal that did not reach the switch.
So i want to add some security that the zones (4 pieces) go off. The scripts does work ok.
explenation, I have to scripts:
1. script M that manages a zone manually.
2. timer script T that manages all zones and calls the other script M to put it on and off.
a. When a zone reaches its event via script T it calls script M and script M puts the zone on and off after the zone timer...
b when manually activate the zone to ON it does the same
c. when putting the zone manually to OFF (abort) it kills the schedule and stops the zone
Question:
So i think i have to add in script M (when putting a zone to ON)
item.switchOff().afterMin(devtimer).silent().repeatAfterSec(5, 2) instead off item.switchOff().afterMin(devtimer).silent()
Possible problem(did not test this) is that when the zone goes to off after x-time it kills the repeat schedule (it executes item.cancelQueuedCommands) (dont know this for sure)
I cant remove the item.cancelQueuedCommands(), i need this when putting the zones manually to on/off, in this case the schedule must be killed when pressing to OFF...
script Manually manage a device
script T (timers)
During my holidat my irrigiation switches (some zones) (sometimes) did not went OFF because of a signal that did not reach the switch.
So i want to add some security that the zones (4 pieces) go off. The scripts does work ok.
explenation, I have to scripts:
1. script M that manages a zone manually.
2. timer script T that manages all zones and calls the other script M to put it on and off.
a. When a zone reaches its event via script T it calls script M and script M puts the zone on and off after the zone timer...
b when manually activate the zone to ON it does the same
c. when putting the zone manually to OFF (abort) it kills the schedule and stops the zone
Question:
So i think i have to add in script M (when putting a zone to ON)
item.switchOff().afterMin(devtimer).silent().repeatAfterSec(5, 2) instead off item.switchOff().afterMin(devtimer).silent()
Possible problem(did not test this) is that when the zone goes to off after x-time it kills the repeat schedule (it executes item.cancelQueuedCommands) (dont know this for sure)
I cant remove the item.cancelQueuedCommands(), i need this when putting the zones manually to on/off, in this case the schedule must be killed when pressing to OFF...
script Manually manage a device
Code: Select all
return {
on = {devices = {'Tuinirrigatie_gazon','Tuinirrigatie_border_links','Tuinirrigatie_planten','Tuinirrigatie_border_rechts'}},
logging = {
level = domoticz.LOG_ERROR,
marker = "Tuinirrigatie",
},
execute = function(dz, item, info)
local devtimer = tonumber(dz.devices(item.name .. '_waarde').levelName) -- timer ophalen. timer heeft altijd de naam van het device met _waarde erachter
local logcode = 3
local messageTable = {}
local add = 'add'
local del = 'del'
local chg = 'chg'
local function globalMessage(action, message, logcode)
if logcode == nil then logcode = 3 end
if action == add and logcode > 0 then
messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
elseif action == del then
dz.globalData.mylogging = message
dz.devices('timerlog').updateText(message)
elseif action == chg then
dz.helpers.dumpMessages(dz, messageTable)
end
end
if item.state == 'Off' then
item.cancelQueuedCommands()
dz.devices('usb lamp').switchSelector('Off') -- er op 29-6-19 bijgeplaatst
globalMessage(add, ' IRRIGATIE UIT: ZONE ' .. item.name .. ' uitgezet...',logcode) -- 'om: ' .. dz.time.rawTime
else
item.switchOff().afterMin(devtimer).silent()
dz.helpers.alertLidl(dz, "blauw", devtimer*60)
globalMessage(add, ' IRRIGATIE AAN: ZONE ' .. item.name .. ' aangezet voor: ' .. devtimer .. ' minuten...',logcode)
end
globalMessage(chg) -- dump
end
}
Code: Select all
-- timers mogen niet op t exacte moment draaien, dus 5mn verschil
-- local Tuinirrigatietimer10 = 'at 18:10 on mon,tue,wed,thu,fri,sat,sun'
--
local Tuinirrigatietimer10 = 'every day at sunset'
local Tuinirrigatietimer20 = 'every other day 5 minutes after sunset'
local Tuinirrigatietimer30 = '10 minutes after sunset on mon,thu,sun'
local Tuinirrigatietimer40 = '10 minutes before sunset on sat'
local Tuinirrigatietimer50 = '5 minutes before sunset on 1/*'
return {
on = { timer = {Tuinirrigatietimer10,Tuinirrigatietimer20,Tuinirrigatietimer30,Tuinirrigatietimer40,Tuinirrigatietimer50},
devices = {'Tuinirrigatie'}},
logging = { level = domoticz.LOG_ERROR ,
marker = "Timers irrigatie"},
execute = function(dz,item,info)
local logcode = 3
local messageTable = {}
local add = 'add'
local del = 'del'
local chg = 'chg'
local function globalMessage(action, message, logcode)
if logcode == nil then logcode = 3 end
if action == add and logcode > 0 then
messageTable = dz.helpers.addMessage(dz, item, info, message, messageTable, logcode)
elseif action == del then
dz.globalData.mylogging = message
dz.devices('timerlog').updateText(message)
elseif action == chg then
dz.helpers.dumpMessages(dz, messageTable)
end
end
local iswitch1 = dz.devices('Tuinirrigatie_border_links_timer')
local iswitch2 = dz.devices('Tuinirrigatie_border_rechts_timer')
local iswitch3 = dz.devices('Tuinirrigatie_gazon_timer')
local iswitch4 = dz.devices('Tuinirrigatie_planten_timer')
local now = os.time(os.date('*t'))
local devduur1 = tonumber(dz.devices('Tuinirrigatie_border_links_waarde').levelName)
local devduur2 = tonumber(dz.devices('Tuinirrigatie_border_rechts_waarde').levelName)
local devduur3 = tonumber(dz.devices('Tuinirrigatie_gazon_waarde').levelName)
local devduur4 = tonumber(dz.devices('Tuinirrigatie_planten_waarde').levelName)
local devpauze = 1
local aftertimer1 = 0 -- toegevoegd als t niet werkt verwijderen
local aftertimer2 = 0
local aftertimer3 = 0
local aftertimer4 = 0
-- hier de tijden bepalen (wanneer de 4 groepen mogen worden gestart...
-- kijkt wel of de duur is gevuld en neemt de tijd anders niet mee
-- kijkt bij timers of de timer aan staat
-- bij manueel of het AAN betreft bij AUTO en OFF spelen deze geen rol, wordt berekend bij timed event of bij aan
aftertimer1 = 0
if (devduur1 >0 and ((item.isTimer and iswitch1.level > 0) or (item.isDevice and dz.devices('Tuinirrigatie').state == 'aan'))) then aftertimer1 = devduur1 + devpauze end
aftertimer2 = aftertimer1
if (devduur2 >0 and ((item.isTimer and iswitch2.level > 0) or (item.isDevice and dz.devices('Tuinirrigatie').state == 'aan'))) then aftertimer2 = aftertimer1 + devduur2 + devpauze end
aftertimer3 = aftertimer2
if (devduur3 >0 and ((item.isTimer and iswitch3.level > 0) or (item.isDevice and dz.devices('Tuinirrigatie').state == 'aan'))) then aftertimer3 = aftertimer2 + devduur3 + devpauze end
aftertimer4 = aftertimer3
if (devduur4 >0 and ((item.isTimer and iswitch4.level > 0) or (item.isDevice and dz.devices('Tuinirrigatie').state == 'aan'))) then aftertimer4 = aftertimer3 + devduur4 + devpauze end -- ALLES nogmaals uit en schakelaar op UIT
if (
(item.isTimer and dz.devices('hetregent').state == 'Off' and dz.devices('Tuinirrigatie').state == 'auto')
or (item.isDevice and dz.devices('Tuinirrigatie').state == 'aan')
) then
-- timed event, het regent niet en irrigatie handeling is auto or
-- device handeling en irrigatie handeling is AAN
if (item.isTimer and iswitch1.level == 10 and item.trigger == Tuinirrigatietimer10) or -- controleer of de irrigatiezone of er aan een van de 4 programma's is voldaan of AAN
(item.isTimer and iswitch1.level == 20 and item.trigger == Tuinirrigatietimer20) or
(item.isTimer and iswitch1.level == 30 and item.trigger == Tuinirrigatietimer30) or
(item.isTimer and iswitch1.level == 40 and item.trigger == Tuinirrigatietimer40) or
(item.isTimer and iswitch1.level == 50 and item.trigger == Tuinirrigatietimer50) or
(item.isDevice and dz.devices('Tuinirrigatie').state == 'aan') then
if devduur1 >0 then
dz.devices('Tuinirrigatie_border_links').switchOn().checkFirst() --.forMin(devtimer1) wordt in DZ_irrigatie_source bepaalt
globalMessage(add, ' IRRIGATIE AAN: ZONE: Tuinirrigatie_border_links wordt aangezet om: ' .. os.date('%Y-%m-%d %H:%M:%S', now) .. ' voor ' .. devduur1 .. ' minuten...',logcode)
else
globalMessage(add, ' IRRIGATIE UIT: ZONE: Tuinirrigatie_border_links is niet aangezet, de duur stond uit',logcode)
end
end
if (item.isTimer and iswitch2.level == 10 and item.trigger == Tuinirrigatietimer10) or
(item.isTimer and iswitch2.level == 20 and item.trigger == Tuinirrigatietimer20) or
(item.isTimer and iswitch2.level == 30 and item.trigger == Tuinirrigatietimer30) or
(item.isTimer and iswitch2.level == 40 and item.trigger == Tuinirrigatietimer40) or
(item.isTimer and iswitch2.level == 50 and item.trigger == Tuinirrigatietimer50) or
(item.isDevice and dz.devices('Tuinirrigatie').state == 'aan') then
if devduur2 > 0 then
dz.devices('Tuinirrigatie_border_rechts').switchOn().checkFirst().afterMin(aftertimer1)
globalMessage(add, ' IRRIGATIE AAN: ZONE: Tuinirrigatie_border_rechts wordt aangezet om: ' .. os.date('%Y-%m-%d %H:%M:%S', now + aftertimer1 * 60) .. ' voor ' .. devduur2 .. ' minuten...',logcode)
else
globalMessage(add, ' IRRIGATIE UIT: ZONE: Tuinirrigatie_border_rechts is niet aangezet, de duur stond uit',logcode)
end
end
if (item.isTimer and iswitch3.level == 10 and item.trigger == Tuinirrigatietimer10) or
(item.isTimer and iswitch3.level == 20 and item.trigger == Tuinirrigatietimer20) or
(item.isTimer and iswitch3.level == 30 and item.trigger == Tuinirrigatietimer30) or
(item.isTimer and iswitch3.level == 40 and item.trigger == Tuinirrigatietimer40) or
(item.isTimer and iswitch3.level == 50 and item.trigger == Tuinirrigatietimer50) or
(item.isDevice and dz.devices('Tuinirrigatie').state == 'aan') then
if devduur3 > 0 then
dz.devices('Tuinirrigatie_gazon').switchOn().checkFirst().afterMin(aftertimer2)
globalMessage(add, ' IRRIGATIE AAN: ZONE: Tuinirrigatie_gazon wordt aangezet om: ' .. os.date('%Y-%m-%d %H:%M:%S', now + aftertimer2 * 60) .. ' voor ' .. devduur3 .. ' minuten...',logcode)
else
globalMessage(add, ' IRRIGATIE UIT: ZONE: Tuinirrigatie_gazon is niet aangezet, de duur stond uit',logcode)
end
end
if (item.isTimer and iswitch4.level == 10 and item.trigger == Tuinirrigatietimer10) or
(item.isTimer and iswitch4.level == 20 and item.trigger == Tuinirrigatietimer20) or
(item.isTimer and iswitch4.level == 30 and item.trigger == Tuinirrigatietimer30) or
(item.isTimer and iswitch4.level == 40 and item.trigger == Tuinirrigatietimer40) or
(item.isTimer and iswitch4.level == 50 and item.trigger == Tuinirrigatietimer50) or
(item.isDevice and dz.devices('Tuinirrigatie').state == 'aan') then
if devduur4 > 0 then
dz.devices('Tuinirrigatie_planten').switchOn().checkFirst().afterMin(aftertimer3)
globalMessage(add, ' IRRIGATIE AAN: ZONE: Tuinirrigatie_planten wordt aangezet om: ' .. os.date('%Y-%m-%d %H:%M:%S', now + aftertimer3 * 60) .. ' voor ' .. devduur4 .. ' minuten...',logcode)
else
globalMessage(add, ' IRRIGATIE UIT: ZONE: Tuinirrigatie_planten is niet aangezet, de duur stond uit',logcode)
end
end
if (item.isDevice) then -- als alle zones zijn gesproeid en dit is als het manueel is altijd AAN geweest, dan deze UIT zetten
dz.devices('Tuinirrigatie').switchSelector(0).afterMin(aftertimer4) -- dz.devices('Tuinirrigatie').switchSelector(dz.devices('Tuinirrigatie').lastLevel).afterMin(aftertimer4) GEEFT problemen soms autom weer op AAN
globalMessage(add, ' IRRIGATIE UIT: Tuinirrigatie wordt uitgezet om: ' .. os.date('%Y-%m-%d %H:%M:%S', now + aftertimer4 * 60) .. ' ...',logcode)
end
elseif (item.isTimer and iswitch1.level == 0 and iswitch2.level == 0 and iswitch3.level == 0 and iswitch4.level == 0) then -- TIMER
globalMessage(add, ' IRRIGATIE UIT: Timerevent gestart maar alle timerzones staat uit',logcode)
elseif (item.isTimer and dz.devices('Tuinirrigatie').state == 'uit') then
globalMessage(add, ' IRRIGATIE UIT: Timerevent gestart maar het timerssysteem staat uit',logcode)
elseif (item.isTimer and dz.devices('Tuinirrigatie').state == 'auto' and dz.devices('hetregent').state == 'On') then
globalMessage(add, ' IRRIGATIE UIT: Timerevent gestart en is niet aangezet, het is aan t regenen... ',logcode)
elseif (item.isDevice and dz.devices('Tuinirrigatie').state == 'uit') then -- er is gekozen voor OFF op de switch
-- device handeling en irrigatie handeling is uit
dz.devices('Tuinirrigatie_border_links').switchOff() -- gebruik geen checkfirst want bij voortijdig annuleren kan het zijn dat het device nog niet aanstaat ivm after xxx... dan gebeurt er dus niets ook geen cancelqueue
dz.devices('Tuinirrigatie_border_rechts').switchOff()
dz.devices('Tuinirrigatie_gazon').switchOff()
dz.devices('Tuinirrigatie_planten').switchOff()
globalMessage(add, ' IRRIGATIE UIT: irrigatie timers/queue verwijderd... ',logcode)
elseif (item.isDevice and dz.devices('Tuinirrigatie').state == 'auto') then -- er is gekozen voor AUTO op de switch
-- device handeling is AUTO
globalMessage(add, ' IRRIGATIE AUTO: irrigatie is op automatisch gezet, timers worden actief... ',logcode)
else
globalMessage(add, ' IRRIGATIE UIT: is niet aangezet, onbekende reden... ' .. item.name .. '/' .. item.state,logcode)
end
globalMessage(chg) -- dump
end
}