Setting up a Raspberry Pi to work with OpenSprinkler (Old post)

NOTE: This is a very old post and is only kept here for historical reasons. More recently I have been working on a Python port of the OpenSprinkler software which was originally written in C for an Ardino based sprinkler controller.

The new software supports a simple plugin architecture for adding custom features. There is a plugin that allows the the software running on a Raspberry Pi to work with an inexpensive relay board such as the ones by SainSmart.

I purchased a Raspberry Pi (Pi for short) credit card size computer a couple of months ago. I’ve been experimenting with it and having way too much fun to think about blogging. It runs a version of Linux. For a long time I thought about learning Linux but never had a compelling reason until now.

After becoming somewhat familiar with Linux and trying out many of the Pi’s capabilities I thought the Pi might be useful for managing an automated irrigation system. The question was, how to interface the Pi to the irrigation system. Then through some googling I discovered OpenSprinkler.

OpenSprinkler is an Arduino based, open source, network connected irrigation controller with a web enabled user interface. One user (David B. Gustovson) wrote a couple of php scripts which can log the activity of OpenSprinkler — a very useful feature. However, the logging scripts need to be hosted on a separate computer that is running a web server and connected to the network. This is a perfect job for the Raspberry Pi. It’s small size, silent operation low power consumption, network interface, and low cost make it ideal for this purpose. In addition there are some files used in the OpenSprinkler web interface that need to to be loaded from a web server. The Pi can be that web server! This also allows OpenSprinkler’s web interface to work even if an internet connection is unavailable.

