Smart Sprinkler System

@mattn I would like to remove the existing ancient controller too, but the wife says no.
I do not have a choice :). Was told to get a box to hide the Arduino/relay wires.

Many thanks to @mattn and @d8adrvn. Instructions were perfect, and the whole thing works flawlessly.

Only thing is I initially wired the relay to the 9v supply, and I was seeing all sprinklers ON all the time.
It works now after I switched it to 5V, but hope I didn’t burn anything.

NIce job, looks great!

@mattn @d8adrvn I only have 5 zones, so I plan to repurpose the remaining relays for a ST controlled garage door switch. Any thoughts on how to change IrrigationControllerDeviceType.groovy and ArduinoSmartShieldIrrigationController.ino?

Arduino side, I am assuming I just need a new command to specifically trigger relay 6/7 or 8.
But on the ST device code, any way I can identify relays 1-5; 6; 7 and 8 as 4 separate “things”?
I am not sure the “Virtual switch capability” applies here (I just don’t understand the virtual switch concept)

@d8adrvn Is there a way to use one of the relays as a pump or master valve… I have a master valve that opens before the zone opens… I have extra relay spots. Not sure how I would do this so the master valve opens the same as the zones open


That is an interesting question. My understanding is that there is already a SmartApp for a garage door opener that uses a momentary switch to trigger the garage door and a SmartThings Multi to detect if the door is open or closed. Our Arduino sketch would require changes to allow a relay time of a few seconds, which would be needed to simulate a garage door button push. The most surgical change would be to change the zone time preferences to seconds (vs. minutes) and remove the *60 from the calculation on line 76. Its not very intuitive for setting your sprinkler system. I think It would require multiple code changes to allow decimal input for minutes, i.e. 0.1 min.) You would then implement the virtual switches from @badgermanus. Then select the virtual switch and multi using the Garage Door Smart App. The Garage Door smart app may also need some changes so that you can see the virtual switches as a choice in the input.

With the above said, I am not sure you gain anything. By the time you buy a couple Multi’s (one for each door), you have spent more than if you just build a dedicated garage door opener. There are a couple arduino door openers on github, including one that I built. See
My implementation uses wired sensors to detect if door is open or closed. This has two advantages over the using a Multi (wired contacts are cheap and they do not use batteries which can be an issue in colder climates). Also I have added a lock capability to make it easy to program your doors to close (lock) when you go to bed or leave the home.

Another alternative is to pull some of the code from my garage door opener and merge with the sprinkler to 1) implement a brief relay action and 2) add the wired sensors. This would be a bigger project.

@kmugh I think this is possible without any changes to the Arduino or Device Type, although, there may be some strange side effects. Here is how you could hack a solution together. :smile:

As @d8adrvn mentioned, you would setup a virtual switch following @badgermanus instructions (seen here). This is what I did, following those instructions:

Create the switch device type:

