Get average watermeter data  [Solved]

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

Moderator: leecollings

Post Reply
Evertjob89
Posts: 7
Joined: Sunday 18 November 2018 9:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Get average watermeter data

Post by Evertjob89 »

Hi,

Currently i'm running an setup with a NPN watermeter sensors and this works fine.

Yesterday the water run for a couple of hours (4 hours) and nobody was at home, so i've lost almost 2000 liter water. I've calculated is should be around 5 liters a minut.

So avoid this (or be notified earlier) i'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be simple:

Code: Select all

--- Watermeter IDx 30
return {
	on = {
		devices = {
			'Watermeter'
		}
	},
	execute = function(domoticz, device)
	   watermeter.Usage = myVar.subsetSince('00:17:00') --- Get data from last 17 minutes
	   
	        if(watermeter.Usage > 94) then
	            domoticz.notify('Water usage high!!',
                                'The waterusage is more than 5,5 liter a minute!',
                                domoticz.PRIORITY_HIGH)
	        end
	end
}
The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

Evertjob89 wrote: Monday 17 December 2018 16:37 So avoid this (or be notified earlier) i'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be simple:
The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Can you tell us what device type and subtype your watermeter in domoticz is ?
Goto the devices tab in the domoticz gui and type water in the search field. I am interested in the idx, name, type and subType values. My screen shows something like:

Code: Select all

  	84	Virtual	00082084	1	Watermeter	General	Custom Sensor	194046	-	-	
  	982	Virtual2	14426	1	Watermeter2	RFXMeter	RFXMeter counter	194.040 m3	
  	1241	Virtual2	00083241	1	waterm	General	Waterflow	0 l/min
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Evertjob89
Posts: 7
Joined: Sunday 18 November 2018 9:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get average watermeter data

Post by Evertjob89 »

waaren wrote: Monday 17 December 2018 19:31
Evertjob89 wrote: Monday 17 December 2018 16:37 So avoid this (or be notified earlier) i'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be simple:
The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Can you tell us what device type and subtype your watermeter in domoticz is ?
Goto the devices tab in the domoticz gui and type water in the search field. I am interested in the idx, name, type and subType values. My screen shows something like:

Code: Select all

  	84	Virtual	00082084	1	Watermeter	General	Custom Sensor	194046	-	-	
  	982	Virtual2	14426	1	Watermeter2	RFXMeter	RFXMeter counter	194.040 m3	
  	1241	Virtual2	00083241	1	waterm	General	Waterflow	0 l/min

Code: Select all

30	Virtuale sensoren	82030	1	Watermeter	General	Counter Incremental	329.286 m3	10	-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

Evertjob89 wrote: Monday 17 December 2018 16:37 Currently i'm running an setup with a NPN watermeter sensors and this works fine.
I'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Could be something like this. Please check the log for a couple of hours to see if factor is set right for your meter.

Code: Select all