Following is a set of instructions based on the steps I used to get the Raspberry Pi and OpenSprinkler working together. Click the embedded links for detailed instructions.

  1. Download the latest version of the operating system (Raspbian) for the Pi as an SD card image and follow the instructions for flashing it onto an SD card. I used an 8mb card and kept the default username (Pi) and password (raspberry) in my setup.
  2. Download the zip file containing the files I used for making the Pi work with OpenSprinkler. It contains:
    • The *.png icon files used in the OpenSprinkler web interface with the addition of a “log” icon
    • JavaScript files for the web interface edited to point to the Pi’s static IP address ( and including a modified home.js file which has a “Logger” button in place of the weather button
    • David Gustovson’s Sprinkler.php logger script edited to use the static IP address of the Pi and to find the directories on the Pi where the text files it uses are located.  You should edit the line that starts with “date_default_timezone_set” (should be line 13) to reflect your local time zone
    • A python script I wrote (, because I couldn’t get David’s SprinklerWatcher.php script to start automatically and run in the background on the Pi. The script has the same functionality, runs as a “daemon” process in the background and starts automatically when the Pi is powered on. It polls OpenSprinkler and records irrigation events into a couple of text files used by David’s script
    • The two text files used by the logger scripts (SprinklerChanges.txt and SprinklerPrevious.txt)
    • A modified version of the OpenSprinkler firmware
    • You can also access the OpenSprinkler GitHub repository at:
  3. Plug the SD card you prepared in step 1 into the PI and connect the Pi to your network. The Pi is equipped with ports for analog and HDMI video output as well as USB ports to which a keyboard and mouse can be attached. For use with OpenSprinkler it is best to access the Pi via SSH. and run it headless (without a monitor, keyboard, or mouse), accessing it from another computer. You can find instructions for accomplishing this on the internet.
  4. In order for the Pi and OpenSprinkler to communicate reliably with each other you should set both the  Raspberry Pi and OpenSprinkler to static IP addresses. I set the Pi to and OpenSprinkler to These IP addresses appear in a number of files and if you decide to use different ones you will need to edit those files. They include the *.js files used in the OpenSprinkler web interface, the Sprinklers.php logger script, the python script I used in place of David’s SprinklerWatcher.php script and possibly the OpenSprinkler firmware.
  5. Once you have your Pi set up and are able to access it via SSH you need to install a web server and PHP. I also installed mySQL database software for future use. See This web site for instructions.
  6. Set permissions for the web server directories on the PI:
    sudo chgrp –R users /var/www/
    sudo chmod -R 755 /var/www/
  7. Install the logger script and associated files and/or the files used by the OpenSprinkler web interface.
  • If you are installing the logger script, create directories for the python deamon program (, the php script (Sprinklers.php) that displays the log as a web page, and the text files used by the logger script:
    1. In the Pi home directory create a sub-directory named python_scripts
      mkdir python_scripts
      then copy the python file into it.
    2. Edit the rc.local file on the Pi. This will cause the script to be launched automatically when the Pi is powered on.
        • sudo nano /etc/rc.local
        • add the following to the end of the file:
          python /home/pi/python_scripts/
        • control o (letter o, not zero) to save the file
        • control x to exit the editor
    3. Next make a new directory under /var/www/ named “scripts” containing a sub directory named “php”:
      sudo mkdir –p /var/www/scripts/php
      Then copy the Sprinklers.php fie into the php directory.
    4. Make a new directory for the irrigation log text files:
      sudo mkdir /var/www/irrlog
      Copy the files SprinklerChanges.txt and SprinklerPrevious.txt into it.
  • If you are installing the files for OpenSprinkler’s web interface you need to:
    1. Create a directory under /var/www/ named images with a sub directory named icons:
      sudo mkdir –p /var/www/images/icons
      Copy the .png icon files into the new icons directory.
    2. Make a new directory for the javascript files:
      sudo mkdir –p /var/www/scripts/scv1.8/java
      and copy the .js files that have been modified to point to the PI as host into it.
    3. Follow the instructions on the OpenSprinkler web site to flash the OpenSprinkler with the precompiled modified firmware. This is only necessary if you will be hosting the files for OpenSprinkler’s web interface on the Pi.

When the files are in place and the Pi and OpenSprinkler are connected to your network. Turn on OpenSprinkler and then power on the Pi.

When you access the OpenSprinkler Web interface, if you have it hosted on the Pi and have flashed OpenSprinkler with the modified firmware, you should see a logger button at the upper right of the home page. Clicking it will open a new window after a few seconds showing the log. If you only installed the files required for the logger you can access the log from assuming that you used the same IP address for the Pi as discussed above. On my test system it takes 5-6 seconds for the log page to appear.

This combination of Raspberry Pi and OpenSprinkler not only provides logging capability for OpenSprinkler but opens up a world of possibilities for advanced irrigation management. I have successfully  tested a python script which can automatically access a network of specialized weather stations here in California (CIMIS) and download Evapotranspiration (ET) estimates which can be used to calculate irrigation requirements. A good explanation of the calculation process can be found in this free publication. It is focused on California landscapes but the general principles and species evaluations should be useful almost anywhere. It is also possible to interface sensors such as temperature and humidity to the system which can provide data for use in calculating ET. Detailed information on using such data and calculating ET values can be found in FAO 56 from the United Nations Food and Agriculture Organization. The use of soil moisture probes to monitor proper irrigation is an important option especially when using drip irrigation.

The inclusion of any automated adjustments in irrigation scheduling makes the ability to log irrigation events imperative.  The setup described here is only the beginning.

If you have questions, corrections, or comments regarding this setup please post them on the OpenSprinkler forum.

Copyright © 2012. All rights reserved.


  1. I like this article but I’m curious if it could all be run within the pi entirely, and eliminate the combo of open sprinkler and a pi?
    This article is from 2012 so I wonder if it has been done already?

  2. I am very keen to use this with soil moisture and ET. I will use on Pi for weather data and another for OpenSprinkler. If anyone is using ET and soil moisture to turn on OpenSprinkler, I would be keen to learn more about what you have done.

  3. […] OpenSprinkler มาดัดแปลงให้ใช้ Raspberry Pi เป็นบอร์ดควบคุม โดย OpenSprinkler และ Raspberry Pi […]

  4. […] for Pi-specific instructions for getting your RasPi in the home automation gardening game, from Xperimentia, via the OpenSprinkler site […]

  5. […] Dan K. from California wrote an excellent blog post about how to set up a Raspberry Pi to work with OpenSprinkler. The link to the blog post can be found here: […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: