I have a script to automatically turn on my waterpump at the moment a watergroup "asks" water, for instance druppelslang.
then the pump and the druppelslang will run for a set amount of time, and it will stop, or it has to be manually disabled.
I use silent() to overcome the script rerunning if it has been manually disabled within the time of the timer. however I see that the pump will be switched on, and I am unsure what could be causing that it is still triggered when the timer is finished?
here is my code:
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 (in minuten)
local sproeitijd = 1
print("stap 1: ".. device.name)
-- silent functie gebruiken, anders gaat de pomp meteen weer uit aangezien er dan weer een state change is.
--help functie
local function schakelPomp(pomp,sproeitijd)
print("stap functie: ".. device.name.. " en ".. domoticz.data.druppel_aan)
if pomp.active == false
then
stroeitimer = sproeitijd * 60
pomp.switchOn().silent()
pomp.switchOff().silent().afterSec(stroeitimer - 5)
print ("Pomp gaat aan via functie")
elseif pomp.active == true and (domoticz.data.voor_aan == 'false' or domoticz.data.voor_aan == nill) and (domoticz.data.achter_aan == 'false' or domoticz.data.achter_aan == nill) and (domoticz.data.druppel_aan == 'false' or domoticz.data.druppel_aan == nill)
then
print("stap stop functie: ".. device.name.." en ".. domoticz.data.druppel_aan)
pomp.switchOff().silent()
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' or domoticz.data.voor_aan == nill) and (domoticz.data.achter_aan == 'false' or domoticz.data.achter_aan == nill) and (domoticz.data.druppel_aan == 'false' or domoticz.data.druppel_aan == nill)
then
device.switchOff().silent().afterMin(sproeitijd)
print("pomp aan via schakelaar")
--Sproeier in voortuin aan
elseif
device.name == 'Sproeier Voor'
then
if device.active
then
svoor.switchOff().silent().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().silent().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
print("stap 2: ".. device.name)
druppel.switchOff().silent().afterMin(sproeitijd)
domoticz.data.druppel_aan = 'true'
schakelPomp(pomp,sproeitijd,domoticz.data.druppel_aan)
print("Druppel aan "..domoticz.data.druppel_aan)
else
print("stap 3: ".. device.name)
domoticz.data.druppel_aan = 'false'
schakelPomp(pomp,sproeitijd)
print("Druppel uit ".. domoticz.data.druppel_aan)
end
end
print("*********Echo van de trigger**********")
print(device.name)
print("*********einde van de trigger*********")
end
}