Blog | Mezzaninehttp://senexcanis.com/blog/feeds/atom/2012-05-14T21:40:02+00:00BlogPython Sprinkler project 2.0 relesaed2012-05-14T21:40:02+00:00senex/blog/author/senex/http://senexcanis.com/blog/python-sprinkler-project-20-relesaed/<p>Version 2.0 of the Python Sprinkler Project has been released.&nbsp; 2.0 makes the sprinlker system smarter and includes a bug fix.</p><p>Skip threshold was expanded from just a 24 hour view to a 24 hour and 48 hour view. This allows for skipping a session if it rained heavily 2 days prior if that days rain was very heavy.</p> <p>Code for detecting chance of rain was fixed, lookups should work now.</p> <p>Added watering duration adjustment to reduce water when it rains even if our threshold isn't met. Reduciton is proportional to the amount of rain received compaired to the 24 hour threshold. Example: if the threshold is .08 inches and it rains .04 inches in the last 24 hours, it will activate the sprinklers for 1/2 the time.</p><p>The original story can be found at <a _mce_href="/blog/python-sprinkler-project/" href="/blog/python-sprinkler-project/">http://senexcanis.com/blog/python-sprinkler-project/</a><br _mce_bogus="1"></p><p>Project page can be found at <a _mce_href="/open-source/pysprinklers/" href="/open-source/pysprinklers/">http://senexcanis.com/open-source/pysprinklers/</a><br _mce_bogus="1"></p>Python Sprinkler project2011-11-10T21:16:30+00:00senex/blog/author/senex/http://senexcanis.com/blog/python-sprinkler-project/<p>When my sprinklers go off in the middle of the night after it was raining that day, I get annoyed.&nbsp; 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.&nbsp; There are systems out there you can buy that do everything for you that cost hundreds, but thats no fun.&nbsp; I have a system that cost me $45 plus things I already had.</p><p>This system, pysprinklers, is written in python and targeted for Linux.&nbsp; With pysprinklers, you can configure when your sprinklers go off, for how long.&nbsp; Also, if it has rained enough in the past 24 hours it will skip watering the lawn that time to save water.&nbsp; Further, before watering, it will check the forecast to see if its likely to rain soon.&nbsp; If it is, then it will hold off a bit and try again in hopes to conserve water.&nbsp; Oh, and it tweets the whole thing along with rain activity.&nbsp; You can find its twitter account <a title="@jash_the_robot" _mce_href="http://twitter.com/#!/jash_the_robot" href="http://twitter.com/#%21/jash_the_robot">@jash_the_robot</a>.<br></p><p><br></p><h2>The Hardware<br></h2><p><strong>Linux Machine:</strong><br></p><p>I already have a Linux machine that acts as a hobby server.&nbsp; This is built out of an old laptop which hosts many things.&nbsp; I use <a _mce_href="http://www.opensuse.org" href="http://www.opensuse.org">openSUSE</a>.&nbsp; If you dont already have one (and who doesn't), this would be a great use of <a _mce_href="http://www.raspberrypi.org/" href="http://www.raspberrypi.org/">raspberrypi</a>.<br _mce_bogus="1"></p><p><strong>Rain Gauge:</strong></p><p>I found the<a _mce_href="http://www.lacrossetechnology.com/9005/index.php" href="http://www.lacrossetechnology.com/9005/index.php"> WS-9005TWC-IT</a> on clearance for $5.&nbsp; The display unit is useless.&nbsp; To this day it has never connected with the rain gauge.&nbsp; But the tipping bucket rain gauge was exactly what I needed... after a little hacking.</p><p><strong>Game Controller:</strong></p><p>I had an old USB Microsoft sidewinder game pad laying around.</p><p><strong>Window magnet sensor:</strong></p><p>I had one laying around, its one of <a _mce_href="http://www.homesecuritystore.com/p-202-943wg-wh-ademco-miniature-surface-contacts-white.aspx" href="http://www.homesecuritystore.com/p-202-943wg-wh-ademco-miniature-surface-contacts-white.aspx">these</a>.<br></p><p><strong>X10 controller &amp; appliance module:</strong></p><p>You need some method of turning the sprinkler system on and off via a computer.&nbsp; You can control X10 from Linux, so I am using this.&nbsp; I got the controller &amp; module as a gift so that made it a great candidate.&nbsp; The controller I have is a <a _mce_href="http://www.thehomeautomationstore.com/sw31a-cm15a.html" href="http://www.thehomeautomationstore.com/sw31a-cm15a.html">CM15A</a> and the module is a <a _mce_href="http://www.x10.com/automation/am466_s.html" href="http://www.x10.com/automation/am466_s.html">AM466</a>.<br></p><p><strong>Automatic Sprinkler system:</strong></p><p>In order for this solution to work, you need a sprinkler system where you can put it in a constant on state.&nbsp; 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.&nbsp; Most houses with automatic sprinkler systems have exactly this.<br></p><h2>Rain Gauge</h2><p>A tipping bucket rain gauge basically teeter totters back and forth as it is raining.&nbsp; When 1 side fills up, it tips to the other side till the other side fills up.&nbsp; The method to read such a rain gauge is to detect when it "clicks".&nbsp; It will either be on the left (on position/close circuit) or it will be on the right position (off position/open circuit).&nbsp; A click is when we alternate between on and off.&nbsp; This particular rain gauge has a magnet on the bucket system.&nbsp; 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).&nbsp; 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.<br></p><p><img title="Rain guage with added sensor" alt="Rain guage with added sensor" src="/site_media/uploads/rain_guage/rain_guage_hacked1.jpg" _mce_src="/site_media/uploads/rain_guage/rain_guage_hacked1.jpg" height="397" width="600"></p><p><br></p><p><img title="Rain guage with added sensor" alt="Rain guage with added sensor" src="/site_media/uploads/rain_guage/rain_guage_hacked2.jpg" _mce_src="/site_media/uploads/rain_guage/rain_guage_hacked2.jpg" height="640" width="400"><br></p><p>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.&nbsp; In pysprinklers you can find rain_gauge_monitor.py that does exactly this.&nbsp; The clicks will be stored into a sqlite3 database for other applications to use.&nbsp; To use rain_gauge_monitor.py, just start the process and keep it running (Follow the included README).</p><h2>Sprinkler Control</h2><p>To control the sprinklers you first need to make sure you can do it via command line (in my case via X10).&nbsp; I found a project that can control my X10 module <a _mce_href="http://eclipsehomeauto.com/cm15a_on_linux/cm15a.shtml" href="http://eclipsehomeauto.com/cm15a_on_linux/cm15a.shtml">here</a>.&nbsp; With that, I created a wrapper called usbheyu.&nbsp; Connect the X10 controller to your Linux box and the appliance module to your sprinkler system.&nbsp; Make sure that you can turn the sprinklers on &amp; off manually via command line.&nbsp; With this in place your sprinklers should be controllable via sprinkler_manager.py (view README for more info).</p><h2>Tweeting</h2><p>If you would like to have everything tweeted, including the rain activity you need to install the <a _mce_href="http://pypi.python.org/pypi/twitter" href="http://pypi.python.org/pypi/twitter">python twitter module</a>.&nbsp; This comes with a command line twitter tool.&nbsp; Run this so that it can update your desired twitter account.</p><p>With twitter setup, I run rain_tweeter.py every 5 minutes so it can poll for changes.&nbsp; When it detects raining started, it will post.&nbsp; When it detects its done raining, it will post again with the rain fall for the past 24 hours.</p><p>Also, when calling sprinkler_manager.py, use the --tweet option for it to tweet as well.</p><h2>Scheduling/Configuration</h2><p>So you have your rain gauge working, X10(or alternative) controlling your sprinkler system...&nbsp; How do you get it all to work?</p><p>First you need rain_gauge_monitor.py to always be running.&nbsp; I just have a script that keeps it running called keep_rain_gauge_monitor_alive.sh.&nbsp; After that, everything is just a cron job.&nbsp; Here is my crontab</p><p><br></p><pre>#Tweet rain activity<br>*/5 * * * * /opt/pysprinklers/rain_tweeter.py &gt;&gt; /var/lib/house/rain_tweeter.log<br><br>#Keep rain gauge alive (start up if machine was rebooted)<br>*/5 * * * * /bin/sh /opt/pysprinklers/keep_rain_gauge_monitor_alive.sh<br><br>#Run the sprinklers<br>00 02 * * thu,sun&nbsp; /opt/pysprinklers/sprinkler_manager.py --tweet \<br>&gt;&gt;&nbsp; /var/lib/house/sprinkler_manager.log<br><br>#Make sure sprinklers werent left on<br>* * * * thu,sun&nbsp; /opt/pysprinklers/sprinkler_manager.py --rs-check --tweet \<br>&gt;&gt; /var/lib/house/sprinkler_manager.log<br></pre><p>You will want to adjust when to run your sprinklers.</p><p>If you end up using this, let me know in the comments section and give me the twitter account for your bot.&nbsp; <a _mce_href="http://twitter.com/jash_the_robot" href="http://twitter.com/jash_the_robot">@jash_the_robot</a> would like to follow other pysprinkler robots out there.</p><p>Grab the software at <a _mce_href="https://bitbucket.org/senex/pysprinklers" href="https://bitbucket.org/senex/pysprinklers">https://bitbucket.org/senex/pysprinklers</a>, its opensource released under BSD 2.0</p><p>Post regarding version 2.0 available at <a _mce_href="http://senexcanis.com/blog/python-sprinkler-project-20-relesaed/" href="http://senexcanis.com/blog/python-sprinkler-project-20-relesaed/">http://senexcanis.com/blog/python-sprinkler-project-20-relesaed/</a><br _mce_bogus="1"></p>