I need some help in diagnosing a script.
In my setup when a pump is turned on, waterflow readings are being sent to Domoticz every second. They are fed to a waterflow sensor and a variable (as I could not get dzVents or Blockly to work with the sensor). I need a script to check the waterflow around 20 seconds after the pump was started. If it's too low, a safety switch should be triggered. My script looks like this:
Code: Select all
return {
on = { variables = {"pompa_zbiornika_przeplyw"},
data = { count = { initial = 0 }
},
execute = function(domoticz, _)
local przeplyw = domoticz.variables("pompa_zbiornika_przeplyw").value
local pompa = domoticz.devices("POMPA ZBIORNIKA").state
if (pompa == "On") then
domoticz.data.count = domoticz.data.count + 1
elseif (pompa ~= "On") then
domoticz.data.count = 0
end
if (domoticz.data.count >= 20 ) then
if (przeplyw >= 0 and przeplyw <= 5 and pompa == 'On' ) then
domoticz.devices("BLOKADA POMPY ZBIORNIKA").switchOn().checkFirst()
domoticz.data.count = 0
elseif (przeplyw > 5 and przeplyw < 22 and pompa == 'On' ) then
domoticz.devices("BRUDNY FILTR ZBIORNIKA").switchOn().checkFirst()
domoticz.data.count = 0
end
end
end
}
}
Regards, darkdude