it seems that I have run into a brick wall and I am in need of an extra set of eyes (more experianced!)
I am building a script for my wellpump and 3 zones that are switched via a z-wave powersocket
I want the pump to automatically start when I enable one of the zone switches for 60minutes -1 and the zone for 60minutes.
if I switch on 2 zones and switch off one zone, then the pump must continue as there is still a zone who is "asking" for water.
I have used user variables in domoticz voor_aan, achter_aan and druppelslang_aan.
what I see happening is that the pump will start how it is requested, but it will not disable.
I see that the user var seems to be changed after the script calls for the enable/disable pump function and thus sees still one zone as 'true'
is there a way how I make sure the order is done correctly and (for me) as expected? or am I missing something?
Code: Select all
return {
on = {
devices = {
'Waterpomp',
'Sproeier Voor',
'Sproeier Achter',
'Druppelslang'
}
},
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)
print("voor: "..domoticz.variables('voor_aan').value,"Achter: "..domoticz.variables('achter_aan').value,"Druppel: "..domoticz.variables('druppel_aan').value)
if pomp.active == false
then
pomp.switchOn().forMin(sproeitijd-1)
print ("Pomp gaat aan via functie")
elseif pomp.active == true and domoticz.variables('voor_aan').value == 'false' and domoticz.variables('achter_aan').value == 'false' and domoticz.variables('druppel_aan').value == '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 device.active == false and domoticz.variables('voor_aan').value == 'false' and domoticz.variables('achter_aan').value == 'false' and domoticz.variables('druppel_aan').value == '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.variables('voor_aan').set('true')
print('Voor aan')
schakelPomp(pomp,sproeitijd)
else
domoticz.variables('voor_aan').set('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.variables('achter_aan').set('true')
schakelPomp(pomp,sproeitijd)
print("Achter aan")
else
domoticz.variables('achter_aan').set('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.variables('druppel_aan').set('true')
schakelPomp(pomp,sproeitijd)
print("Druppel aan")
else
domoticz.variables('druppel_aan').set('false')
schakelPomp(pomp,sproeitijd)
print("Druppel uit")
end
end
end
}