Automatic Pool Fill Control

Hello -

My first post here and I thought I would share with everyone a project I have been working on for our pool. I now several others are doing the same thing, but I approached it a little differently.

It is built using the following Hardware and Software:

Raspberry Pi3 LowPowerLabs MightyHat (Pi UPS/Power Control, LCD, RFM69HW 433Mhz Radio, Power Booster, Arduino Clone) 4400mAh LiPo Battery for the MightyHat LowPowerLabs MoteinoUSB-R5 (Arduino Clone with RFM69HW 433Mhz Encrypted Radio) LowPowerLabs Moteino-R4 (Arduino Clone with RFM69HW 433Mhz Encrypted Radio) eTape resistive liquid level sensor from milonetech.com OpenEnergyMonitor (OEM) EmonCMS OEM EmonPi (Raspberry Pi w/radio for collecting sensor information via 433Mhz)

Basically I have designed an automatic pool fill system that monitors the level of our pool and then fills it automatically when needed, but based on some very specific criteria.

I know what you are thinking...why not just by a little float thing and have it fill that way...well we had one of those and it broke in such a way that we would have to tear up the existing system where it was mounted (in cement) in order to replace the part that had broke. Since we have a bunch of monitoring and automation within our home already, I decided to automate this process as well.

First some background:

