SmartThings Community

How to Get Started Creating Complex Rules in SmartThings (2017) (SmartThings Classic)



(This is a wiki post: feel free to edit it or add to it as needed. Also, I can’t take any screenshots since I can’t use the app at this time due to its incompatibility with voiceover, so feel free to add screenshots where they would be helpful.)

At one point, one of the biggest advantages of using the SmartThings platform was the wide variety of devices that it supported. However, by the end of 2017 several competing platforms had caught up in that regard.

Where SmartThings still holds a significant advantage over some of the other low-cost home automation solutions is in the ability to really build really complex rules in a fairly simple manner. You won’t have to be a programmer, but you may need the help of other community members to get the logic constructed just right.

So how can you take advantage of this ability? This thread is intended as a basic introduction to building complex rules in SmartThings and was created at the request of @Raeven, who was looking for guidance on getting started in this area. Again, this thread is not intended for programmers, who will probably want to instead go straight into the developer materials for the SmartThings platform. This thread is intended for people who are not programmers who want to use some of the existing tools to create complex rules. :sunglasses: If you add to the thread, please keep this audience in mind.

A Basic Rule: If A, then B

There are many low-cost, automation systems that can perform basic rules of the “if A, then B” format.

if I arrive home, turn on the porch lights

if I press this switch, turn on that outlet

if the closet door opens, turn on the closet light

if it is 15 minutes before sunset, turn on the Living room light

if there has been no motion in the bathroom for 15 minutes, turn off the Bathroom lights

Although there are some variations in the exact devices and options available, this basic “If A, then B” setup is available with everything from HomeKit to echo plus.

There is also a free service, IFTTT (“If This, Then That”) which will let you tie devices from many different companies together in this kind of basic rule. “If the thermostat drops below 68°, turn my hue lights blue.”

In SmartThings, you can do this basic structure with the official Smart Lighting feature, the official Smart Home Monitor feature, and the official Routines feature. You may need to check all three of these locations to find the exact options you’re looking for. For example, if you want to get an alert when the temperature on a specific sensor is too high, you have to use smart home manager, not a routine or the smart lights feature.

It also participates in the IFTTT service.

Level 2: If A and B, then C

The next most complicated type of rule is a compound rule. It lets you combine some additional conditions, usually from a very limited set of possibilities, with your original rule. In low-cost home automation systems, the most typical kind of compound rule lets you also check home/away or time of day.

If I arrive home AND the time is between sunset and sunrise, turn on the porch lights

If I press this switch AND it is before 11 PM, turn on that outlet

If the closet door opens AND it is before 9 pm, turn on the closet light ( to keep from waking the baby up :baby:t3:)

If it is 15 minutes before sunset AND I am home, turn on the Living room light

Many Low cost home automation systems can do this, but not all. At the time of this writing, for example, the Echo Plus could not do an AND condition. HomeKit can, but only for time of day and home/away.

Also, the free IFTTT service does not have compound rules.

Smartthings has compound rules for both time of day and home/away in the official smartlights feature and in the official routines. The official features also offer the option to use “Mode” which adds some additional compound rule capabilities.



Level 3: Stacked Conditionals: Or, While, Unless

The next level is where the rules start to get really complicated, and most of the low-cost home automation systems fall away. This is when you start combining conditions and also checking for the absence of a condition.

If I arrive home AND the time is between sunset and sunrise OR if the motion sensor on the front porch detects motion during the same time, turn on the porch lights UNLESS The date is between Thanksgiving and New Years (keeps the porch lights from spoiling the effect from the outdoor holiday lighting)

If I press this switch AND it is before 11 PM, turn on that outlet UNLESS I have guests, in which case ignore the time restriction

If the closet door opens AND it is before 9 pm OR the mode is “baby sleeping” turn on the closet light ( to keep from waking the baby up :baby:t3:)

If it is 15 minutes before sunset AND I am home, turn on the Living room light UNLESS I am watching a movie

If there has been no motion in the bathroom for 15 minutes AND the humidity levels have not been rising, turn off the bathroom lights (this keeps the lights on if someone is in the shower where the motion sensor might not detect them)

If the indoor temperature is above 78° AND The bedroom window is not open, start the bedroom air conditioner UNLESS I am not home

And a community favorite:

If there has been no motion in the living room AND I am home turn off the Living room lights UNLESS the lights were turned on with the wall switch (manual override of the automatic light turn off)

Stacked conditionals can get really complex. Maybe you want to combine several different devices, so that a rule only gets triggered if a door is open AND there is motion in the room AND you are not home. (so your dog moving around doesn’t trigger your burglar alarm siren)

