Best strategy for measuring consumption?

Folks,

I have the water meter which measures water flow and publishes it, L/min, using mqtt.
I want to have an alert to tell me when 100L (for example) of water has been used continuously. i.e pond/pool is full or the kids have had long enough in the shower.

How can I, in OH rules, convert this to a volume?
Below is the persisted data which is from a single number item.

"2019-12-25 21:18:09"	"15.36"
"2019-12-25 21:18:08"	"15.23"
"2019-12-25 21:18:06"	"15.11"
"2019-12-25 21:18:05"	"15.23"
"2019-12-25 21:18:04"	"19.36"
"2019-12-25 21:18:03"	"22.85"
"2019-12-25 21:18:01"	"22.73"
"2019-12-25 21:18:00"	"22.98"
"2019-12-25 21:17:59"	"22.35"
"2019-12-25 21:17:58"	"22.73"
"2019-12-25 21:17:57"	"20.23"
"2019-12-25 21:17:51"	"18.98"
"2019-12-25 21:17:48"	"19.11"
"2019-12-25 21:17:47"	"19.23"
"2019-12-25 21:17:45"	"19.11"
"2019-12-25 21:17:44"	"19.23"
"2019-12-25 21:17:43"	"20.1"
"2019-12-25 21:17:41"	"23.6"
"2019-12-25 21:17:40"	"19.36"
"2019-12-25 21:17:39"	"10.99"
"2019-12-25 21:17:37"	"8.49"
"2019-12-25 21:17:36"	"4.75"
"2019-12-25 21:17:26"	"0"
"2019-12-25 21:17:25"	"0.5"
"2019-12-25 21:17:22"	"7.74"
"2019-12-25 21:17:21"	"7.87"
"2019-12-25 21:17:19"	"7.74"
"2019-12-25 21:17:17"	"7.87"
"2019-12-25 21:17:16"	"0.12"
"2019-12-25 21:15:01"	"0"
"2019-12-25 21:13:21"	"0"
"2019-12-25 21:13:20"	"1.25"
"2019-12-25 21:13:19"	"6.74"
"2019-12-25 21:13:15"	"9.37"
"2019-12-25 21:13:14"	"9.43"

Cheers,
C

You likely need to define a timeframe for “continuously”. 1 hour or 1 week?

You are getting an update every second so you need do some maths. Just a bit.
Use the persistence averageSince method: https://www.openhab.org/docs/configuration/persistence.html#persistence-extensions-in-scripts-and-rules

Do the average since the last hour, that will give you the average flow for the last hour in l/min
Multiply by 60 will give the volume used in that hour. If more than 100 then trigger what you want.

It will not be trivial to do the continuously part. But 1 hour should give a good starting point

1 Like

What kind of water meter do you use?
What is the scale value of the meter output?
Possible to calculate the flow in the meter?

1 Like

What I’m trying to do is alert every, for example, 100L. A pause of zero-usage for, say 5 minutes, would reset the counter. This would indicate the kid(s) have finished showering, gives me an idea of how much watering has happened in the garden etc.

I could be over thinking it too. Sprinklers, hose, shower etc, all have a certain flow rate. Maybe just checking how long they have been on for will suffice.

I was playing around with that but was thinking there might be a better way. Would averaging it not lose accuracy?

If my measurements are every second and given as L/m, would taking each value, dividing it by 60 and then summing them for the hour, that would give me L/s * 3600 = litres in the last hour.
I could then persist that to another item as L/h
I could simplify the above if I changed the Arduino code to report L/s every second.

It’s a custom built one. As above, I could change the code to report in L/s which would make it simpler in OH to calc.

I’d say there are a few ways to go about this.
First of all, create an item that stores the volume and an item that stores a datetime since when that volume is valid, for convenience. Then, make a rule that runs every time your flow item gets an update. If you are sure the interval between the updates is 1 second always, just divide the value by 60 to get the volume in that interval.
If the time actually varies, you will have to track the time since the previous update and use that time interval to calculate the volume in that interval. In that case, you will also need to consider which flow value you should use then, because it might make more sense to take the average of the previous value and the new value, or even only use the old value, and multiply that with the time interval (in minutes).

Then, add that volume to the value of the volume item you made, and set the datetime item to the current time as well.

Last step will be to make a timer and store that in a global variable (defined at the top of the rule file) with a schedule of say 5 minutes. In that time, reset the volume item to 0 and set the datetime item to null. And unset the timer.
Wrap that timer in an if statement that creates the timer if it isn’t set yet, and otherwise, if the timer is already running, reschedule it for 5 minutes later.

To deal with the volume going above a certain value, you could either check that in the same rule, but I would suggest make a separate rule for the volume item, to check when it changes above 100 L, and then send a notification, turn of the boiler, sound an alarm, or whatever you like.

That should basically do what you are looking for.

I ended up with this

Number  utility_water_main_usage_hour   "Water usaga by hour"           (g_persist_change, Group_HabPanel_Dashboard)
rule "Utility - Water Usage by Hour"
when Time cron "10 0 0/1 1/1 * ? *" //10 seconds past every hour
then
    val Number tVal = utility_water_main_flow_rate.sumSince(now.minusHours(1)) / 60 //measurments are in L/m

    utility_water_main_usage_hour.postUpdate(tVal.toString)
end

What I end up with then is an item which, every hour, will have the L/h used.

Within that rule I can now track the continuous usage. As you say, I can now keep adding the value to a global variable and, when it trips mod 100, send an alert. When it hits zero for n number of seconds, I can zero.

The Arduino code only sends updates every second when there is water flow. Nothing after the first (couple of) zero measurements.

Ah ah. Now we can be more accurate.
Pseudo code
When 2 updates are zero (flow is stopping) set folw flag to false
When update is more than zero (The first time) set flow flag to true and measuse the time

Then every update use averagedSince.(measureTimeFlowStart) and divide by (now - measuredTimeFlowStart) in seconds

This should give a pretty accurate volume since start of flow

Reset when flow stops