LowPowerLab Forum

Hardware support => Projects => Topic started by: G550_Pilot on May 06, 2016, 04:24:42 AM

Title: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 04:24:42 AM
Hey Everyone -

I set out to automate my family's pool's water level using a Moteino, a Pi3, eTape, EmonCMS, some MySQL/PHP scripts a sprinkler valve and pushbullet (for notifications).

This is my first project with a Moteino and it was a lot of fun. I learned a lot about the Moteino (thanks Tom and Felix) and actually put something together that works!

The moteino is connected to a eTape sensor. Every minute (eventually 10 minutes) I read the sensor to determine the water level in our pool. I record the resistance being returned from the eTape, the battery voltage, the RSSI and a water level bit I set in the sketch based on the resistance value as well. This information is transmitted to my EmonPi and from there to my self hosted emoncms. So long as the water is above a certain level, nothing happens.


If the water level gets below a certain point, I toggle the pool.level bit that I am sending out to emoncms from a 1 to a 0. I also throw on the LED.

On my Pi, I am running a PHP script that checks that bit every minute and if it is low, it turns on a sprinkler control valve and starts filling the pool. Eventually the Moteino will detect that the pool is at the correct level, set the pool.level bit back to a 1 and my PHP script will detect that and shut off the valve.

I am using pushbullet (free) for my notification system. It notified me when the pool is low and the refilling has started and it notifies me when the pool is back to normal and the refilling has stopped.

I will add some additional information to the notifications such as gallons used to refill the pool and the time that it took. I will also add some backup controls to make sure the sprinkler valve does not stay open for more than 90 minutes (my refill window between low and normal levels in my pool). I also need to build in some time management since I do not want to be refilling my pool while my sprinkler system is running as I will lose too much water pressure.

Anyway, I have attached the sketch as well as the PHP script in case this could be of any use to anyone! I am sure it can use some cleanup and maybe more debugging along the way!

Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: Felix on May 06, 2016, 08:32:59 AM
Sticky!
Very interesting and probably useful project, any photos you could share?
Do you use emoncms for this purpose only or this just plugs into it along other things you monitor?
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:02:10 PM
Thanks Felix -

This was my first ever 'DIY' project that required me to do any soldering work, so please don't laugh at the pictures. I had been buying sensors already constructed but I need the high power radio and I figured I would give it a try.

I use emoncms for a lot of different things. We monitor all of the house electrical on every single circuit, we monitor our solar, import and export of power as well as temperatures all over the house. So it was natural that I used emoncms as part of this project since I am graphing those values anyway. I have more that I want to do, but I needed the highpower radios, but so far I have been unable to get the HW to talk to my emonpi with your RFM69 library, having to use the JeeLib library instead, but I am still working on it. I am not a programmer, but I have a very analytical mind so going through the code is a long process, but one that is pretty enjoyable.

My next project for the moteino is to track water usage, but I am using reed pulse sensors and I have yet to get the watermote to recognize the pulses.  One I have that working, I will include gallons used to fill the pool with the other information that I am graphing for the pool (level, temp, eventually pH and ORP).

I am a pilot so I have large blocks of time where I work and large blocks where I do not, so these projects are healthy for my mind and good fun!

Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:02:36 PM
More pictures
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:03:13 PM
More Pictures
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:03:49 PM
emoncms
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:05:44 PM
emoncms
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 03:06:43 PM
emoncms
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: WhiteHare on May 06, 2016, 04:37:16 PM
Say, those graphs look very nice indeed.  Thanks for sharing!

How would you rate the difficulty of setting up the data capture and graphing using emoncms?  Easy?  Difficult?

I notice it's using MySQL.  So, does that mean it can keep years of detailed history without performance coming to a crawl?
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 08:26:53 PM
WhiteHare -

I think it was quite easy to get it set up. There is a little bit of a learning curve to understanding everything you can do in emoncms, it is very powerful and has an amazing feed processor. A feed is any data you are asking it to record.

Take a look at the attached screen shot and you can see what I mean. If you are interested in sensors and monitoring and such, I think emoncms is a fantastic way to go and they have a great support forum over at https://community.openenergymonitor.org.

In the attached screen shot, all of those inputs are watts from CTs on my electrical panel. Some I just log to a mysql database (Log to feed) like my Range and over and my kids rooms. Others (like Solar) are more complicated and I have to conver it from a positive to a negative, then log that value to the database, then convert to a kWh, then add it back to my main power feeds, then log that number to the database and convert that to a kWh and then finally track a daily number.

It seems like a lot, but pretty much anything you want to measure or monitor is already being done by someone, so there is a lot of help out there for it.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 06, 2016, 08:33:27 PM
I have updated my php script to include a check to see if someone is manually filling the pool as well as a blackout window to prevent my pool from filling while my sprinklers are running.

Script attached.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 10, 2016, 06:29:33 PM
I have updated my sketch to correct an error when debug mode is shut off.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 12, 2016, 06:37:18 PM
Here is another update to the sketch that reads the eTape. With a lot of help from Tom, Felix and others, I have managed to reduce the power requirements of the sketch quite a bit.

I still need to make some more changes to include redoing the battery voltage monitoring (this sketch reads against the output of the VR), create some intelligence to help determine which Moteino we are running on and deal with the flash automatically, and some other cleanup.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: Felix on May 13, 2016, 03:20:09 PM
Great, thanks for the continued updates and sharing.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 15, 2016, 08:44:24 PM
OK, MAJOR update. I have shifted from a php script that runs once per minute via cron, to a python script that runs all of the time. This has allowed me to add in a manual fill button using the GPIO.add_event_detect, clean up the code, add additional alerting options via (free) pushbullet and do a more error checking.

My pool sensor is eTape connected to a Moteino R4 running off 2 x AA Energizer Lithium batteries. The control node is a Pi3 with a MightyBoost/MoteinoUSB and a 4400mAh LiPo battery. I have a relay connected to GPIO17 that manages power to my 24VAC sprinkler valve. I have a momentary push button switch with integrated LED connected to GPIO2 (built in 1.8k resistor) on the switch side and GPIO11 (with 560Ohm resistor) on the LED side. I am using an interrupt via GPIO.add_event_detect to determine if the manual switch has been pressed. I have pretty good notifications set up, but they could be modified pretty easily or shutoff completely by setting one flag in the config file. 

In addition I will be adding a hardware circuit interruptor switch between the relay and the sprinkler valve (like a vacation, don't ever fill no mater what switch).


I have attached a zip file with the following files:

pool_fill_control.py - Main python script

pooldb.py - database information and scheduling information (how often to check, etc)
alerting.py - config values for setting up pushbullet

pool_fill_control.sh - /etc/init.d/pool_fill_control file for start/stop/status, etc (install file and run update-rc.d pool_fill_control defaults, followed by service pool_fill_control start) if you use some other system for start/stoping scripts, then this may not work for you.

And finally the sketch I use on my etape Moteino.

I run everything from /root/pool_control and I run it as root, you may want to change this and other configuration options.

If nothing else, I have enjoyed working on this project and maybe this will give someone else some ideas.

I will continue to work on it to include logging and additional refinements! This is a hobby, I am a pilot by trade and love doing this in my spare time so any suggestions/comments are most welcome.

I have ordered my outdoor enclosure and have all the other parts and pieces to make all of this work. I will get pictures of the physical install and pass them along!





Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: TomWS on May 15, 2016, 09:16:42 PM
What I want to know is when is the pool party and who's supplying the beer?   8)
In lieu of that, I wouldn't mind a ride on a G550!   ;D

Tom
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: ssmall on May 15, 2016, 09:32:24 PM
I get the copilot seat!  Very nice project congrats.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 16, 2016, 02:19:27 AM
Yea, the 550 is a nice ride for sure, but I would rather be flying the helicopter truth be told. Not much to do at 51,000' but drink coffee and watch the gauges!
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/PHP, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 17, 2016, 12:31:29 AM
OK, another big update to my pool_fill_control.py script.

V2.1
        # - Added logging
        # - Reworked notifications to remove requirement to write a file
        #   and see if the file was present. Used global variables instead.
 
        # - Reworked overfill tracking and notification

        # - Reworked manual fill to prevent manual fill while automated
        #   fill is in progress. Before, requesting a manual fill while a
        #   fill was in progress caused the relay to kick out and back in
        #   and notifications for manual fill to go out. Now, before we do
        #   a manual fill we check to see if an auto fill is in progress.
        #   If there is one in progress, we just blink the button LED a
        #   bunch of times and log the event.

        # - Cleaned up the database check to prevent checking the pool level
        #   while we are manually filling the pool.   
        # - Added support for Rachio smart sprinklers via their API to
        #   automatically detect if the sprinklers are running or not.

You will need to get yoru Bearer and Device IDs from your rachio account and put them in pooldb.py


Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/Py, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 29, 2016, 11:38:20 PM
Added some more changed to pool_fill_control.py:

V2.2 (2016-05-29)
         - Added checking to see if our pool pump is running. Since (in
           our case) we fill the pool through the same piping that we
           filter with, we do not want the pool trying to fill while our
           pump is running. We have a backflow valve installed to prevent
           pressure from the pump from pushing pool water into our sprinkler
           system (although it would have to get past a closed sprinkler
           valve). We just don't want to try and fill the pool against the
           pressure of the pool pump.
               
           We have a CT on our pool panel that measures our power
           power consumption in real time and we log that data to our emoncms
           database (same database we log our pool level) and we are just
           reading the power utilization (in watts) and setting a max
           wattage that would indicate that our pump is running.
       
           If the pump is running, automatic and manual filling is disabled
           and we log and INFO message in the logfile. 
         
         - Added some additional debug messages. Set logger.setLevel(logging.INFO)
           to logger.setLevel(logging.DEBUG) to see the additional messages in your
           logfile. 
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 30, 2016, 04:53:12 PM
OK, made another big change to my project that I completed (finally) today. I have stopped using the MightyBoost and replaced it with the MightyHat and integrated the lcd screen into my project to output information form my script onto the screen so you don't need to log into the Pi anymore to see what is going on with the system.

I also reworked some of the debug logging (added a lot more) and rearranged the pushbullet notifications.
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 30, 2016, 04:54:19 PM
More pics
Title: Re: Automatic Pool Fill Control (Moteino, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on May 30, 2016, 04:54:44 PM
More Pics
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: Felix on May 31, 2016, 08:15:29 AM
Nice work  ;D
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 01, 2016, 04:38:34 PM
Thanks. Adding even more changes now!
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 03, 2016, 09:52:57 PM
V2.4 is available as of today.

- Added 5 system status LEDs (Sprinklers Running, Pool Pump Running, System OK, System ERROR, Pool Filling)
- Updated Manual fill function to check for sprinklers running before allowing a manual fill
- Added external power button to MightyHat and update MightyHat.ino to have only green LED which is what my external power button has on it.

Added wiring schematic.

All files are now on github:

https://github.com/rjsears/Pool_Fill_Control

Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 04, 2016, 08:36:02 PM
V2.5 is available today:

https://github.com/rjsears/Pool_Fill_Control


Big change was adding a manual interrupt switch that physically opens circuit between relay and sprinkler valve. This is a DPDT switch that allows me to interact with the script when the switch is pushed. This is a 'last resort' switch in the event something happens and the sprinkler fill valve will not respond to the program. This resets the relay and sends notifications as well as logs the event.

Added another LED connected to the above switch to indicate that we have manually interrupted the circuit.

Centralized all pushbullet notifications.

Cleaned up a bug that would not reset our run time even after pool was full.



For version 2.6 I am working on integration with our smart water meter so that once the pool has been filled I will get a notification how many gallons of water were needed to fill the pool.

Looking for any suggestions or feedback!!

Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 06, 2016, 01:50:18 AM
Version 2.6 was put on GitHub today. Didn't integrate with the smart meter (yet) but I did a bunch of code rearrangements, optimization, a couple of small bug fixes and most important rewrote the code to support watchdog support.

Since I am checking the pool_level every 60 seconds, I set the watchdog timer to 70 seconds. If after 70 seconds we do not get a ping to the watchdog, systemd will restart the script.

https://github.com/rjsears/Pool_Fill_Control
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 14, 2016, 03:26:00 AM
I am now up to V2.8 on my code. I added in support for the Atlas Scientific pH and ORP probes along with the ability to log the information from the probes to one or more local or remote emoncms (openenergymonitor.org) servers. Since I use a different system (called an AutoPilot) to control my Acid and SWG, I do not do anything with this probe information other than log it.

More code and import optimizations and some other cleanup.

I will be adding a filter pressure sensor and water meter to the R5 I have running alongside the Pi.

 
https://github.com/rjsears/Pool_Fill_Control
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on June 19, 2016, 12:55:30 AM
V2.9 uploaded to github today. 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
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on October 08, 2016, 10:19:01 PM
Version 3.1 release today!

A lot of changes from the previous versions. Code enhancements and optimizations as I learn more and more about python. Couple of big changes in the version included a full check of my external temp and level sensors by the main program to make sure I have not lost communication with them for any reason and to let me know via pushbullet if my batteries are getting low in my sensors.

If I lose communication with my pool_level_sensor for more than x numbers of checks, I force the pool fill to stop.

Also changed the way I reported my pool level. I had programmed the moteino to send a 0 if the pool were low and a 1 when the pool level was back to normal. Now I send the actual resistance level to my program and I can change what I do within my script as opposed to having to reflash the moteino if I want to change the level values for some reason.


(https://raw.githubusercontent.com/rjsears/Pool_Fill_Control/master/pictures/PFC_internal.jpg)

Cheers

https://github.com/rjsears/Pool_Fill_Control

Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: Felix on February 13, 2017, 03:29:23 PM
Great progress, not sure how I did not see this update before  :-[
Title: Re: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)
Post by: G550_Pilot on February 13, 2017, 03:56:41 PM
Yeah, it has been a very fun project. I have run into a couple of little issues having to do with some of my buttons on the RPi, but I am working on getting those issues addressed.

I am currently working on V3.2 which includes a major restructuring of my python code to clean it up (v3.2 is now almost 2,000 lines long), break out a bunch of stuff into other modules, start working on the web interface and just do basic cleanup and some more sensor integration!

Once I get that to a point where I like it, I will update here again!