Posted by: senex 8 years, 10 months ago

(Comments)

When my sprinklers go off in the middle of the night after it was raining that day, I get annoyed. I wanted an intelligent home brew solution to this problem that was cheap and was mostly COTS and not requiring much electrical engineering know how. There are systems out there you can buy that do everything for you that cost hundreds, but thats no fun. I have a system that cost me $45 plus things I already had.

This system, pysprinklers, is written in python and targeted for Linux. With pysprinklers, you can configure when your sprinklers go off, for how long. Also, if it has rained enough in the past 24 hours it will skip watering the lawn that time to save water. Further, before watering, it will check the forecast to see if its likely to rain soon. If it is, then it will hold off a bit and try again in hopes to conserve water. Oh, and it tweets the whole thing along with rain activity. You can find its twitter account @jash_the_robot.







The Hardware



Linux Machine:



I already have a Linux machine that acts as a hobby server. This is built out of an old laptop which hosts many things. I use openSUSE. If you dont already have one (and who doesn't), this would be a great use of raspberrypi.



Rain Gauge:

I found the WS-9005TWC-IT on clearance for $5. The display unit is useless. To this day it has never connected with the rain gauge. But the tipping bucket rain gauge was exactly what I needed... after a little hacking.

Game Controller:

I had an old USB Microsoft sidewinder game pad laying around.

Window magnet sensor:

I had one laying around, its one of these.



X10 controller & appliance module:

You need some method of turning the sprinkler system on and off via a computer. You can control X10 from Linux, so I am using this. I got the controller & module as a gift so that made it a great candidate. The controller I have is a CM15A and the module is a AM466.



Automatic Sprinkler system:

In order for this solution to work, you need a sprinkler system where you can put it in a constant on state. While in the on state plugging it in turns the sprinklers on, unplugging it turns them off, plugging them in again turns them on and puts them in a new zone. Most houses with automatic sprinkler systems have exactly this.



Rain Gauge

A tipping bucket rain gauge basically teeter totters back and forth as it is raining. When 1 side fills up, it tips to the other side till the other side fills up. The method to read such a rain gauge is to detect when it "clicks". It will either be on the left (on position/close circuit) or it will be on the right position (off position/open circuit). A click is when we alternate between on and off. This particular rain gauge has a magnet on the bucket system. I first add a magnet sensor inside the rain gauge so that in one position it can read the magnet (making sure when the bucket is in the other direction it does not read the magnet). I then connect the wires for the magnet sensor to the game controller so that I can read the button as either being pressed or not pressed.











At this point the game controllers button state is the same as the rain gauge button state and you can use game controller software to read the rain gauge. In pysprinklers you can find rain_gauge_monitor.py that does exactly this. The clicks will be stored into a sqlite3 database for other applications to use. To use rain_gauge_monitor.py, just start the process and keep it running (Follow the included README).

Sprinkler Control

To control the sprinklers you first need to make sure you can do it via command line (in my case via X10). I found a project that can control my X10 module here. With that, I created a wrapper called usbheyu. Connect the X10 controller to your Linux box and the appliance module to your sprinkler system. Make sure that you can turn the sprinklers on & off manually via command line. With this in place your sprinklers should be controllable via sprinkler_manager.py (view README for more info).

Tweeting

If you would like to have everything tweeted, including the rain activity you need to install the python twitter module. This comes with a command line twitter tool. Run this so that it can update your desired twitter account.

With twitter setup, I run rain_tweeter.py every 5 minutes so it can poll for changes. When it detects raining started, it will post. When it detects its done raining, it will post again with the rain fall for the past 24 hours.

Also, when calling sprinkler_manager.py, use the --tweet option for it to tweet as well.

Scheduling/Configuration

So you have your rain gauge working, X10(or alternative) controlling your sprinkler system... How do you get it all to work?

First you need rain_gauge_monitor.py to always be running. I just have a script that keeps it running called keep_rain_gauge_monitor_alive.sh. After that, everything is just a cron job. Here is my crontab





#Tweet rain activity

*/5 * * * * /opt/pysprinklers/rain_tweeter.py >> /var/lib/house/rain_tweeter.log



#Keep rain gauge alive (start up if machine was rebooted)

*/5 * * * * /bin/sh /opt/pysprinklers/keep_rain_gauge_monitor_alive.sh



#Run the sprinklers

00 02 * * thu,sun /opt/pysprinklers/sprinkler_manager.py --tweet \

>> /var/lib/house/sprinkler_manager.log



#Make sure sprinklers werent left on

* * * * thu,sun /opt/pysprinklers/sprinkler_manager.py --rs-check --tweet \

>> /var/lib/house/sprinkler_manager.log



You will want to adjust when to run your sprinklers.

If you end up using this, let me know in the comments section and give me the twitter account for your bot. @jash_the_robot would like to follow other pysprinkler robots out there.

Grab the software at https://bitbucket.org/senex/pysprinklers, its opensource released under BSD 2.0

Post regarding version 2.0 available at http://senexcanis.com/blog/python-sprinkler-project-20-relesaed/

