Calculate consumption rainwater

I’m trying to figure out if I could calculate the amount of rainwater we use. I’ve got a pressure sensor, that calculates the level of my rain tank. That part works great (see below).

I would like now to have a kind of counter that gives me the amount of water we used.
So I was thinking of a kind of counter, that counts the value when it drops with bigger values then 0.05.

Workflow that pop ups in my head:

  1. If new value of sensor is lower then previous
  2. and if the difference if bigger then 0.05
  3. convert it to %, and calcute amount of L from tank (ref 10.000)
  4. take value from UsuageTotal, and add the previous result

Any suggestion on it?




Some info of my current setup:

Item:

Number  Waterput1a   "Waterput1a [%s]"   { channel="knx:device:f17df1a7:1" }

Rule I’m using today to convert it to % levels.

//------------------------------------------------------------------------------------------
rule "Waterlevel"
when
        Item Waterput1a changed
then
        val Number WellMinI = 4.64              // Level for empty tank
        val Number WellMaxI = 7.96              // Level for full tank
        if      ((Waterput1a.state as Number) < WellMinI)       {Waterput3Proc.postUpdate (0)}
        else if ((Waterput1a.state as Number) > WellMaxI)       {Waterput3Proc.postUpdate (100)}
        else                                                    {Waterput3Proc.postUpdate ((((Waterput1a.state as Number) - WellMinI) / (WellMaxI - WellMinI)) * 100)}
end

A bit annoying is that the levels are so little, that I’ve got a huge of readings that are ‘false’. In this log, you can see it rains around 20:55, just for about 20 minutes…

log/events.log.14:2022-01-31 20:33:01.062 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.86
log/events.log.14:2022-01-31 20:35:01.056 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.84
log/events.log.14:2022-01-31 20:36:01.051 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.82
log/events.log.14:2022-01-31 20:37:01.046 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.82 to 7.84
log/events.log.14:2022-01-31 20:38:01.042 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.82
log/events.log.14:2022-01-31 20:39:01.038 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.82 to 7.84
log/events.log.14:2022-01-31 20:42:01.027 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.82
log/events.log.14:2022-01-31 20:43:01.020 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.82 to 7.84
log/events.log.14:2022-01-31 20:44:01.016 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.86
log/events.log.14:2022-01-31 20:45:01.013 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.84
log/events.log.14:2022-01-31 20:46:01.010 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.86
log/events.log.14:2022-01-31 20:47:01.019 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.84
log/events.log.14:2022-01-31 20:48:01.001 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.82
log/events.log.14:2022-01-31 20:49:00.996 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.82 to 7.86
log/events.log.14:2022-01-31 20:50:00.990 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.84
log/events.log.14:2022-01-31 20:52:00.981 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.84 to 7.88
log/events.log.14:2022-01-31 20:54:00.974 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.88 to 7.86
log/events.log.14:2022-01-31 20:57:00.958 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.9
log/events.log.14:2022-01-31 20:58:00.965 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.86
log/events.log.14:2022-01-31 21:01:00.944 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.86 to 7.9
log/events.log.14:2022-01-31 21:03:00.963 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92
log/events.log.14:2022-01-31 21:04:00.928 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.88
log/events.log.14:2022-01-31 21:06:00.922 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.88 to 7.9
log/events.log.14:2022-01-31 21:11:00.904 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92
log/events.log.14:2022-01-31 21:12:00.893 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.9
log/events.log.14:2022-01-31 21:13:00.903 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92
log/events.log.14:2022-01-31 21:15:00.881 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.94
log/events.log.14:2022-01-31 21:16:00.882 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.94 to 7.92
log/events.log.14:2022-01-31 21:20:00.872 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.9
log/events.log.14:2022-01-31 21:21:00.857 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92
log/events.log.14:2022-01-31 21:29:00.830 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.9
log/events.log.14:2022-01-31 21:30:00.832 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92
log/events.log.14:2022-01-31 21:33:00.813 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.92 to 7.9
log/events.log.14:2022-01-31 21:34:00.802 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.94
log/events.log.14:2022-01-31 21:35:00.801 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.94 to 7.9
log/events.log.14:2022-01-31 21:37:00.784 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Waterput1a' changed from 7.9 to 7.92