preferences {
    input("num", "number", title: "Switch number", description: "The switch (relay) number to connect to (1 to 8)", required: true)

metadata {
    definition (name: "Virtual Switch", author: "you", namespace: "smart things") {
        capability "Switch"
        capability "Momentary"
// simulator metadata
simulator {
    status "on":  "command: 2003, payload: FF"
    status "off": "command: 2003, payload: 00"

    // reply messages
    reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
    reply "200100,delay 100,2502": "command: 2503, payload: 00"

// tile definitions
tiles {
    standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
        state "on", label: '${name}', action: "", icon: "st.switches.switch.on", backgroundColor: "#79b821"
        state "off", label: '${name}', action: "switch.on", icon: "", backgroundColor: "#ffffff"

    standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
        state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"

    main "switch"
// handle commands
def on() {
	log.debug "On"
    sendEvent (name: "switch", value: "on")

def off() {
	log.debug "Off"
    sendEvent (name: "switch", value: "off")

Use the IDE to create the device and select this device type.

Create the parent app that ties the v. switch to the Irrigation Controller and makes the switch behave as a momentary (you need to space out the on and off or the Arduino device will lose messages)

    name: "Virtual Garage Door Switch Parent App",
    namespace: "smartthings",
    author: "you",
    description: "Virtual Garage Door Relay Parent App",
    category: "My Apps",
    iconUrl: "",
    iconX2Url: "")
preferences {
	section("Connect this virtual switch to the Arduino's relays") {
		input "switch1", title: "Switch for relay", "capability.switch"
    section("Which Arduino relay board to control?") {
		input "arduino", "capability.switch"
        input "channel", "string", title: "Channel to switch (1 to 8)"

def installed() {
	log.debug "Installed with settings: ${settings}"

def updated() {
	log.debug "Updated with settings: ${settings}"

def subscribe() {
    subscribe(switch1, "switch.on", on)
    subscribe(switch1, "", off)

def on(evt) {
    log.debug "on($ $evt.value: $evt.deviceId)"
    runIn(10, "switchOff")

def off(evt) {
    log.debug "off"

def switchOff() {

You should be able to use the new virtual switch in a Garage Door app. I’ve tried this in the IDE. It seems to work. Now, you will see your irrigation device type tile turn on when you open your garage door. This is not ideal, but you could save a little money.

Got it installed and it works great for one zone… Not sure if you can turn 2 relays on using this system or not… Since I have the master valve guess I won’t be able to use it without some major code changes…

Out of the box, you can only have one relay on at a time. Reminds me of a limitation that I forgot to mention to @kmugh. The solution given about will NOT work when your sprinklers are running. :smiley: this may be a feature to add. Allow configuration of relays to participate in the irrigation system that run mutually exclusive. Others are free to be turned on independently.

@mattn @d8adrvn Cannot thank you guys enough, you both rock. Will use your suggestions and report back soon.

I’ve been waiting for something like this - great work! I’m using ST on an Android OS phone. At some point, will your code work for ST on Android?


@jbeletti It works well both on Android/iOS … the code is not platform dependent.

Cool. I look forward to building and trying this out later this summer.

Hi @docwisdom,

Actually, the system is already compatible with input buttons! You can pair the system with the Aeon MiniMote which allows you to individually control all 8 zones! The MiniMote has 4 buttons but each button can sense when its either “pressed” or “held”, giving you in effect the ability to control 8 switches. To use with this project, just virtualize the 8 relays and pair with the MiniMote. I tried this today and it took me just a few mins to hook up, after spending about 10 mins virtualizing my switches.

And here is the cool part: no need to run back and forth to the garage to activate the next zone. Just walk and click. This should easily work for the use case of when a repair person comes to work on the system. Just hand them the MiniMote.

I added some instructions to both virtualize the switches and pair the MiniMote to the README file on github under our MASTER branch.

Here is an excerpt:

Take Your Controller to the Next Level:

We modified our Device Type command set to be compatible with the Virtual Switch capability by Jonathan (jwsf on github or badgermanus on SmartThings). This allows you to virtualize each of the 8 zones giving enhanced ecosystem capabilities. Virtualizing gives each zone its own “switch” capability that can be recognized within SmartThings ecosystem. Then you can start linking irrigatoin zones to all the SmartApps that link switches to other devices.

For example, you can use the “Turn on when there is motion” SmartApp to connect an irrigation zone to a motion detector and trigger the sprinkler every time deer or intruder enters that zone!

As another example, you can use the Aeon Labs MiniMote to wirelessly turn on and then off individual zones. This is great if you do not have your iPhone or if you have a repair person working on your system. The repair person just needs the MiniMote to switch the zones. No running back and forth to the garage to advance the system!!!

Here is how to virtualize your switches:

  1. Log into
  2. Go to “My Device Types”
  3. Create a new SmartDevice, filling out the required info to create the device
  4. Paste in the VirtualSwitch.groovy code from jwsf.
  5. Save and Publish (for me)
  6. Go to My SmartApps and create a new SmartApp
  7. Paste in the modified code for the VirtualSwitchParent.groovy. I have modified to recoginize our Irrigation Controller. Be sure to use the modified code.
  8. Save and Publish (for me)
  9. Go to My Devices and create a new Device.
  10. Give it a ‘name’ and a ‘label’ such as “Virtual Irrigation Zone #1
  11. Under ‘type’, select “virtual switch”, which is the device type you created in #4 above
  12. For ‘version’, select “published”
  13. Now repeat this 7 more times for each of your zones!

The above is a bit tedious. As soon as SmartThings supports child devices, I imagine we will update our code and can do away with the need to create virtual switches.

Now for the cool part. To control your system with the Aeon MiniMote:

  1. Add the MiniMote to the sytem using Aeon’s instructions "Becoming a Secondary/Inclusion Controller to Another Z-Wave Controller or Gateway in an Existing Z-Wave Network
  2. When it asks you to configure ‘button 1’: add Virtual Irrigation Zone 1 as the switch under ‘Pushed’ and Virtual Irrigation Zone 2 as the switch under ‘Held’
  3. Repeat for buttons 2,3,4 using zones 3-8

Now when you ‘push’ or ‘hold’ a MiniMote button, the corresponding zone will activate. If you push again, it will turn off. If you do not turn off the sytem, it will run for as long as the zone ran, the last time it was activated from the device type or the smart app. Tip: you can tell push and hold apart. When you push, a solid blue led comes on. When you have ‘held’ the button, the blue led starts flashing.

@mattn is also looking into adding a button directly to the controller. This will be cheaper than buying a MiniMote (but everyone should have at least one) and also allow walk up control at the device.


Hi @dbmet,

So you need to control a pump? No problem, we have added two ways to control a pump or master valve. In both cases, the relay controlling the pump or master valve will be activated when any of the zones are active. Also, it will stay activated while the system switches from one zone to the next. And it automatically shuts off after all the zones have finished.

In the first scenario, you can now repurpose relay 8 to control the pump. Simply connect the Pump Start Relay load wire to Relay 8 on your 8-relay board and hook the Pump Start Relay ground wire to your ground wire bundle with the 24V transformer. The SmartDevice tiles now include a tile to activate the use of pump and inactivate relay 8.

In the second scenario, you can also purchase an additional single relay and add to your Arduino. The additional relay is then used to connect to your Pump Start Relay. A small code change activates the additional relay!

I have uploaded the updated Arduino sketch and Device Type groovy code to our Master branch on github. Our Master Branch is where we keep works in progress so there is a chance its a bit buggy or will change. We have a few other enhancements in the works and will create a new release when they are all done. I also updated the README file on the master branch to include some help in setting up the pump connections.

We hope either of these works for your use case. Please provide feedback on how it works!

This is fantastic. How hard would this be to install for someone that has never used an Arduino?

@Jsalicru if you are somewhat tech savy and handy, this really isn’t that difficult. The readme @d8adrvn provides is extraordinary and walks you through the entire process. Give it a shot! I couldn’t be happier.

@Jsalicru Could not agree more with @ziemba_jason
That readme is very detailed, walks you through the entire process.

I am new to this, but where do I “paste the code” in when I am on the new device type screen and where exactly do find the code ( I down loaded the “smart sprinkler master” folder, is it present there and if so how do I access it?). Also do any of the other fields need to be filled out?

1 Like

Hi @chrisharrigan,

To set up the device type, go to Go to ‘My Device Types’ and click on upper right button to create a ‘New SmartDevice’. On the next page, just assign the device a name such as “Irrigation Controller”. Don’t worry about anything else. Click Create New Device.

You should then see the following screen:

You need to replace all the lines of code that you see in the box (lines 1-33). Select all the code on the on lines 1-33 and delete them. Now paste in the code from teh Irrigation Controller.groovy app that you down load from github. Click Save and then Click Publish (for me).

You should really go back to github and download the code from our Release. On the github site you should see a link that says release. Click it and download the release code. Its in a zip file so it needs to be unpacked. Don’t know what machine you have but on a Mac, its automatic.

Good luck

Thanks, that answered my questions! I appreciate your efforts. I think this is an awesome project and am looking forward to getting it up and running!