Filling a water container from empty


Hi. First project using Raspberry Pi.

So I wish to allow a water container to reach almost empty, before being refilled to top (I don’t want to maintain the tank at the high level).

I have the water supplied via a solenoid valve which is controlled via a float switch in the solenoid 12v circuit so when the water rises to almost full it cuts off the supply (This is the switch A). I can easily connect a relay to the solenoid 12v supply also.

I have set up a float switch to the pi as a generic digital input that provides a high/low value which is correctly recording on the Cayenne interface - which can therefore be used to detect the water level having fallen to “almost empty” (I’ll call this the switch B).

I can see how a Trigger can be used to open the relay based on B being low - but assume that as soon as B is high the relay would shut off - meaning the tank would start full, fall to near empty and then be maintained at “near empty”.

I would like to trigger the relay IF B reads low (which will always mean both A and B are low) and the valve to remain open until both A and B are high.

Can someone explain how I can make this happen please?

Many thanks in advance.



Seeing as how you’re dealing with water I would probably opt for a local solution instead of Cayenne. If the cloud servers or your internet ever go down while you are filling you will be in for quite a mess!

That being said, if you want to do it all you have to do is set up 2 triggers: one to read if B is low and set the pin for the relay to be on, and another to read if A is high and set the pin for the relay.


ok. I guess this is the bit I’m not getting. As soon as the water fills and B is no longer low, won’t the relay switch off and the water stop? Is a trigger only “one way”?


OK. I got it. My error was that I thought the float switch would act as a “switch” rather than a trigger. I’ve set up as you described Adam and I’ve retained a third float switch in the solenoid power line. That way if the Pi fails “open” and the tank continues to fill it will trip the power from the solenoid which will close.


Nice solution!


need code for interfacing solenoid with cayenne.