Perhaps the first thing to do then, is clean up the jittery source data.
Calculating the level from an average of last 5 or 10 mins by persistence should do it, I would guess.

The maybe look at the delta between a 10-min average and 5-min average to see whats going in/out.

Consumption is only ever going to be approximate if you cannot sense either input or output.

Watch out for a slow leak type situation. It’s not clear but for 2, you need to run if the difference is bigger than 0.05 from the last processed reading, not just the last reading. For example, you receive 50 readings that go down only by 0.04 between each, your tank will be empty and your rule will never have run.

I recently published a rule template to the Marketplace that might make a good starting point for something like this (templates are only available in the UI though). To do so you’d install the template and instantiate a new rule from it. Trigger the rule using Waterput1a. You’ll need another Item to store the totals for the second property when installing the rule, we’ll call that Waterput1aSum.

But this rule assumes it’s always counting up and treats new readings that are lower than the last as the sensor having been reset so we need to customize it some.

  1. Add a new Item to store the last processed reading, we’ll call that Waterput1aLastProcessed

  2. Add a new condition (Rules DSL) with code along these lines:

val curr = newState as Number
val lastState = previousState as Number
val lastProcessed = Waterput1aLastProcessed.state as Number
val delta = lastProcessed - curr

curr < lastState && delta >= 0.05

That will only allow the rule to run if the current reading is less than the last reading and the current reading is more than 0.05 less than the last processed reading (which avoids the slow leak problem).

  1. The calculation in the rule’s action assumes the reading is always counting up but in this case we are always counting down. So we need to make one minor change to the code. Change the following line:
var delta = (reading < lastReading) ? reading : (reading - lastReading);

To

var delta = Math.abs(reading - lastReading);

That will make the total increase as the readings decrease. We don’t have to care about seeing is reading is greater than the last reading because that’s now handled in the condition.

  1. We need to record the Item as having been processed. Add a new Script Action (if you want to stick to Rules DSL) with the following line.
Waterput1aLastProcessed.postUpdate(newState)

That should do it. If you want you could instead add the following line of ECMAScript to the existing action.

items.getItem('Waterput1aLastProcessed').postUpdate(newState);

Even if you don’t use the rule template, this should give you enough of an example to work from.

1 Like

Thanks for the detailled explanation! Will certainly try to build something with it.

Guess that I’ll have an issue, since for example an average toilet use is 3 ~ 8 liter. And with a tank of 10.000 liter, this is very small. In my graphs, you see it going down over a longer period, but an average flush fe isn’t noticeable in the logs. At least not at first sight.



This is fe the same, but for a smaller tank (3.000 liter). Mostly used for washingmachine. Drops are clearer.



Maybe it would be better to take fe every half hour a measurement?

The end idea is to have a montly/yearly/… view how much rainwater has been used.

One of the advantages you get by calculating the delta from the last time you processed the change is that it doesn’t matter how long it takes for the value to fall below the threshold.

However, this raises a concern because there will be lots of situations where usage will be missed. What if you run the washing machine while it’s raining? The level might be going up faster than it drops from usage. What if it dropped just a little, not enough to trigger the rule and then it rains?

The calculation will only ever be a rough estimate. To get closer you need to measure the water actually coming out of the pipe, not the tank level, as @rossko57 said.

But the only problem I see with that first graph is that it increases the likelihood that you’ll miss some usages. But I don’t know that taking more frequent readings will help much.The problem is the precision of the measurement, not the time between measurements. If you can’t see a toilet flush in the data, taking more frequent readings isn’t going to fix that.