The point is that most low-cost home automation systems, including HomeKit and Wink and Echo Plus, just can’t handle these kinds of rules. But SmartThings can, and much more complex ones as well. However, it can’t do these kinds of stacked conditional rules through the official features. You will have to write your own code, use a third-party app like Stringify, or learn to use the free community created rules engine, webCoRE.

If you do happen to have an iOS phone, there is one third-party app which let you create simple “if A while B then C” compound rules with a nice visual interface. It costs about $10 and is quite popular for people who just need one level up from the basic type of rules. For example, this is the simplest way to set up a rule “if the garage door is open and has stayed that way for 20 minutes while I am away then send me a notification.” You install it like any other app from the App Store. But again, it is only available for iOS phones.

There is a similar third-party app that works only with android phones, called sharptools:

To Infinity and Beyond: Webcore and other ways of creating stacked conditional rules

In the early days of SmartThings, if you wanted to set up a stacked conditional rule, you had to write your own code. People did share the code with others in the community, but still. It was a lot of work and hard to follow.

Eventually, one grandmaster coder in the community, Bruce R, created “Rule Machine,” a smartapp that let you create some stacked conditionals. It was immediately very popular with the more technical community members, but eventually the author moved on to other projects and the code was withdrawn.

Seeking to fill the gap made by its absence, @ady624 , with some help from other community members, designed and wrote a very sophisticated rules engine, CoRE (Community’s Own Rules Engine). This did everything rule machine had done and more, but was still restricted by the size limits of running within the smartthings mobile app.

So in 2017, he created a new improved version, webCoRE, which let you work in a regular web browser to create your rules (called “pistons” in both CoRE and webCoRE).

webCoRE is essentially a scripting language for SmartThings, and it does most of the heavy lifting as far as managing devices and variables. It lets you create extremely complex stacked conditionals, with everything from built-in holiday schedules to web hooks to internal counters. :christmas_tree::tada:And it has a very active support community, and even its own forum, so you will be able to get lots of help setting up any individual piston even if you have no programming background at all.

It can’t address any of the underlying SmartThings architecture issues, like cloud latency or reliability, but it definitely answers the question of “why would I want to use SmartThings instead of HomeKit or Echo Plus?”

The answer is simple: if you want to go above basic “if A then B” rules and start creating automations that include OR, UNLESS, and WHILE, most of the low-cost competition won’t be able to do it and SmartThings will. But you are going to need to either write your own code or use something like webcore to accomplish that.

A Note About Stringify

Sometimes referred to as “IFTTT on Steroids,” stringify is a third-party app which lets you create visual “flows” which are stacked conditional rules tying together devices from different systems. It’s quite popular with people who like a more visual approach to rules design and management.

The only problem is that it was recently bought by Comcast, and there are some concerns that Comcast may eventually bring it in house, add it to their own home automation system, and stop supporting the free version. They haven’t said they’re going to do that, but you never know.

There’s no reason not to use it if you like its format. But unlike webCoRE, which Is offered with an open source perpetual license, Stringify could stop working at anytime.

So if Stringify would be an essential piece of a new home automation system, you might want to research further just to make sure you have a Plan B.

Getting started creating your own rules for SmartThings

Personally, I’m a great believer in practical applications. So I usually recommend that people start by designing rules that they actually intend to use, rather than just trying to come up with the craziest most complicated rule they can imagine and then implementing that. But it’s your choice. :stuck_out_tongue_winking_eye:

It’s also your choice whether you want to just start with the official smart lighting feature and play around with rules in that until you hit something that you can’t accomplish and then move on to webcore or Stringify, or whether you want to jump right in with the more complex rules engines from the beginning and do even your simple rules with those.

The official smartlights feature does have one advantage over the others in that its rules can “run locally” even when the SmartThings cloud is not available provided The rule is only using devices that are using device type handlers that can also run without the cloud.

This aspect is why there are some people who continue to use both the official smartlights feature and webcore. They will use smartlights for everything they can, then shift to webcore if they need it to support more complex rules.

But there are other people who prefer to do everything in webcore, even though they know those rules will not run if the SmartThings cloud is not available, because they just find that a simpler approach. Choice is good.

Getting More Help

If you have any questions about setting up a specific rule, please do not add them to this thread.

Instead, if it is a question about a webCoRE piston, go straight to their forum and you will get the quickest and most expert help:

If it is a question about any of the official features or just how to set up a rule in general, start a new thread in the following section of the forum:

