If Mode Changes from ____ to _____

Can I have rule machine perform the follow action

If mode changes from Away to Home
Unlock Front Door

I don’t want this rule to occur if the mode changes from Night to home.

Should be simple.. just add a condition when mode Away..

1 Like

Conditional Actions and Logical Expressions
In Rule 4.0 IF-THEN-ELSE-ENDIF conditional blocks can be nested. The UI uses textual indentation to help guide you in keeping track of which IF-THEN-ELSE-ENDIF block you are currently adding actions to. It falls on you to complete each level of nested IF-THEN blocks.

In Rule 4.0 the condition of an IF-THEN or ELSE-IF action can be a full logical expression built up from individual conditions, and logical operators AND, OR, XOR, and NOT. Parenthesized sub-expressions are also possible. This is the same user interface used to create the rule portion of a Rule or Triggered Rule for Rule 3.0. An individual condition can be created 'on the fly' while defining a logical expression. Every such condition is kept in the list of available conditions. This list of available conditions is available on the Define Actions page. It can be opened, and presents the familiar user interface for creating, editing and deleting conditions. If a condition is edited, those changes will be reflected where it is used in an IF-THEN or ELSE-IF conditional action.

This combination of nested IF-THEN blocks and full logical expression for each IF-THEN and ELSE-IF allows creativity for rules in Rule 4.0 that is limited only by your imagination. To help you with complex logic structures, one more new action is provided: Exit Rule. With Exit Rule the execution of actions for that rule stops, irrespective of where in the rule it is. Pending delays are not cancelled, and current repetitions are not stopped. These can be managed separately if so desired with Stop Repeating Actions, Stop Rule Actions, and Cancel Delayed Actions, as appropriate.

Automatic Condition Creation
When Event Triggers are defined, corresponding conditions are created for most types. Some, like button, Certain Time, etc, do not have state and so have no corresponding condition. These created conditions are available in the Define Actions page for use in Conditional actions. These can be edited. For example, in the rule above where Motion Changed was the trigger event, there is an IF-THEN for Motion Active as the first action. Instead of having to create that by hand, it is automatically created. One needs to edit it to modify from using Changed to using Active.

Every condition that you create in a Conditional action is available for use in other actions, and can be edited.

IF-THEN-ELSE
You can introduce conditional execution of actions using:

`IF (condition) THEN 
     some actions...
ELSE-IF (condition) THEN 
     some actions...
ELSE 
     some actions...
END-IF  `

IF-THEN and ELSE-IF both accept a logical expression as described above. IF-THEN-ELSE can be nested. If the expression on the IF part is true, then those actions following the IF and before any ELSE-IF or ELSE statements are run. If the expression is false, then those actions are skipped, and the ELSE part or ELSE-IF part are run. In the case of ELSE-IF, its expression is tested, and the following actions run or not depending on the result. There can be as many ELSE-IF sections as you want, and both ELSE-IF and ELSE are optional. END-IF is also optional, and if omitted means all remaining actions are part of the preceding IF-THEN, ELSE-IF or ELSE. It is strongly recommended that you use END-IF as a regular practice.

1 Like

You could do something like the following.

You could also store the current mode in a variable and then compare that variable to the new mode and take action on that and then store the new mode in the variable again.

1 Like

Technically, that would also catch a mode changing to "Away," changing to something else, then changing to "Day." If you really want only Away to Day directly, you could add a trigger for almost every mode: "Mode becomes Away" OR "Mode becomes Night" OR "Mode becomes XYZ" (everything execpt Day mode as above, or whichever one you care about it changing to), then use an IF to test for the current mode. A "Wait" gets cancelled any time a trigger fires, so the doing of the "other stuff" here won't happen, and as before, the Wait still won't get scheduled unless the mode is Away:

IF (Mode is Away) THEN
  Wait for Events: Mode becomes Day
  Do other stuff
END-IF

Just an idea if this matters!

2 Likes

Agreed, I was just trying to put them on the right track. This is why I use variables in some cases. Below is a snippet of where this can come in handy.

3 Likes

Good point.
So from my understanding this should be the proper setup: (I have 3 modes Away/Home/Night)

Trigger Events

  • Modem Becomes Away
    OR
  • Mode Becomes Night

Select Action to Run

IF (Mode is Away) THEN
  Wait for Events: Mode becomes Home
  Unlock the Door
END-IF

Separately, is their an easier method for rule machine to determine the following scenario. If the current mode is Home and home is called again then DO SOMETHING?

That looks right to me! (Actually it looks odd because it may seem like nothing gets rid of that "Wait," but any trigger firing will indeed get rid of any Wait in progress, so it should work. If you get farther into Rule Machine, Delays are different and do not work like this.)

I'll echo comments from staff that they generally recommend avoiding automating potentially insecure actions like door unlocks, but I will let you assess your own situation. :slight_smile:

I don't think so: the mode can't "change" from Home to Home, so it probably won't create an event, and because of that there is nothing you could trigger on. However, there are some devices where this would work (e.g., on() getting called twice in a row on a switch would match a trigger both times). Mode is a special thing and I'm not sure how that is handled. You could definitely do it if you use virtual switches synced with mode (I do for other reasons, including easy voice control) and activate the mode by turning "on" the switch instead of altering the mode directly, but you'd have to be careful to do it only that way if you care about this trigger. Perhaps others will have better ideas here...

2 Likes

Could you clarify what your thought on this is? What would be the scenario where you would want to take action?

Well it seems it’s not possible for a mode to run again as @bertabcd1234 mentioned (unlike a routine on ST) so I guess this scenario is not possible

A routine on ST is not a mode? If you want a button (or anything) to run a set of actions (which is what a routine was) that is more than possible using RM.

1 Like