(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. 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 )
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 )
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 all of these kinds of stacked conditional rules through the official features.
(Note that the new V3 Version of the SmartThings mobile app has an official rules creator which does offer more stacked conditional options than the classic app did, so that’s worth taking a look at also. You can run both versions of the mobile app if you want to, and some people do, because the classic app may support some devices not yet supported in the new app, but they do like the rules creator in the new V3 app better.)
If you can’t find the options you want in the official features, you will have to write your own code, use a third-party app like SharpTools, or learn to use the free community created rules engine, webCoRE.
If you do happen to have an android 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 Android phones at present.
( they also offer a dashboard product which works with any web browser.)
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. 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.
And in 2020, SmartThings introduced an official feature, “The Rules API,” which is similar to WebCore, although not as yet as fully developed or documented. But it is expected that in the future it will eventually provide full support for these kind of complex rules.
Neither WebCore nor the Rules API can address any of the underlying SmartThings architecture issues, like cloud latency or reliability, but they definitely answer 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: Now Discontinued
Sometimes referred to as “IFTTT on Steroids,” stringify was a third-party app which let you create visual “flows” which are stacked conditional rules tying together devices from different systems. It was quite popular with people who liked a more visual approach to rules design and management.
Unfortunately it was recently bought by Comcast, and in April 2019 it was announced that Comcast was bring adding it to their own home automation system, and would stop supporting the free version. So any references you see to it in the forum refer to the time when it was available to anyone, but no longer apply.
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.
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:
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.
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.