Re: dzvents Silent() seems not to be working
Posted: Monday 26 April 2021 12:01
You could control this by adding a virtual switch "Pomp ontluchten"
With below modified script the pump will be on manual control when this switch is active.
Code: Select all
return
{
on =
{
devices =
{
'Waterpomp',
'Sproeier Voor',
'Sproeier Achter',
'Druppelslang',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Waterpump',
},
execute = function(dz, device)
local waterpump = dz.devices('Waterpomp')
local backGardenSprinkler = dz.devices('Sproeier Achter')
local frontGardenSprinkler = dz.devices('Sproeier Voor')
local dripperHose = dz.devices('Druppelslang')
local bleeding = dz.devices('Pomp ontluchten')
local spraytime = 1
local function hosesActive()
local activeHoses = backGardenSprinkler.active and 1 or 0
activeHoses = activeHoses + ( frontGardenSprinkler.active and 1 or 0 )
activeHoses = activeHoses + ( dripperHose.active and 1 or 0 )
return activeHoses
end
local function switchWaterpump( sprayMinutes )
if not(sprayMinutes) then
dz.log('All hoses closed. Stop waterpump now', dz.LOG_DEBUG)
waterpump.switchOff().checkFirst().silent()
else
local delay = sprayMinutes * 60 - 5
waterpump.cancelQueuedCommands()
waterpump.switchOn().checkFirst().silent()
waterpump.switchOff().silent().afterSec(delay)
dz.log('Switching waterpump On for ' .. delay .. ' seconds ', dz.LOG_DEBUG)
end
end
if device == waterpump and device.active then
if bleeding.active then
dz.log('Bleeding switch on; waterpump now on manual control!', dz.LOG_FORCE )
return
elseif hosesActive() > 0 then
device.switchOff().silent().afterMin(spraytime)
dz.log('One or more hoses active. Stop waterpump after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
else
switchWaterpump()
end
return
end
if device.active then
device.switchOff().silent().afterSec(spraytime * 60)
dz.log('Switching ' .. device.name .. ' Off after ' .. spraytime .. ' minutes', dz.LOG_DEBUG )
switchWaterpump( spraytime )
elseif hosesActive() == 0 then
switchWaterpump()
end
end
}