Thanks to this thread I got my water flow meter working with my water usage meter (a home built wireless solution using a Wemos D1 with ESP Easy). But I encountered something strange about this script: the meter only seems to give values in increments of 12.
- If I open one tap completely, the flow is 12l/min.
- If I open two taps, the flow is 24l/min.
- If I open one tap halfway, the flow is not 6l/min as you would expect, but alternately 5 seconds 0 and 5 seconds 12l/min.
- If I open one tap very slightly, the flow is 0l/min for 15x5 seconds and then 12l/min for 1x5 seconds.
5 Seconds is the interval with which the Watermeter sends data to Domoticz. I have set that myself in ESP Easy. It means that the Waterflow script is also triggered every 5 seconds. But it is weird that the script to measure the flow should report only on/off values in increments of 12, instead of calculating the average over multiple measurements. Any ideas about why this happens?
BTW this is the script I am talking about:
Code: Select all
return {
on = { devices = {
'Waterverbruik' -- change to name of your watermeter
},
},
data =
{
water =
{
initial = { 0 },
},
},
execute = function(dz, item)
local factor = 1000 -- this might need to be changed depending on if your meter is in liters or m3 or different.
local waterFlow = dz.devices('Waterflow')
print ("waterFlow=")
print (waterFlow)
print ("waterTotal=")
local waterTotal = item.counterToday * factor -- watermeter can be of type counter or custom sensor sValue works for both
print (waterTotal)
if dz.data.water.total ~= nil then -- first reading does not update the flowmeter
waterFlow.cancelQueuedCommands()
local pastTime = dz.time.dDate - dz.data.water.lastTime -- seconds since last time
local waterFlowValue = dz.utils.round((( waterTotal - dz.data.water.total ) * 60) / pastTime, 2) -- liter / min
print("waterFlowValue=")
print(waterFlowValue)
waterFlow.updateWaterflow(waterFlowValue)
waterFlow.updateWaterflow(0).afterSec(60) -- if no new data within 60 seconds the reset flow to 0
end
dz.data.water.total = waterTotal
dz.data.water.lastTime = dz.time.dDate
end
}