Here in Belgium, they’re rolling out smart energy meters. The ‘goverment’ want us to spread our consumption. Use power when there’s sun! So in the future, we shouldn’t wash when it’s rain. :wink:
But I see your point.

I’ve got also power meters on the pumps? I can put them ON/OFF when the tank reach a certain level. These power meters also measure the current.
So maybe it’s an option to only measure it when the pump is running? Or better, do the measurement when it stops? Or maybe a duration pump = amount liters?

Current pump:
2022-02-02 12:57:39.117 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.1 to 1228.3
2022-02-02 12:57:49.117 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1228.3 to 724.4
2022-02-02 12:58:23.115 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 724.4 to 1.1
2022-02-02 13:37:33.106 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.1 to 680.3
2022-02-02 13:37:44.105 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 680.3 to 1.2
2022-02-02 13:37:54.111 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.2 to 687.3
2022-02-02 13:38:08.106 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 687.3 to 1.1
2022-02-02 13:38:22.105 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.1 to 690.1
2022-02-02 13:40:48.109 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 690.1 to 1.2
2022-02-02 13:40:58.109 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.2 to 682.3
2022-02-02 13:45:44.105 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 682.3 to 1.2
2022-02-02 14:01:29.692 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sch_OnOff8_Vermogen' changed from 1.2 to 1.1

And I’ve got a Netatmo rain sensor. Not sure if I can mix it with that? Sadly I don’t see much coming in from this sensor. For example only log on 31/01 for a big rain:

Rain sensor:
log/events.log.10:2022-01-31 02:18:23.123 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0 mm to 0.13600000739097595 mm
log/events.log.10:2022-01-31 02:38:38.616 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.13600000739097595 mm to 0 mm
log/events.log.10:2022-01-31 02:48:34.019 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0 mm to 0.13600000739097595 mm
log/events.log.10:2022-01-31 02:58:39.647 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.13600000739097595 mm to 0 mm
log/events.log.10:2022-01-31 03:08:40.608 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0 mm to 0.13600000739097595 mm
log/events.log.10:2022-01-31 03:18:46.400 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.13600000739097595 mm to 0.2709999978542328 mm
log/events.log.10:2022-01-31 03:28:46.695 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.2709999978542328 mm to 0.13600000739097595 mm
log/events.log.10:2022-01-31 03:38:57.592 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.13600000739097595 mm to 0 mm
log/events.log.12:2022-01-31 20:57:47.329 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0 mm to 0.13600000739097595 mm
log/events.log.12:2022-01-31 21:17:56.198 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'na_Rain_Rain' changed from 0.13600000739097595 mm to 0 mm

I should really need to find once a good explanation of interpreting some values of sensors. Or what we can do with them. I got the same issue with usuage of gas, water… Big data, no big instinct on them… :blush:



Agree, but today no sensors on this output. I didn’t find any ‘claws’ to put on the pipes to measure water movement. And cutting pipes is so drastic.

But I like to try to think out of the box. How we can do great things with the things we have?


ps thank you guys for thinking with us! Always nice to have somebody else vision and experience. We simple don't show our appreciation enough!

What pumps?? Are saying these tanks are filled (or emptied) under control, so you can estimate one of “in” or “out”? This is pretty key.

Sorry, that phrase sounds more intelligent than it’s. :blush:

I’ve got a “FIBARO Switch 2” on the power line of the rainwater pumps. The pumps are very basic.
Main reason is that I can power on/off the pumps in function of the water level, and the function.
One installation is mainly for garden/toilets/…, other installation (better filters) is mainly for washing machine. But both can be disabled/enabled, based on the levels of tanks.

Level of tanks is measured with pressure sensor (ALS-MPM-2F) and KNX input module ( MDT AIO-0210V.01).

Small scheme:

This or put some sort of meter on the actual water flow will probably be your most reliable ways to measure consumption. Anything else will be no better than a rough estimate, which may be good enough.

Using the flow of the pumps comes with its own wrinkle. Does the flow vary based on the water level in the tanks?