How to Get Started Creating Complex Rules in SmartThings

(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.

Also, you don’t need a smartthings hub to do this: the rules engine is built into the platform architecture. So even if all you have is some Wi-Fi switches that work with smartthings you can still take advantage of its sophisticated rules.

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 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.

And Amazon has been increasing the complexity of the rules offered through its free Alexa Routines.

There is also a subscription 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.” (This used to be free to consumers, and was very popular then, but now charges a monthly fee if you have more than three rules.)

In SmartThings, you can do this basic structure with the official Smart Lighting feature, the official Smart Things 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.

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 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. HomeKit can, but only for time of day and home/away unless you use the more complex Shortcuts feature. Alexa routines can do this for some conditions, but it can’t turn on one light switch because another one is turned on.

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 automations. 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 Alexa routines, 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.)

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 Rules API.

To Infinity and Beyond: 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. Then for a while, there was another community written option, Webcore, but that doesn’t work on the 2023 architecture.

So 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. Which is important, because when smartthings discontinues its free groovy cloud, Webcore will stop working. But the routines you can build in the smartthings app and the rules API will still work with the new architecture.

Additionally, the third-party SharpTools, has added a lot of features to its rules engine. They have both a free tier and a more advanced “pro” level, which costs $30 per year at the time of this writing.

Neither SharpTools 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 bought by Comcast, and in April 2019 it was announced that Comcast was 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. :disappointed_relieved:

Stringify shutting down (April 2019)

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 routines feature and play around with rules in that until you hit something that you can’t accomplish and then move on to SharpTools or the Rules API, 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.

Getting More Help

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

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:

Unless your question is specific to the new rules API. That now has its own section in 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:

Sharptools also has its own community forum where you can ask questions about it.

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?
Where to start - Checking the status of two or more "things" before triggering an action
Difference between IFTTT, Stringify, WebCore, Device Handlers and SmartApps
IFTTT I need more options
SThings Automation/Scenes vs. Google Routines
Help with SmartApp
Routines vs. Modes, etc
New to SmartThings should I avoid Wifi devices over alternative Z Wave or Zigbee devices?
Condition Logic for Custom Automations
New to Smartthings (clsanchez77) -- looking for suggestions or feedback
Old thread: please delete
SmartThings vs Aurora AOne hub?
Picking a hub
Need another “this” in IFTTT
Routines / automations on Alexa alternate to ST
Automate Lights with Lots of Conditions?
Introduction: New kid on the block finds ST alternately enjoyable and frustrating
Smartapps and routines (overlapping)
Help with Philips Hue and Motion Sensors scenarios
Control crawlspace fan based on humidity?
SmartThings or Alexa? Which is good for what?
Garage Doors Again: check doors at a specific time each day?
What's the best way to select ANY or ALL in official features like Smart Lights?
Schlage Smartlocks: setting up complex rules?
Lights turn on based on multiple criteria (AND)
Thermostat Automation
'New' smartthings app and classic app: Advice for someone new?
Turn on the AC in the evening, but only if the door is closed?
First Post - Using IFTTT with SmartThings lights such as CREE or Hue
Struggling with my first automation
Door sensors to shut down AC?
Motion Sensor to turn light on? How does this all work?
Is Smartthings for me?
Disable Motion sensor in the bedroom when in night mode?
Notifications after multiple motion sensors?
New to st. Building a house
Do WebCore and SmartThings Connect Play Nice Together?
Turn on device for a few minutes repeatedly throughout the day?
How to setup a light to turn on when a door opens/closes the first time and then off when it opens / closes the next time
Notify Me When Door Has Been Left Open at Sunset?
Arm "Away" vs "Stay" Based on Switch?
Activate a siren on multiple conditions?
Who wants to get paid Write Code?
Need ideas for multi-zone heat pump thermostats
Door to backyard pool. Best way to have it alarmed? --- One Button to Set Off an Alarm? --
Question about multiple trigger automation
N00b: Automate via ST when Device is Paired to Alexa
Use light switch to turn on multiple devices?
Setting a preset that isn’t overridden by switch?
Temperature control & dog feeding alerts
Z-wave momentary switch using Alexa
Can routines call other routines?
Light switch on and off based on sensor—but not every time?
Trigger a light based on temperature?
Can anyone help? Looking for an “if this has not happened by x time each day, please alert me”
Best Brand? Is it OK to mix and match?
Routine to Arm Monitor based on lock AND presence?
Multipurpose Sensor status as enabler of routine or app
Why use SmartThings or any Hub for that matter? (Not a troll, real question)
Make two single switches act as a 3-way
Automating a Meat Curing Chamber
Does ANYONE like the new smart things app?
Working with devices that do not show current state
Stacked conditional rules
Smart Lighting feature request
Smart Things step by steps / explanation guides?
Schedule Event based on calendar entry?
Sunset to Sunrise Automation both say sunset to sunset (or sunrise) See screenshot
Ecolink Z Wave Plus Motion Sensor - Association Group Command Access
IFTTT lacks persistence: how do I stop the "that" later?
Control Hue bulbs with a dimmer switch with no load?
Suggestion: Have more Included SmartApps
Aqara contact sensor + Alexa routines
Thinking of Switching from zipabox: anyway to use wired sensors with a smartthings system?
Want to start a smart home, have a few questions about where to begin
Deeper integration with Ring Alarm using Alexa as bridge?
Turn lights off after so many minutes?
Considering ST to replace Insteon. What ST options are there for dimmers that don’t have a neutral?
Repeating On/Off every hour?
Water tank pump - IFTTT to turn off pump if running for more than x minutes
New user - not a happy user
Help - Automation Scenarios Poll
Alert when door opens after certain time = classic app
Help with Moving to SmartThings and Possible HomeKit
Original & Aqara Xiaomi Zigbee Sensors (contact, temp, motion, button, outlet, leak, etc)
Newbie just starting with SmartThings
Is programming ST Hub more "unstructured" than ISY?
What SmartThings compatible hub should I get?
Automation help with scene changes
Newby looking for some guidance (UK)
Problem with Automation using Nest Hello to switch on an outside light
Why did Samsung abandon us?
I want to create a nested condition on IFTTT or otherwise (2014)
Left garage door - notification
New user.. confused as f
SmartThings Beginner’s Guide (2020)
Suggestion turn on light at random times especially night time
Using Amazon Echo as a Hub?
Boat Alarm System
Smart light switch and motion sensor
Use motion/contact sensor on set days and times
Honeywell Dimmer switch dim level—how to set it to 15%?
Would like for my home alarm to arm & disarm with smart deadbolt. Any ideas?
Using SmartThings As An Alarm/ Security System (UK)
Confused about SmartThings Hub
I'm just gonna ask: help explain automations to someone new? (2019)
New from Iris: easiest way to create rules?
Complex Timed event with automation?
Perform routine based on temperature in the Classic app?
If X, Then Y, if Z ? (Stacked conditionals)
Looking for advice about how to turn a smart app on or off (keep a cat out of the front room)
Combining ANY and ALL conditions in an automation - possible?
Boat Alarm System
Trying to Intergrate a sensor open / close to send a URL command
New Smartthings Setup - Latest Device Handlers?
Using CoRE or SmartRules app
Multiple Actions?
How to run an automation within a scene?
Newbie with basic app questions
Using smartthings hub to trigger multiple devices from different companies at once?
Alerts / triggers based on mold risk
Status update every 6 hours
Turn a GE Smart switch off after 10 minutes
Button not listed under Contact Sensors
Newbie: First automation of Keen HVAC vent. Misc questions
Top Level Priorities Checklist: what to consider before you start selecting smart home devices (2019)
I thought this was supposed to be easy
Looking for use cases. What can SmartThings do for you?
Automation that can have WHILE and not just IF and THAN
My Migration from IRIS

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