Utilizing various software and hardware platforms we currently monitor every electric circuit in our main power panel, all of our solar production, all of our weather information (Davis Vantage Pro 2 weatherstation) and temperatures throughout our house, air conditioning and cooling ducts, attic and our pool water. For tracking all of this we utilize EmonCMS (from Openenergymonitor.org) and store all of the information and readings in a MySQL database. All of the weather data is stored in a MySQL database and converted with a php script to run our family weather website (http://zeus.rstechnical.com). The weather stuff is cool, but not really part of this current project.

The sensors we are using are from both Openenergymonitor as well as LowPowerLabs. We use the emonTH from OEM and the Moteinos (and associated hardware) from LowPowerLabs. We use the Raspberry Pi as our management and data collection nodes.

My current Pool level monitoring and filling project is broken into two parts: monitoring the level, and filling the pool.

The pool level monitoring part was pretty easy. We have a small cement basin with a 1" pipe connecting to our pool. This basin is about 1' deep and connects directly to the pool and the level of the water in this basin is representative of the level of the pool water. Since it only has a small 1" pipe connecting it to the pool, it is almost impervious to the kids splashing and creating havoc in the pool. This became the perfect place to install the eTape water level sensor.

The pool level monitor uses a product called eTape from milonetech.com. It is a resistive based liquid level sensor. (google milone etape and click on images). It basically looks like a ruler with three wires coming out of the top. You only need to use two of them to get a resistive reading. This eTape connects to a little Moteino (lowpowerlab.com) microcontroller (~$20) and two AA batteries. The Moteino is an Arduino clone. The Moteino sketch that I wrote gets the level of the pool and transmits it via 433Mhz to my EmonPi Raspberry Pi which in turn sends it to emoncms and stores the data in a mySql database once per minute. This Moteino is battery operated and at a once per minute transmission, the batteries should last about two or so years.

I chose the eTape solution instead of simple float or even the SST liquid sensor from sparkfun (as others have done) because I want to be able to see the level of my pool, not just get a notification if it is low. Plus from a programming standpoint, I can (and do) use low and high thresholds. With the eTape, I get a resistance measurement across the entire level of the water in my measurement area. When I see that I am low, I can fill until the resistance changes to the value that I want. This allows me to let the pool level go down several inches and then fill back to my full level as opposed to starting the fill process the instant the sensor comes out of the water. I can also track the level of the pool over time since the eTage provides resistive values based on the water level.

The second part utilizes another Raspberry Pi3 ($35), a microUPS/battery backup/power control unit called MightyHat (~$40) (lowpowerlab.com) which provides the Pi with another arduino microcontroller, a 4400mAh battery for power backup (about ~3 hours) and another 433Mhz radio for transmitting sensor data. In addition it includes an Nokia LCD screen that I can send information and status updates. I have three weatherproof buttons on the Pi, one (momentary) to boot/reboot and powerup the Pi, one (momentary) to handle manual filling of the pool if needed and a third (latching) to physically interrupt power to the valve that I use to control the filling process.

Please see part 2

HERE IS PART 2:

I have written the control software for the Moteinos using the Arduino IDE and the control software for the Pi in Python.

The basic premise of the system was if the pool falls below a certain level, the Pi will open a sprinkler valve to fill the pool. Since we are required to have vacuum breakers on all irrigation connections, I choose to add an additional sprinkler valve to my irrigation system. This valve is connected to a relay on the Pi and when the software tells the valve to open, the relay fires and operates a 24VAC sprinkler valve. This valve is connected to my pool plumbing on the output side and so includes a backflow valve to prevent pressure from the pool pump heading back to the irrigation system.

Because I am running this from my irrigation system, I wanted to make sure that the pool would not attempt to fill while my sprinklers were running. Within my python script, I check for this in one of two ways. First, I have a generic "blackout' period where you simply set the times your sprinklers are running and we won't fill the pool during that time. The second way is via an API call to my Rachio sprinkler system. This call tells me if the sprinklers are currently running or not. If the sprinklers are running, we will not attempt to fill the pool for any reason, automatically or manually as doing so will cause the sprinklers to fail due to low water pressure from too much draw on the irrigation system. If there is an attempt to fill the pool automatically or manually while the sprinklers are running, we flash some LEDs, we write to the LCD, send a pushbullet notification and make a log entry.

Second, I wanted to make sure that the pool would not attempt to fill if my pool pump were running as I do not want to try and fill against the pressure form my pool pump. I manage this by monitoring the power utilization on the circuit going to my pool panel. If I am using more than 30 watts, I know my pool pump is running as my monitoring and chemical autopilot system consume only 12 watts of power. Anything over that means my pump is running and we should not fill the pool. Again, if the system attempts an automatic or manual fill while the pump is running, we flash some LEDs, we write to the LCD, send a pushbullet notification and make a log entry. But we don't fill the pool.

If I want to prevent the system from running for any other reason, I have a toggle switch that physically opens the circuit between my relay and the sprinkler valve. This is done utilizing a DPDT switch that also lets me notify my script and take action when the switch is thrown. If we are not filling the pool, we inhibit any filling (both automatically and manually) and if we are filling, then it shuts off the relay and basically resets the system. Of course, with the physical connection interrupted these are pretty much just house cleaning activities. The script remembers the state it was in when the switch was thrown and goes back to that state immediately once it is put back. I wanted at least one hardwired interrupt to the process in case the software went bonkers or we wanted it bypassed for whatever reason. I could simply ssh into my Pi and shut down the script, but the rest of my family has no interest in learning linux, ssh or anything like it, so the switch was the way to go.

In order to prevent an overfill while in automatic mode, I have a timer built into the script that monitors the fill time and will force shutoff the valve if you go over whatever you set your max runtime to in the settings. For example, I know my pool will take about 1.5 hours to go from low to where I like it, but it would take about 6 hours to overfill, so I set my timeout to 180 minutes. It will be more full than normal, but not overfull.

Due to the nature of the manual fill button, this will run until you shut it off regardless of the pool level or pool fill timer!!!

I use pushbullet (free) for all of my notifications (which can be toggled on or off in the settings) and use Python's builtin logging for tracking what the system is doing.

The system has six status LEDs:

System OK - Green Sprinklers Running - Blue Pool Pump Running - Yellow System Error - Red Pool Filling (Auto or Manual) - Blue Fill Valve Disabled - Red

In addition the main power switch has an builtin green LED that lights when the Pi is powered. To reboot the Pi I simply press and hold the button for 2 seconds and the Pi will reboot. If I want to shut it down, I simply hold the button down for more than 5 seconds and the Pi will gracefully shutdown. This is all handled by the Arduino/MightyHat and scripts on the Pi.

The manual fill button also has a builtin green LED. It is normally off, but if you go into manual fill, then it will go solid green. If you attempt a manual fill while the sprinklers are running, the pool pump is running or the bypass switch has been thrown, it just blinks a bunch of times to let you know it cannot do a manual fill.

All of the error and status information is written to the log (info, error and debug) and written to the LCD screen as well. If you enable notifications, they will also be sent to you via pushbullet (which is free).

I have gone form the breadboard stage and I am just waiting on my nema3r enclosure (with fans) to arrive before I finish mounting everything.

My latest changes to the code include full watchdog support. I check the level of my pool once per minute and ping my watchdog once every 70 seconds (these are configurable). If after 70 seconds we do not have a watchdog ping, systemd restarts my script automatically. Since all state information is stored in a MySQL database, once the script restarts, the system will go back to doing whatever it was doing before it was restarted. The only exception to this is the manual fill. If you are manually filling and the watchdog fires, you would have to restart the manual fill process again.

My continuing goal is to add into the mix pH and ORP monitoring, a full web interface so my family can see all the information from our website and manually control the system without having to walk to the pool pump containment area and filter pressure readings so I know when I need to backflush the filter.

I have then entire project including all code, schematics and some pictures available on GitHub:

https://github.com/rjsears/Pool_Fill_Control

Version 2.7 has been released, includes Atlas Scientific pH and ORP sensors.

https://github.com/rjsears/Pool_Fill_Control

V2.9 uploaded to github yesterday. Made a lot of changes to DEBUG output to STDOUT if set, also integrated alerting.py and pooldb.py together and added a temperature compensation function to the pH probe reading.

V2.9 (2016-06-18) - Eliminated alerting.py file, added contents to pooldb.py file. - Added a lot of DEBUG printing to STDOUT if DEBUG == 1 is set. - Moved pool_level and pump_running_watts table defs to pooldb.py so that you do not have to modify table definitions in main script. - Added in temperature compensation function for pH readings if you have a pool water temp probe. Configuration is done in pooldb.py

https://github.com/rjsears/Pool_Fill_Control

One of the various screens |500x373

The breadboard mockup. |500x376

Here is the eTape and Moteino (Arduino clone) for measuring the water level. |326x500

The interface board front |500x371

The interface board back |500x375

pH probe calibration |500x376

Atlas Scientific USB interface for pH and ORP Probes (shows up as a serial device). |500x362

Here is the wiring diagram for the Pi: |500x310

Here is the wiring diagram for my IO Break Out Board |500x315

Very interesting! What is your experience so far with the eTape level sensor?

All other aspects have my interest too; however I would like to implement this project in a Arduino Uno or Mega. Do you have a specific reason to use a Pi over Arduino?

Hi Brice -

I chose the Pi on the frontend just because of all of the stuff that I wanted to do with it. It really is my control head and then most of my sensors are motenio (Arduino) based units.

The main python program that runs everything for my pool is almost 1,400 lines of python code now and there is no way I could get a microcontroller to do everything my python code is doing, at least not in a way that I could figure out.

So far the liquid tape has been amazing. It works great and I have had no issues with the output resistance wandering which I was a little concerned about initially.

I continue to add to the system, mostly updating how I am doing things in my python code as I learn more and better ways of making things happen. Sometimes I get a little carried away and break my code, then I have to go back and figure it out again!

Great, thank you very much for your answer!

I will keep this in mind when adapting my automatic pool filling system.

Did you connect the Ph and Redox probes yet? Me too I have a electrolysis type chlorine generator using salt pool water. I use a Zodiac (French, I have the holiday home in Southern France) Pro controller that adds acid automatically. But in time I think about replacing at least the Ph and redox probes by the ones you mention. I realise this will imply a major undertaking at the controller level, but we'll see. I have however not the extensive software knowledge and background you seem to have.

We'll keep in touch; great project! Erik

Thank you Erik -

I do have them hooked up, but I am not controlling my acid with them as of yet. I have an AutoPilot system that already automatically controls my acid pump and SWG so adding these probes to this project was just for monitoring and tracking purposes as opposed to control purposes, although you could very easily adapt it to manage acid and ORP using a few more relays.

This is all a learning experience for me. I am a pilot by trade not a programmer, but I love the technical aspects of this kind of stuff. I am sure there are better ways of doing things which is why I share my project on various boards and look for input and ideas from others such as yourself.

I am currently up to V3.1 continue to add different things to the project.

Kudos for your work! I will follow this. Have a nice weekend, Erik