Intel Edison + Koyo Sprinkler Controller

AKA: How to build a smart sprinkler controller in less than 100 lines of code

Sound impossible?  It isn’t.  Here’s how I did it but before we start, lets define what we mean by “smart”.  “Smart”, in a sprinkler context (yes, this will be highly subjective), to me means it waters my lawn and other things that need watering at just the right amounts at just the right time.

It must be green.  If it rains, it can’t water unnecessarily.  So it has to be able to understand the weather.  It also cannot water more than my lawn or other plant needs.  This means that it has to know what I’m watering and how much water it needs.  With those features in mind, lets begin.

First, the brains of the operation: The Intel Edison.  The Edison is a powerful and small unit with built in wifi and bluetooth.  That means it’s really easy for it to connect to both other devices and to the cloud.

The wifi feature will help us get weather data from the cloud and also evapotraspiration data (ET say whut?  More on this later).  The Edison also has USB, which we will need later on.

The Second piece of hardware we will use is the “Koyo”.  It’s a PLC.  My brother had an extra one that he was willing to donate.  I understand you can do the same thing with the Edison and a relay array, but if you have a PLC, why not use it, right?

The koyo uses UDP for control.  My brother wrote a python library to interface with the unit.  It’s pretty easy to use, the readme that comes with the library will help you find the koyo on the network and change its IP address.  The library also allows us to toggle the koyo’s relays.  The koyo python library requires a connection to the koyo.  If you can plug the koyo into your network via ethernet, awesome.  If not, you need to use something to bridge to the koyo over wifi.  The Edison has wifi, so we are good there.  But it doesn’t have ethernet.  This is where USB comes in.

I picked up a usb to ethernet adapter on digikey.  Using the Edison breakout board and a USB OTG to USB female I now have working ethernet -well almost.  Connman, the network manager, which comes installed on the Edison was a bit of trouble here.

Once we have a connection set up, we need some data from the Internet so we can make the system smart.  There are two sources we will use for data.  Weather Underground and Agrimet.  Whether Underground can tell us if it has rained and Agrimet will tell us how much to water.

Agrimet has a table that contains the evapotranspiration data for several crop types including “lawn”.  Evapotransperation (ET) is how much transpiration and evaporation of water has occurred during the day.  This number takes several variables into account including precipitation, solar irradiation, wind, and several other variables.  For more on ET and how it is calculated checkout the Wikipedia page.  Many local weather stations calculate ET for different crop types and Agrimet aggregates that data. Agrimet organizes the data per station so  we will need to find you nearest weather station to our location.  You can find your station on a map here.  Remember the station id. We will need it later.

Once you have the weather station id nearest your area, we can get an ET data table for that station.  The URL to get the table is this:

Replace {stationID} with your station and open the URL in a browser and you should see the data table.  To parse the data I used this script:

To use this class do the following:

“cropName” can be any crop that you see in the chart.  Since we are watering grass, I will use “LAWN” for my crop.  The next thing we want to do is see if it’s rained today.  Since our forecast was predicted using yesterdays numbers, if it rained today, it will not have factored in.  So we will just subtract the amount of precipitation if any from our forecast.  I use weather underground to get the current weather conditions.  Here’s my sprinkler.py that combines the Et with weather data and turns on/off my sprinkler zones.

 

The zones are defined in a json file:

I got the rate for each zone by putting a cup and running the sprinkler for 10 mins then dividing by 10 to give me how much water my system produces per minute.  Type is LAWN, but it could be any crop.  No I’m not using this variable in my code.

The last thing to do is set it up on a schedule.  To do that, check out my video.

Conclusion

I’m almost completely happy with this setup after a few weeks of operation.  I love being able to ssh into the sprinkler and turn it on and off -even from my android phone.

Leave a Reply

Your email address will not be published. Required fields are marked *