And if you want to write your own code and you need help with that, see the developer section of the forum and again you will get the quickest and most expert responses:

Have fun! :sunglasses:

SmartThings is a very powerful, versatile system even for non-programmers. You will have to do a little research to get started, but it definitely has rules capabilities far beyond many of the other low-cost home automation systems, so if you want those kinds of complex rules, it may be a very good match for you.

On the other hand, if you decide all you need are the most basic rules, then you may prefer to choose a system which is simpler, more intuitive, or less dependent on the cloud . Choice is good. :wink:

Even more ideas

And for more ideas and inspiration on what you can do with SmartThings, check out the quick browse lists in the community – created wiki, particularly the project reports section.

There is a “get started“ list there that includes topics like “the top 10 things to do with SmartThings“ and “what device should I get next?” as well as lists for everything from holiday projects to baby nurseries.

Some of those involve complex rules, some are done with very basic rules, but there’s a lot of ideas from the community that are worth checking out. :sunglasses::tada:

Light on when arriving home after sunset?
Smarthings And/OR?
Difference between IFTTT, Stringify, WebCore, Device Handlers and SmartApps
Where to start - Checking the status of two or more "things" before triggering an action
IFTTT I need more options
Light switch on and off based on sensor—but not every time?
Can routines call other routines?
Z-wave momentary switch using Alexa
Setting a preset that isn’t overridden by switch?
N00b: Automate via ST when Device is Paired to Alexa
Question about multiple trigger automation
Need ideas for multi-zone heat pump thermostats
Who wants to get paid Write Code?
Activate a siren on multiple conditions?
Arm "Away" vs "Stay" Based on Switch?
Notify Me When Door Has Been Left Open at Sunset?
Turn on device for a few minutes repeatedly throughout the day?
Do WebCore and SmartThings Connect Play Nice Together?
New to st. Building a house
Notifications after multiple motion sensors?
Disable Motion sensor in the bedroom when in night mode?
Is Smartthings for me?
Perform routine based on temperature in the Classic app?
Door sensors to shut down AC?
Struggling with my first automation
First Post - Using IFTTT with SmartThings lights such as CREE or Hue
If X, Then Y, if Z ? (Stacked conditionals)
'New' smartthings app and classic app: Advice for someone new?
Lights turn on based on multiple criteria (AND)
Schlage Smartlocks: setting up complex rules?
What's the best way to select ANY or ALL in official features like Smart Lights?
Using smartthings hub to trigger multiple devices from different companies at once?
Status update every 6 hours
Turn a GE Smart switch off after 10 minutes
Newbie: First automation of Keen HVAC vent. Misc questions
Routines vs. Modes, etc
New to Smartthings (clsanchez77) -- looking for suggestions or feedback
Old thread: please delete
Need another “this” in IFTTT
Looking for advice about how to turn a smart app on or off (keep a cat out of the front room)
Automate Lights with Lots of Conditions?
Smartapps and routines (overlapping)
Help with Philips Hue and Motion Sensors scenarios
Control crawlspace fan based on humidity?
Motion Sensor to turn light on? How does this all work?
Aqara contact sensor + Alexa routines
Control Hue bulbs with a dimmer switch with no load?
IFTTT lacks persistence: how do I stop the "that" later?
Ecolink Z Wave Plus Motion Sensor - Association Group Command Access
Schedule Event based on calendar entry?
Smart Things step by steps / explanation guides?
Smart Lighting feature request
Stacked conditional rules
Working with devices that do not show current state
Automating a Meat Curing Chamber
Why use SmartThings or any Hub for that matter? (Not a troll, real question)
Multipurpose Sensor status as enabler of routine or app
Routine to Arm Monitor based on lock AND presence?
Best Brand? Is it OK to mix and match?
Can anyone help? Looking for an “if this has not happened by x time each day, please alert me”
Trigger a light based on temperature?
( Cosmo) #2

Incredible writeup @JDRoberts. This will be highly beneficial for prospective and new members!

(Robin) #4

Another great write up from the master, JD!!

For those wanting to dip their toes into webCoRE, myself and the other ‘webCoRE minions’ are ready and willing to help as best we can!

(Andy - United Kingdom) #5

Is JD the last JeDi?

(Dana ) #6

Agreed…he’s a god among children. :slight_smile:

( I hate Mondays) #7

Wow. On behalf of all users, thank you for the detailed write up, covering a lot of bases and options. Thank you.


Well, if you hadn’t written WebCoRE, there wouldn’t have been so much to write about! So the bases are mostly on you. LOL :stuck_out_tongue_winking_eye: