Precondition in Rules API

The SmartThings app got updated with “precondition” in App automation.
Still, there’s no documentation of “if” statement in Rules API to use “precondition”.
SmartThings API (

Is there any way to use “if” statement with “precondition” in Rules API?

I was thinking of migrating my automation from WebCoRE to Rules API, but I was stuck with condition/trigger problem. Until now, all of “if” statement in Rules API were trigger.
But now, it seems that precondition is implemented, so I hope to use this in Rules API.

That is frustrating me too. Obviously you can do a condition with the subscription disabled but that doesn’t seem to be quite the same thing as Rules only log an activation when preconditions are met.


As Automations can do ‘if motion is inactive for ten minutes’ there must be a remains/stays capability. It is not the same as a sleep.

What about button presses? Buttons don’t change attributes so you need the webCoRE ‘gets’ type functionality if there is more than one condition. You can’t even use ‘changes’ and that isn’t documented anyway.

How do you execute Scenes or send notifications?

Having had webCoRE and STHM deleted in bizarre circumstances last night, I want Rules more than ever. Automations are not a safe option.

1 Like

I didn’t know that there’s “trigger” field in Rules API.

This could be my option for condition without trigger.

Thank you.

Hi, @iquix! Can you give an example of one Rule you’d like to create using preconditions? I mean the flow you want it to follow

Something like this

if (button gets pushed) {
   if (switch1 is on) {
       action 1
   else {
       action 2

switch1 should be set to ‘trigger: “Never”’, because I don’t want this code to be executed when switch1 gets changed.

You can just use “equals” for buttons getting pushed.
I made a Rule like below, and it works as expected when I press button1 or button2

  - if:
              - @button1
              - @button2
            component: main
            capability: button
            attribute: button
          string: pushed
        aggregation: Any
         - do something

I was aware you’d be able to do that. However what if your rule runs when the button hasn’t just been pushed, for example you execute it manually? Or what if you want button1 and button2 to do different things? Or you also run the Rule when a contact opens? There isn’t a Ready/Standby so a single value button is always set to pushed.

You’re right, the condition for the Switch should have “Never” in the trigger property. Otherwise, the Rule would be executed even if the button wasn’t pressed.
For others to take reference, here are two samples of a similar Use Case:

  • Scenario 1: is using the “precondition” approach
  • Scenario 2: uses the AND operand

Both scenarios work the same:

  1. IF button is pushed
  2. Compare IF switch 1 is “on”
    • Yes > action 1
    • No > action 2