Is JD the last JeDi?


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

1 Like

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:


Thanks for this intro and summary @JDRoberts :+1:

I learned several things that I didn’t know before :slightly_smiling_face:


Can you point me to the rules creator in Smartthings new app?

“Note that the new V3 Version of the SmartThings mobile app has an official rules creator which does offer more stacked conditional options”


You access it anytime you “add an automation.“ So just click on the + in the upper right of the home screen and then choose automation.

There is also a new “rules API“ which can do even more complex things, but it’s still in development. :sunglasses:


Thanks @JDRoberts!
I was confused with the wording Rules Creator and thought that Rules api was already implemented.

So within Smartthings,
Automation = Official Rules Creator

There are also features like
Smart Lighting
Webcore Rules Engine
Smartthings Home Monitor

All of them have ‘If A then B function’ and some have more complex ones. Are there plans to merge all these functionalities into 1 single smartapp?


1 Like

Webcore is unofficial, community-created, And the official equivalent is the new rules API. So it will remain standalone.

As for the others, there’s no telling what will be combined. They haven’t said anything official one way or the other. :sunglasses:


is there any way to do :

activate this plug, after X ( let’s say 3 ) detections from a motion sensor ?

thanks for your help

WebCoRE can do it. You can post on the webcore forum and there are users who can help you build the piston

1 Like

thanks a lot for your answer jkp, i’ll have a look to the webCoRE community then .

Thank you. I have learned a lot from this extremely helpful post.

1 Like

Just found this forum and now this Wiki… Exactly what I was needing! Cheers!


So will the new API engine do things that Webcore can? For example, I had to write a piston to allow a button remote to increase Sonos Volume, with automations I can only set it to specific value and not increment it on button press?

Similar, but not identical, and the new Rules API is still,in development. For further discussion of its details, please see:

FAQ: Getting Started with the new Rules API

1 Like

The ‘will’ is perhaps the key word there. At the moment the documented features are relatively sparse, though still incredibly useful. However, given that the Automations have migrated to rules, it seems reasonable to assume there are some undocumented features (not necessarily available to the punters). For example, button presses work and as they don’t return to a standby state you really need an equivalent of the webCoRE ‘gets’ trigger, using ‘is’ or ‘changes’ just isn’t the same thing (the latter isn’t documented either).

I can see the Rules API having a full range of loops and comparisons, but that is really the basic stuff. Where webCoRE comes into its own is in its use of variables and arrays, and arguably even more critically the Task Cancellation, Execution and Scheduling Policies. That is where it gains the power to handle real world situations that would otherwise need bespoke logic. So that is the stuff we really need to see.