Water level sensor, looking for ideas

We have water tank in the house whose water is supplied by the County. The water is supplied in the morning between 5 and 6am. The start and end time is not strict. Each day somebody has to wakeup in the morning to switch on the pump, so that the water from the incoming pipeline can be fed to the overhead water tank. I want to automate the pump switch on and off with openhab.

I am looking for suggestions on how to implement this in rules. My current thinking is to have a cron job which turns on the pump at 5am. It then runs the pump for 5 minutes and finds out the water level at the end. If the water level has increased than the pump should be kept on until the tank is full. On the other hand if the water level has not changed at the end of 5 minutes than the pump should be switch off for 10 minutes. So every 15 minutes the pump should be turned on and water level should be checked. This way the pump doesnt need to be on when there is no water in the pipeline.

Does this make sense and how would you write a rule for this?

Do you have a device to sense the water level in the supply tank? I would think you could use this as a trigger for both turning the pump on and off.

I’m not familiar with water pumps, but would think running it dry would not be good for it. Does your pump have any protection to prevent it from running dry, or does it not have a problem with it?

I am going to use an ultrasonic sensor to measure the water level. The uncertainty is I don’t know when the County will release the water to the pipeline. Is there any sensor which can be attached to a faucet/tap to detect if water is coming through?

The pump won’t like to be run dry. Hence I am limiting to run it for 5 minutes in every 15 minutes until water level increase is detected.

In the supply tank or the overhead tank? My thought was that when the county fills the supply tank, a sensor could change state, a rule would turn on the pump, and when the water goes below the sensor, turn off the pump. Some logic may be needed if the filling of the tank is slower than the rate of the pump, or the pump could get switched on and off too much.

Yes… there are flow sensors. I’ve seen at least one that uses zwave, but it was RIDICULOUSLY over priced. I’ve looked into building one, possible using something like this, or a noninvasive inductive coil. It’s not a flow meter, but this looks good for your application. You’ve probably already found this one.

The specifics of any solution will depend on how you detect that the water is flowing. But at a high level you can code the overall behavior using Timers.

var pumpTimer = null

rule "Pump control"
when
    Time cron "0 0 5 * * * *" // I'm not sure I have this right, double check
then
    // create a Timer that will go off immediately
    pumpTimer = createTimer(now.plusSeconds(0), [ |

        // the Pump is OFF, turn it ON for 5 minutes to see if the water is flowing
        if(Pump.state == OFF) {
            Pump.sendCommand(ON)
            pumpTimer.reschedule(now.plusMinutes(5))
        }

        // the Pump is Running
        else {

            // Water is flowing, keep checking for tank full or water stopped flowing every second
            if(water level is changing or water is flowing) {
                // check every second, stop when full or water stops 
                pumpTimer = createTimer(now.plusSeconds(1), [ |
                    if(tank is not yet full and water level is still going up/water is still flowing) pumpTimer.reschedule(now.plusSeconds(1)
                    else {
                        Pump.sendCommand(OFF)
                        pumpTimer = null
                    }
                ])
            } // water is flowing

            // Water is not flowing, turn OFF the pump for 10 minutes and try again
            else {
                Pump.sendCommand(OFF)
                pumpTimer.reschedule(now.plusMinutes(10))
            }
        } // pump is running
    ])
end

I don’t like this code as written and if I had time I’d try to come up with a lest nested (timers inside of timers) approach. But it should work, or get you close to something that works in terms of the timing.

How it works is at 05:00 we create a Timer that kicks off immediately.

If the Pump is OFF when the Timer starts running we turn on the Pump and reschedule the Timer for five minutes.

If the Pump is already ON then we check to see if the water is flowing. If the water is flowing we create a new Timer that loops every second to check whether the tank is full or the water has stopped flowing (you may need more time to sense if the water is still flowing with a sonic sensor). When that occurs the Pump is turned OFF and the timer exits otherwise we reschedule the timer to check again in a second.

If the water is not flowing then we stop the Pump and reschedule the Timer to run again in 10 minutes.

I don’t normally like to just write Rules for folks without their trying first, but one is a really complex one.

1 Like

The water comes through a pipeline which is at ground level. A pump is attached to the pipeline and it used to pump water to the overhead tank. In hindsight, i dont really need to measure the flow rate. All i need to know is whether the pipeline has sufficient pressure as it is an indicator that the County is supplying water.

I think hooking this sensor to the pipeline would be a good option. I could then track the pressure and turn on the pump if the pressure is sufficient.

I am thinking of using this sensor in the overhead tank as it is water proof. I have seen reports that the version 2 of this sensor has some stability issues, so will need to see how this works out.

Thanks. This is a very nice post and will give me a basis to start out. I was wondering whether it is possible to try out this code with virtual devices before connecting it for real. The Pump ON/OFF state could be simulated using a proxy switch, but I am not sure how to represent the water level. Maybe i can use an integer counter.

You should also take a look at:

I would be careful about turning on the pump for 5 minutes on an empty supply. Water pump are not designed to run without water and you may damage it.
If you level sensor is sensitive enough try to reduce the amount of time it runs on empty.

  1. Use a pressure switch to sense when to turn the pump on
  2. Use a flow sensor to confirm flow.

Avoid any sort of level sensor except float switches as they are unreliable!