I have created a script to automatically turn on my waterpump when one of the watering zones has been enabled.
next to that it will run for a certain period as defined as "sproeitijd"
the functions are, enable to pump alone, no zone
enable a zone -> pump needs to enable too
extra zone -> pump needs to continue
disable zone -> check if other zone is still enabled -> if yes, leave pump on (do not reset timer)
if no, turn pump off
so, wha tis the issue, if the zone or pump is disabled manually, and not by timer, the pump will enable after as it seems the timer has ended.
it looks and I could be wrong that there is a state change and that is picked up and interpreted that the system needs to do somehting.
can some one confirm this, and help how to cercomvent this?
Code: Select all
return {
on = {
devices = {
'Waterpomp',
'Sproeier Voor',
'Sproeier Achter',
'Druppelslang'
},
},
data = {
voor_aan = {initial='false'},
achter_aan = {initial='false'},
druppel_aan = {initial='false'}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Waterpomp',
},
execute = function(domoticz, device)
--declaratie van devices
local pomp = domoticz.devices('Waterpomp')
local sachter = domoticz.devices('Sproeier Achter')
local svoor = domoticz.devices('Sproeier Voor')
local druppel = domoticz.devices('Druppelslang')
--Hoelang moet er gesproeid worden
local sproeitijd = 60
--help functie
local function schakelPomp(pomp,sproeitijd)
if pomp.active == false
then
pomp.switchOn().forMin(sproeitijd-1)
print ("Pomp gaat aan via functie")
elseif pomp.active == true and domoticz.data.voor_aan == 'false' and domoticz.data.achter_aan == 'false' and domoticz.data.druppel_aan == 'false'
then
pomp.switchOff()
print("pomp gaat uit via functie")
end
return self --om te testen dat het is gelukt
end
--pomp alleen aan, let op de druk van de pomp!
if
device.name == 'Waterpomp' and domoticz.data.voor_aan == 'false' and domoticz.data.achter_aan == 'false' and domoticz.data.druppel_aan == 'false'
then
device.switchOff().afterMin(sproeitijd)
print("pomp aan via schakelaar")
--Sproeier in voortuin aan
elseif
device.name == 'Sproeier Voor'
then
if device.active
then
svoor.switchOff().afterMin(sproeitijd)
domoticz.data.voor_aan = 'true'
print('Voor aan')
schakelPomp(pomp,sproeitijd)
else
domoticz.data.voor_aan = 'false'
schakelPomp(pomp,sproeitijd)
print("Voor uit")
end
--Sproeier in achtertuin aan
elseif
device.name == 'Sproeier Achter'
then
if device.active
then
sachter.switchOff().afterMin(sproeitijd)
domoticz.data.achter_aan = 'true'
schakelPomp(pomp,sproeitijd)
print("Achter aan")
else
domoticz.data.achter_aan = 'false'
schakelPomp(pomp,sproeitijd)
print("achter uit")
end
--Druppelslang voor en achter
elseif
device.name == 'Druppelslang'
then
if device.active
then
druppel.switchOff().afterMin(sproeitijd)
domoticz.data.druppel_aan = 'true'
schakelPomp(pomp,sproeitijd)
print("Druppel aan")
else
domoticz.data.druppel_aan = 'false'
schakelPomp(pomp,sproeitijd)
print("Druppel uit")
end
end
end
}