Custom Code with SmartThings

One of the coolest aspects of the SmartThings platform is the ability to write your own custom code.  With so many different devices available, you can write “SmartApps” that interact in ways no has though of or that meet some special purpose just for you.

In the Spruce Scheduler you see the option to add a “contact delay”.  This is an example of interacting with other devices on the SmartThings network.  With a contact sensor selected, Spruce will pause the watering schedule when a door is opened and then resume after the door is closed and the set time has passed.  This is one example of ways to interact with devices.

Getting started

First things first: You will be writing code on the Samsung SmartThings platform and as such are agreeing to the Samsung SmartThings terms.  Plaid Systems and Spruce operate on the SmartThings platform but that is all.  Follow their rules, simple enough.

Getting started is easy, go to the SmartThings web developer page and login using your same account and password information.  You now have full access to the developer IDE.

So how do I code?  The best way to get started is reading through the SmartThings documentation and following the examples listed right there in the IDE.  SmartThings does a thorough job with this and  even offers workshops on getting started.  Visit the SmartThings Community page which hosts a large and diverse community.

Examples from Spruce!

This first example is a SmartApp that subscribes to a moisture sensor, when the sensor reads below a setpoint, turns a zone on for a set time or until the moisture reads above a setpoint then turns the zone off.  The basic principles included are:

  • subscribing to a sensor
  • turning a specific zone on Spruce on or off
  • setting a time and duration to run

The example is downloaded as a text file, then copy & pasted into a new Smartapp in the SmartThings web IDE.

Zone Moisture

spruce-smart-zone-v1-01-groovy – improved zone moisture by BAB!

Spruce Sensor Device Code with adjustable moisture offsetthanks to Larry

What’s next?

We will periodically add additional examples, or user submitted examples.  Let us know what interests you!

Was this article helpful?

Related Articles