Page 1 of 1
Stable waterflow detection to detect a leak
Posted: Sunday 26 May 2024 9:59
by Patricen
Hello,
I installed a sensor on my water meter, I can then detect water consumption and flow.
When a stable positive flow is detected, this is really suspicious and looks like a water leak.
How is it possible to code with DzVents something like if the waterflow is stable and not equal to zero for more than x min?
I can't find out how to use maybe lastupdate() or any other solution.
Thanks
Re: Stable waterflow detection to detect a leak
Posted: Sunday 26 May 2024 10:43
by HvdW
Your water meter has a counter?
Just read the log.
No dzvents needed.
Re: Stable waterflow detection to detect a leak
Posted: Sunday 26 May 2024 10:59
by Patricen
The metering is issued from an ECO-Devices, screenshot below.

- Screenshot_20240526-105744.png (295.53 KiB) Viewed 1008 times

- Screenshot_20240526-105429.png (333.34 KiB) Viewed 1008 times
Re: Stable waterflow detection to detect a leak
Posted: Sunday 26 May 2024 11:58
by Kedi
You could put every minute the waterflow value in a data set like:
Code: Select all
data = {
waterflow = { history = true, maxItems = 20 }
},
then when the max is reached you could compare the last value with the average.
If the difference between those 2 value is less then x you have a constant flow and could act on it.
Make of course an exception for zero.
You should take into account long showers and watering the garden.
See:
https://www.domoticz.com/wiki/DzVents:_ ... stent_data
Re: Stable waterflow detection to detect a leak
Posted: Sunday 26 May 2024 21:57
by Patricen
Kedi wrote: ↑Sunday 26 May 2024 11:58
You could put every minute the waterflow value in a data set like:
Code: Select all
data = {
waterflow = { history = true, maxItems = 20 }
},
then when the max is reached you could compare the last value with the average.
If the difference between those 2 value is less then x you have a constant flow and could act on it.
Make of course an exception for zero.
You should take into account long showers and watering the garden.
See:
https://www.domoticz.com/wiki/DzVents:_ ... stent_data
Thanks,
I'll try this
Re: Stable waterflow detection to detect a leak
Posted: Monday 27 May 2024 19:23
by Patricen
Hello,
No success with history, I then tried avgSince but it is not working either.
Code: Select all
2024-05-27 19:20:06.933 Error: dzVents: Error: (3.1.8) water leak: .../pi/domoticz/scripts/dzVents/generated_scripts/Fuite.lua:25: attempt to call a nil value (field 'avgSince')
Can somebody help me?
Thanks
Code: Select all
return
{
on =
{
devices =
{
'Eau-débit',
-- change to name of Sensor
},
},
data =
{
},
logging =
{
level = domoticz.LOG_DEBUG, --LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is tested and OK
marker = 'water leak',
},
execute = function(dz, item)
local avg = dz.devices('Eau-débit').avgSince('00:05:00')
dz.log('\nDevicename: ' .. item.name .. ', nValue: ' .. item.nValue .. ', sValue: ' .. item.sValue ..
'\nDevicetype: ' .. item.deviceType .. ', deviceSubType: ' .. item.deviceSubType )
if (item.nvalue>0) then
dz.log('Mobile average ' .. avg)
dz.log('Flow ' .. item.nValue)
if(item.nvalue==avg) then
domoticz.notify('Water stable flow : ' .. avg .. ' since 5 min')
end
end
end
}
Re: Stable waterflow detection to detect a leak
Posted: Wednesday 29 May 2024 13:49
by Kedi
Something like this. I did not test it.
Code: Select all
local maxValues = 30 -- number of minutes over which an average is taken
local devWater = 'Water'
local deviation = 0.001 -- deviation from average
-- Don't change anything below this line
return {
active = true,
-- active = false,
on = {
timer = {
'every minute',
},
},
logging = {
-- level = domoticz.LOG_INFO,
level = domoticz.LOG_DEBUG,
marker= 'WFA'
},
data = {
waterflow = { history = true, maxItems = maxValues },
},
execute = function(dz, item)
local _f = dz.data.waterflow -- data set
local nCounter = dz.devices(devWater).counter -- get last watermeter value
local flow = 0 -- initialize flow
if _f.size > 0 then
flow = nCounter - _f.getLatest().data
end
_f.add(nCounter) -- add counter to data set
dz.log('Counter: '..nCounter..' Flow: '..dz.utils.round(flow,3)..' - Avg: '..dz.utils.round(_f.avg(),3)..' Set: '.._f.size, dz.LOG_DEBUG)
-- only after full data set
if _f.size == maxValues then
-- only if there is flow and less then average +/- deviation
if flow > 0 and (nCounter - deviation < _f.avg() and nCounter + deviation > _f.avg()) then
dz.notify('Waterlekkage!', 'Er is waterlekkage in de leiding!!', dz.PRIORITY_EMERGENCY, dz.SOUND_SIR$
end
end
end
}
Re: Stable waterflow detection to detect a leak
Posted: Wednesday 29 May 2024 18:24
by Patricen
Thanks,
I did change the dz.devices name but got the following error:
2024-05-29 18:17:00.294 Error: dzVents: Error: (3.1.8) WFA: Item data is not a number type. Type is nil
2024-05-29 18:17:00.294 Error: dzVents: Error: (3.1.8) WFA: An error occurred when calling event handler leak
2024-05-29 18:17:00.294 Error: dzVents: Error: (3.1.8) WFA: /home/pi/domoticz/dzVents/runtime/HistoricalStorage.lua:289: attempt to perform arithmetic on a nil value (local 'sum')
Re: Stable waterflow detection to detect a leak
Posted: Wednesday 29 May 2024 19:32
by Kedi
This script expects a number from "dz.devices(devWater).counter"
Perhaps you have to change the counter with what your device has in its output.