return  {
    
    on          =   {   devices         =   { "Watermeter"    }}, 
                    
    data        =   {   watermeter      =   { history = true, maxHours = 2 }},
    
    logging     =   {   
                        level           =   domoticz.LOG_DEBUG,
                        marker          =   "watermeter"     
                    },

    execute = function(dz,item)
    
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
    	
    	-- JSON call to emulate waterflow
  	 -- http://192.168.192.51:8084/json.htm?type=command&param=udevice&idx=1242&svalue=1
  
        dz.data.watermeter.add(item.counter)
	   
        local minutes               = 17
        local maxLitersPerMinute    = 5.5
        local meterFactor           = 100
        
        local max                   = dz.data.watermeter.maxSince('00:'.. minutes .. ':00')
        local min                   = dz.data.watermeter.minSince('00:'.. minutes .. ':00')
        local litersPerMinuteNotify = (max - min) / minutes * meterFactor
        local litersPerMinuteNow    = dz.data.watermeter.avgSince('00:01:00') * meterFactor
        
        if litersPerMinuteNotify > maxLitersPerMinute then
            dz.notify   (   
                            'Water usage high!!',
                            'The waterusage is ' .. dz.utils.round(litersPerMinuteNotify,1) .. ' liter a minute!',
                            dz.PRIORITY_HIGH
                        )
        end
        logWrite("Current water usage: " .. dz.utils.round(litersPerMinuteNow,1) .. " liter a minute")
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Evertjob89
Posts: 7
Joined: Sunday 18 November 2018 9:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get average watermeter data

Post by Evertjob89 »

waaren wrote: Monday 17 December 2018 21:05
Evertjob89 wrote: Monday 17 December 2018 16:37 Currently i'm running an setup with a NPN watermeter sensors and this works fine.
I'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Could be something like this. Please check the log for a couple of hours to see if factor is set right for your meter.

Code: Select all

return  {
    
    on          =   {   devices         =   { "Watermeter"    }}, 
                    
    data        =   {   watermeter      =   { history = true, maxHours = 2 }},
    
    logging     =   {   
                        level           =   domoticz.LOG_DEBUG,
                        marker          =   "watermeter"     
                    },

    execute = function(dz,item)
    
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
    	
    	-- JSON call to emulate waterflow
  	 -- http://192.168.192.51:8084/json.htm?type=command&param=udevice&idx=1242&svalue=1
  
        dz.data.watermeter.add(item.counter)
	   
        local minutes               = 17
        local maxLitersPerMinute    = 5.5
        local meterFactor           = 100
        
        local max                   = dz.data.watermeter.maxSince('00:'.. minutes .. ':00')
        local min                   = dz.data.watermeter.minSince('00:'.. minutes .. ':00')
        local litersPerMinuteNotify = (max - min) / minutes * meterFactor
        local litersPerMinuteNow    = dz.data.watermeter.avgSince('00:01:00') * meterFactor
        
        if litersPerMinuteNotify > maxLitersPerMinute then
            dz.notify   (   
                            'Water usage high!!',
                            'The waterusage is ' .. dz.utils.round(litersPerMinuteNotify,1) .. ' liter a minute!',
                            dz.PRIORITY_HIGH
                        )
        end
        logWrite("Current water usage: " .. dz.utils.round(litersPerMinuteNow,1) .. " liter a minute")
    end
}

Code: Select all

2018-12-17 21:12:29.649 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua
2018-12-17 21:12:59.690 Status: dzVents: Info: Handling events for: "Watermeter", value: "0.00"
2018-12-17 21:12:59.690 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-17 21:12:59.692 Status: dzVents: Debug: watermeter: Current water usage: 32938.2 liter a minute
2018-12-17 21:12:59.693 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-17 21:13:50.929 Status: dzVents: Info: Handling events for: "Watermeter", value: "0.00"
2018-12-17 21:13:50.929 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-17 21:13:50.930 Status: dzVents: Debug: watermeter: Current water usage: 32938.2 liter a minute
2018-12-17 21:13:51.044 Status: dzVents: Info: watermeter: ------ Finished Test
It should be zero because there is no waterflow at the moment? The current count is 329.382
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

Evertjob89 wrote: Monday 17 December 2018 16:37 Currently i'm running an setup with a NPN watermeter sensors and this works fine.
I'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Modified the calculation of current flow. Can you try this ? and please check the log for a couple of hours to see if factor is set right for your meter.

Code: Select all

return  {
    
     on          =   {   devices         =   { "Watermeter"    }}, 
                    
    data        =   {   watermeter      =   { history = true, maxHours = 2 }},
    
    logging     =   {   
                        level           =   domoticz.LOG_DEBUG,
                        marker          =   "watermeter"     
                    },

    execute = function(dz,item)
    
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
    	
    	-- JSON call to emulate waterflow
  	 -- http://192.168.192.51:8084/json.htm?type=command&param=udevice&idx=1242&svalue=0
  
        dz.data.watermeter.add(item.counter)
        local minutes               = 17
        local maxLitersPerMinute    = 5.5
        local factor                = 100
        
        local max                   = dz.data.watermeter.maxSince('00:'.. minutes .. ':00')
        local min                   = dz.data.watermeter.minSince('00:'.. minutes .. ':00')
        local litersPerMinuteNotify = (max - min) / minutes * factor
        local current               = dz.data.watermeter.get(1).data 
        
        local previous, previousTime, litersPerMinuteNow 
        
        if dz.data.watermeter.get(2) ~= nil then
            previous            = dz.data.watermeter.get(2).data 
            previousTime        = dz.data.watermeter.get(2).time.msAgo
            litersPerMinuteNow  = (( current - previous ) / (previousTime / 60000 )) * factor  -- 60000 = msecs in a minute
            logWrite("Current water usage: " .. dz.utils.round(litersPerMinuteNow,1) .. " liter a minute")
        else
            logWrite("Current water usage cannot be determined (not enough data in history)")
        end
	   
        
        if litersPerMinuteNotify > maxLitersPerMinute then
            dz.notify   (   
                            'Water usage high!!',
                            'The waterusage is ' .. dz.utils.round(litersPerMinuteNotify,1) .. ' liter a minute!',
                            dz.PRIORITY_HIGH
                        )
        end
        
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Evertjob89
Posts: 7
Joined: Sunday 18 November 2018 9:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get average watermeter data

Post by Evertjob89 »

waaren wrote: Monday 17 December 2018 22:15
Evertjob89 wrote: Monday 17 December 2018 16:37 Currently i'm running an setup with a NPN watermeter sensors and this works fine.
I'm looking for a script that could help me but because i don't get DzVents as everyone else (maybe i'm thinking to difficult?) but the idea should be The idea is very simple, but i'm not getting it working (And i would like to not test it for 17 minutes)
Modified the calculation of current flow. Can you try this ? and please check the log for a couple of hours to see if factor is set right for your meter.

Code: Select all

return  {
    
     on          =   {   devices         =   { "Watermeter"    }}, 
                    
    data        =   {   watermeter      =   { history = true, maxHours = 2 }},
    
    logging     =   {   
                        level           =   domoticz.LOG_DEBUG,
                        marker          =   "watermeter"     
                    },

    execute = function(dz,item)
    
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
    	
    	-- JSON call to emulate waterflow
  	 -- http://192.168.192.51:8084/json.htm?type=command&param=udevice&idx=1242&svalue=0
  
        dz.data.watermeter.add(item.counter)
        local minutes               = 17
        local maxLitersPerMinute    = 5.5
        local factor                = 100
        
        local max                   = dz.data.watermeter.maxSince('00:'.. minutes .. ':00')
        local min                   = dz.data.watermeter.minSince('00:'.. minutes .. ':00')
        local litersPerMinuteNotify = (max - min) / minutes * factor
        local current               = dz.data.watermeter.get(1).data 
        
        local previous, previousTime, litersPerMinuteNow 
        
        if dz.data.watermeter.get(2) ~= nil then
            previous            = dz.data.watermeter.get(2).data 
            previousTime        = dz.data.watermeter.get(2).time.msAgo
            litersPerMinuteNow  = (( current - previous ) / (previousTime / 60000 )) * factor  -- 60000 = msecs in a minute
            logWrite("Current water usage: " .. dz.utils.round(litersPerMinuteNow,1) .. " liter a minute")
        else
            logWrite("Current water usage cannot be determined (not enough data in history)")
        end
	   
        
        if litersPerMinuteNotify > maxLitersPerMinute then
            dz.notify   (   
                            'Water usage high!!',
                            'The waterusage is ' .. dz.utils.round(litersPerMinuteNotify,1) .. ' liter a minute!',
                            dz.PRIORITY_HIGH
                        )
        end
        
    end
}
I've tried it and it works, only not as i thought: I've want an average (Usage / Time = Result) for the last 17 minutes, right know it's giving me the result for every minute:

Code: Select all

2018-12-18 15:53:40.529 Status: dzVents: Info: Handling events for: "Watermeter", value: "0.00"
2018-12-18 15:53:40.529 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:53:40.560 Status: dzVents: Debug: watermeter: Current water usage: 0 liter a minute
2018-12-18 15:53:40.568 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:54:40.490 Status: dzVents: Info: Handling events for: "Watermeter", value: "6.00"
2018-12-18 15:54:40.490 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:54:40.520 Status: dzVents: Debug: watermeter: Current water usage: 0.6 liter a minute
2018-12-18 15:54:40.527 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:55:01.324 Status: dzVents: Info: Handling events for: "Watermeter", value: "4.00"
2018-12-18 15:55:01.326 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:55:01.355 Status: dzVents: Debug: watermeter: Current water usage: 1.2 liter a minute
2018-12-18 15:55:01.362 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:55:52.990 Status: dzVents: Info: Handling events for: "Watermeter", value: "14.00"
2018-12-18 15:55:52.990 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:55:53.019 Status: dzVents: Debug: watermeter: Current water usage: 1.6 liter a minute
2018-12-18 15:55:53.026 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:56:44.405 Status: dzVents: Info: Handling events for: "Watermeter", value: "11.00"
2018-12-18 15:56:44.405 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:56:44.434 Status: dzVents: Debug: watermeter: Current water usage: 1.3 liter a minute
2018-12-18 15:56:44.442 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:57:35.673 Status: dzVents: Info: Handling events for: "Watermeter", value: "8.00"
2018-12-18 15:57:35.673 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:57:35.702 Status: dzVents: Debug: watermeter: Current water usage: 0.9 liter a minute
2018-12-18 15:57:35.709 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:58:27.354 Status: dzVents: Info: Handling events for: "Watermeter", value: "8.00"
2018-12-18 15:58:27.354 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:58:27.383 Status: dzVents: Debug: watermeter: Current water usage: 0.9 liter a minute
2018-12-18 15:58:27.390 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 15:59:08.583 Status: dzVents: Info: Handling events for: "Watermeter", value: "5.00"
2018-12-18 15:59:08.583 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 15:59:08.612 Status: dzVents: Debug: watermeter: Current water usage: 0.7 liter a minute
2018-12-18 15:59:08.619 Status: dzVents: Info: watermeter: ------ Finished Test
2018-12-18 16:00:01.630 Status: dzVents: Info: Handling events for: "Watermeter", value: "0.00"
2018-12-18 16:00:01.630 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 16:00:01.662 Status: dzVents: Debug: watermeter: Current water usage: 0 liter a minute
2018-12-18 16:00:01.669 Status: dzVents: Info: watermeter: ------ Finished Test

Ive used 56 liters in 8 minutes so the result should be 56 / 8 = 7.25

Code: Select all

2018-12-18 16:00:01.630 Status: dzVents: Info: Handling events for: "Watermeter", value: "0.00"
2018-12-18 16:00:01.630 Status: dzVents: Info: watermeter: ------ Start internal script: Test: Device: "Watermeter (Virtuale sensoren)", Index: 30
2018-12-18 16:00:01.662 Status: dzVents: Debug: watermeter: Current water usage: 7.25 liter a minute
2018-12-18 16:00:01.669 Status: dzVents: Info: watermeter: ------ Finished Test
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

Evertjob89 wrote: Tuesday 18 December 2018 16:08 I've tried it and it works, only not as i thought: I've want an average (Usage / Time = Result) for the last 17 minutes, right know it's giving me the result for every minute:
What you see is debug information. These are the values calculated every time the script executes.
If the water usage is above the set average (5.5) for the set period (17 minutes ) the script should send a notification.

If you want to test you can lower these settings by modifying the lines

Code: Select all

        local minutes               = 17
        local maxLitersPerMinute    = 5.5
and set them to a lower value.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

Script is working excellent also for me but i would like add switch in section when alerts is on.

Code: Select all

       if litersPerMinuteNotify > maxLitersPerMinute then    
            --I added here     
                 execute = function(domoticz, alert_woda)
                 local alarmwoda = domoticz.devices('Woda Alarm')
                 alarmwoda.switchOn()
                end
                
But switch state Off and no errors. What i am doing wrong
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

rodaman wrote: Monday 17 February 2020 13:05 Script is working excellent also for me but i would like add switch in section when alerts is on.

Code: Select all

       if litersPerMinuteNotify > maxLitersPerMinute then    
            --I added here     
                 execute = function(domoticz, alert_woda)
                 local alarmwoda = domoticz.devices('Woda Alarm')
                 alarmwoda.switchOn()
                end
                
But switch state Off and no errors. What i am doing wrong
You don't need the repetition of the execute section. Just use

Code: Select all

       if litersPerMinuteNotify > maxLitersPerMinute then    
            --add this line
            dz.devices('Woda Alarm').switchOn()
            
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data  [Solved]

Post by rodaman »

It works!!! Thank you. I have to study DzVents better.
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

My friend got bill 200E for water. 2 times. After that he discovered that he had very little leakage from woodburner where is water valve for emergence. If there is power cut and woodburner is full of burning wood and pump stop pumping hot water, woodburner could explode so thermovalve open cold water for cooling stove. That valve opened just a little and he had very little leakage for very long time directly to sewage pipe so he could not spoted it. I have the same valve in my stove. How to check database water usage if there is no 0 usage during 24h for example?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

rodaman wrote: Tuesday 18 February 2020 15:00 How to check database water usage if there is no 0 usage during 24h for example?
How many liters per day or per week should be considered as too much ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

I was thinking like, it should be 0 (zero) liter at some point in 24 hours. If there is a constant liittle leakage it will never be 0. Am I wrong?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

rodaman wrote: Tuesday 18 February 2020 15:40 I was thinking like, it should be 0 (zero) liter at some point in 24 hours. If there is liittle leakage it will never be 0. Am I wrong?
I guess you are right but how long do you want to monitor the meter before you conclude the usage you measure is from a leak and not from common usage ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

During 24 hours I would like check if there is 0 liters usage. It should be especially in the night in my case . If 0 never occur for given time- alarm.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

rodaman wrote: Tuesday 18 February 2020 15:53 During 24 hours I would like check if there is 0 liters usage. It should be especially in the night in my case . If 0 never occur for given time- alarm.
Probably a language thing but I try to understand what your definition is for 'given time'. Is it 3 days, a week, a month or something else ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

Ok, sorry. Let say 24 hours because I can see in a daily Domoticz report every night I have zero usage at some point so I do not have a little leakage. No need immediate action, just check if 0 occured during last 24 hours. Maybe I am wrong but I thought Domoticz keep detailed values for 24 hrs.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get average watermeter data

Post by waaren »

rodaman wrote: Tuesday 18 February 2020 16:27 Ok, sorry. Let say 24 hours because I can see in a daily Domoticz report every night I have zero usage at some point so I do not have a little leakage. No need immediate action, just check if 0 occured during last 24 hours. Maybe I am wrong but I thought Domoticz keep detailed values for 24 hrs.
You could try this. It should notify you when there was no water usage in the last 24 hours.
Don't expect a notification the first time. The value is initialized then.

Code: Select all

local watermeterName = 'Watermeter' -- device name of watermeter

return
{
    on =
    {
        timer =
        {
            'at 22:00',
        },

        devices =
        {
            watermeterName
        },
    },

     data = 
     {
          waterTotal = { initial = 0 },
          watermeter = { history = true, maxHours = 2 },
     },
    
    logging    =
    {
        level =  domoticz.LOG_DEBUG,
        marker = 'watermeter',
    },

    execute = function(dz, item)
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        -- JSON call to emulate waterflow
       -- http://192.168.192.51:8084/json.htm?type=command&param=udevice&idx=1242&svalue=0

        if item.isTimer then
           local watermeter = dz.devices(watermeterName)
            if watermeter.counter == dz.data.waterTotal then
                logWrite("No water usage today")
                dz.notify ('Water usage', 'There was no waterusage today', dz.PRIORITY_NORMAL )
            else
                dz.data.waterTotal = watermeter.counter
            end
            return
        end

        dz.data.watermeter.add(item.counter)
        local minutes               = 17
        local maxLitersPerMinute    = 5.5
        local factor                = 100
        local max                   = dz.data.watermeter.maxSince('00:'.. minutes .. ':00')
        local min                   = dz.data.watermeter.minSince('00:'.. minutes .. ':00')
        local litersPerMinuteNotify = (max - min) / minutes * factor
        local current               = dz.data.watermeter.get(1).data

        local previous, previousTime, litersPerMinuteNow

        if dz.data.watermeter.get(2) ~= nil then
            previous            = dz.data.watermeter.get(2).data
            previousTime        = dz.data.watermeter.get(2).time.msAgo
            litersPerMinuteNow  = (( current - previous ) / (previousTime / 60000 )) * factor  -- 60000 = msecs in a minute
            logWrite("Current water usage: ' .. dz.utils.round(litersPerMinuteNow,1) .. ' liter a minute")
        else
            logWrite("Current water usage cannot be determined (not enough data in history)")
        end

        if litersPerMinuteNotify > maxLitersPerMinute then
            dz.notify   (
                            'Water usage high!!',
                            'The waterusage is ' .. dz.utils.round(litersPerMinuteNotify,1) .. ' liter a minute!',
                            dz.PRIORITY_HIGH
                        )
            dz.devices('Woda Alarm').switchOn()
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Get average watermeter data

Post by rodaman »

Thank you for the script. I was thinking more that notification should be when non "0" occur during 24hrs. It could be sign that I have constant usage, very small but constant. What is "waterTotal" as a value. Maybe I can figure out how to write the script by me. I am very appreciated for your help.
Post Reply

Who is online

Users browsing this forum: RonkA and 1 guest