Waterflow meter shows data in 12 l/min steps?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Waterflow meter shows data in 12 l/min steps?

Post by pgielen »

This is a follow-up to the thread https://www.domoticz.com/forum/viewtopi ... 59&t=30920

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
} 
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Waterflow meter shows data in 12 l/min steps?  [Solved]

Post by waaren »

pgielen wrote: Tuesday 07 April 2020 16:49 This is a follow-up to the thread https://www.domoticz.com/forum/viewtopi ... 59&t=30920

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 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?
It's all in the script logic. The smallest delta between waterTotal and dz.data.water.total when above 0 is now 1.

1 * 60 / pastTime ==> 1 * 60 / 5 ==> 12
0 * 60 / pastTime ==> 0 * 60 / 5 ==> 0

If you need a more accurate average you can either use devices able to send / receive mL or decrease the number of times the script calculates the average to once / minute (like below)

Code: Select all

return 
{
    on = 
    { 
        devices = 
        {
            'Waterverbruik', -- change to name of your watermeter
        },
    },

    data =
    {
        water =
        {
            initial = { 0 },
        },
    },
 
    execute = function(dz, item)    
        
        if dz.data.water.total ~= nil then -- first reading does not update the flowmeter
            local pastTime = dz.time.dDate - dz.data.water.lastTime -- seconds since last time
            if pastTime > 55 then 
                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')
                
                local waterTotal = item.counterToday * factor -- watermeter can be of type counter or custom sensor sValue works for both
                dz.log (' waterTotal= ' .. waterTotal, dz.LOG_FORCE)
        
                local waterFlowValue = dz.utils.round((( waterTotal - dz.data.water.total ) * 60) / pastTime, 2) -- liter / min
                if waterFlowValue > 0 then 
                    waterFlow.cancelQueuedCommands()
                    waterFlow.updateWaterflow(waterFlowValue)
                    waterFlow.updateWaterflow(0).afterSec(70) -- 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
        end
    end
} 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
pgielen
Posts: 91
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Waterflow meter shows data in 12 l/min steps?

Post by pgielen »

Thanks for this solution, this is much better. I have modified the script to update every 30 seconds and this works best for me. Having to wait a full minute could mean disaster if there would be a real water leakage :)
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest