Author Topic: Automatic Pool Fill (MightyHat, Pi3, MySql/Python, Sprinkler Valve, eTape)  (Read 6106 times)

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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!

« Last Edit: May 30, 2016, 07:05:53 PM by G550_Pilot »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5779
  • Country: us
    • LowPowerLab
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?
« Last Edit: May 11, 2016, 08:16:16 AM by Felix »

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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!


G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
More pictures

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
More Pictures

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
emoncms

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
emoncms

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
emoncms

WhiteHare

  • Hero Member
  • *****
  • Posts: 1297
  • Country: us
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?

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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.

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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.

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
I have updated my sketch to correct an error when debug mode is shut off.

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5779
  • Country: us
    • LowPowerLab
Great, thanks for the continued updates and sharing.

G550_Pilot

  • Full Member
  • ***
  • Posts: 143
  • Country: us
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!