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.
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.
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
val Number tVal = utility_water_main_flow_rate.sumSince(now.minusHours(1)) / 60 //measurments are in L/m
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.
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