[OBSOLETE] Smart Sprinkler System

A project by Stan Dotson (stan@dotson.info) and Matthew Nichols (matt@nichols.name)

Would you like to have a smarter lawn? We just updated our SmartThings Project to build a Smarter Irrigation Controller. The project originally posted to the old SmartThings Build Forum. Since then, we have made some significant progress and it is time to share our progress with the SmartThings community. The entire project can be downloaded in our latest release.

###Some of the highlights for our project are:

  • Simple toconstruct using an Arduino, a ThingShield and an 8-channel relay. We have even provided step by step instructions.
  • Controls up to 8, 16 or up to 24 irrigation zones with options to activate a Master Pump and Master Relay
  • Includes iPhone controls to manually start and stop the system
  • An Irrigation Scheduler app allows for automatic control of the system
  • A Rain Delay feature skips watering when the your local weather history and forecast indicate rainfall above a threshold. No need for moisture sensors.
  • An Accessory App provides additional flexibility to manage your automated irrigation schedule around yard projects, after application of weed control, during winter season, etcā€¦
  • Each of the zones can be virtualized with their own ā€œswitchā€ capability using modified code from @badgermanus This allows an irrigation zone to be integrated with another SmartThing. For example connect a sprinkler zone with a motion detector to chase away deer or other intruders from your yard. Or let your repair person test your sprinkler using the Aeon MiniMote

###Irrigation Controller App
We created an Irrigation Controller app (device-type) to manually control our system from an iOS device. Each zone has its own control tile. The tiles are used to turn on a zone, queue up a zone to run next, stop the currently running zone or remove a zone from the queue. The main tile turns on/off the entire system at once. The main tile also shows when the system is on Rain Delay. Below is a pic of the Irrigation Controller App. When a zone is off, the tile is white. The tile turns blue when the zone is on and is gold when the zone is in the queue. You can enter your manual run times using the Preferences tile.

###Irrigation Scheduler App
The Irrigation Scheduler App allows the system to run automatically. You can set up as many instances of the Irrigation Scheduler app as needed to cover every irrigation scenario. For example, set up one instance for to water the lawn and another instance to turn on a drip system.

This flexible app allows you to select days of the week and an interval to start your system. The days of the week option is handy if you are under watering restrictions or if you want to skip watering on the day you mow the lawn. The app also allows you to schedule up to three waterings per day. Multiple starts per day is useful after re-seeding you lawn when its important to keep the soil moist.

The Irrigation Scheduler is also smart! The app uses a user supplied zip code to look up the local weather history and forecast. A virtual rain gauge measures the rain from yesterday, today and adds in todayā€™s forecasted rainfall. The app will push a message and skip watering if the virtual rain gauge exceeds a threshold. The threshold is set in the preferences. Here are a few pics of the Irrigation Scheduler app:

###Summary
All of the code for the project and step by step instructions can be found on github. Matt and I have been using this project to irrigate our yards this summer. Several others, including @billwitt27 and @ziemba_jason have also successfully installed the project. Its cool having a connected sprinkler system that can be controlled by an iPhone. And the smart Rain Gauge is conserving water while keeping our lawns/gardens healthy.

17 Likes

It would be really sweet if there were input buttons for local control like is proposed on the Eden.

@d8adrvn Stan and Matt, thanks very much for sharing this, and for the detailed walkthrough. I just purchased the individual components from Amazon/ST last week after seeing your GitHub page. Will be bothering you if I encounter any issues.

Separately, I second @docwisdomā€™s suggestion - canā€™t we wire both the existing (old) controller in parallel with the Sain relay? Any potential issues with this?

This is great! I encourage you (if you already havenā€™t) to publish and pertinent device types and SmartApps for this project. Very cool.

You guys need a paypal donation link at the bottom of the git page. This is a lot of work and done very well!

1 Like

Just ordered the stuff to assemble this as well. Should be fun!!

@kmugh, I had the same question about parallel wiring with old controller when I was putting my system together. I think the answer to the question is yes, it is possible. However, the complexity of that task really depends on your controller and how accessible the power supply and relays are. I opted to just remove my old controller altogether for simplicity and space. For me, that was the right decision. I havenā€™t looked back. For what itā€™s worthā€¦ :smile:

@d8adrvn Any idea why I get this error when trying Load the sketch into Arduino software?

ArduinoSmartShieldIrrigationController:89: error: ā€˜SmartThingsCallout_tā€™ does not name a type
ArduinoSmartShieldIrrigationController:90: error: ā€˜SmartThingsā€™ does not name a type
ArduinoSmartShieldIrrigationController:95: error: ā€˜Timerā€™ does not name a type
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void setup()ā€™:
ArduinoSmartShieldIrrigationController:118: error: ā€˜smartthingā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController:121: error: ā€˜tā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void loop()ā€™:
ArduinoSmartShieldIrrigationController:141: error: ā€˜tā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController:149: error: ā€˜smartthingā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void toggleOn()ā€™:
ArduinoSmartShieldIrrigationController:229: error: ā€˜smartthingā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController:231: error: ā€˜tā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void toggleOff()ā€™:
ArduinoSmartShieldIrrigationController:237: error: ā€˜smartthingā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void allOff()ā€™:
ArduinoSmartShieldIrrigationController:252: error: ā€˜smartthingā€™ was not declared in this scope
ArduinoSmartShieldIrrigationController.ino: In function ā€˜void sendUpdate(String)ā€™:
ArduinoSmartShieldIrrigationController:277: error: ā€˜smartthingā€™ was not declared in this scope

Looks like you still need to properly install the libraries. Use the links to download them. Once you have the zip files downloaded, you can import them within the Arduino IDE. Go to the Sketch:Import Library;Add Library drop down menu. Once you have added the libraries, they will show up under Sketch:Add Library:Contributed as ā€œTimerā€ and ā€œSmartThingsā€.

@d8adrvn I donā€™t see a link for the librariesā€¦ Could be Iā€™m missing itā€¦ Downloaded the zip from Github and its not in there?

Hi, I just updated the release and the read me files to include the timer library instructions and links. FYIā€¦ the links were also in the header of the Arduino sketch. As an additional watch out, the timer library downloads as a zip file that needs to be renamed. Change the name of the file (folder that contains the code) to Timer before uploading.

Awesome That workedā€¦ Opened the sketch again and DUH the links were right thereā€¦ Haha sorry about thatā€¦

Now to wait for the smart things shield to come in tomorrowā€¦

@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

@kmugh,

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 https://github.com/d8adrvn/twoCarGarageDoorOpener
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: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
        state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
    }

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

    main "switch"
    details(["switch","refresh"])
}
}
// 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)

definition(
    name: "Virtual Garage Door Switch Parent App",
    namespace: "smartthings",
    author: "you",
    description: "Virtual Garage Door Relay Parent App",
    category: "My Apps",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
    
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}"
	subscribe()
}

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

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

def on(evt) {
    log.debug "on($evt.name: $evt.value: $evt.deviceId)"
    arduino."RelayOn${channel}For"(1)
    runIn(10, "switchOff")
}

def off(evt) {
    log.debug "off"
    arduino."RelayOff${channel}"()
}

def switchOff() {
	switch1.off()
}

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.