Rule Machine How To: Set a variable in one rule and use in another

Sounds simple enough, but searching didn't lead me quickly to a useful forum topic or the right documentation so I ended up spinning my wheels until I found this info (Rule Machine 5.0 doc; also mentioned in the Rule Machine 5.1 doc).

You want to use Hub variables -- they can be used across rules. Don't use Local variables - they can only be used in the rule they are created in.

KEY TIP: If you don't create a hub variable first, then you won't get Variable as an option in Steps 5 and 11! I'm embarassed to say, this is where I got stuck :confounded: :angry: In hindsight, it makes perfect sense doh!:man_facepalming:t3:

Here are the general steps to set a variable in Rule 1 and check its value in Rule 2.

  1. Go to Settings | Hub Variables and create your variable with a default value
  2. Then go to Apps | Rule Machine and create Rule 1
  3. Add a trigger
  4. Click Select Actions to Run and in the Select Action Type to add dropdown, click Set Variable, Mode or File, Run Custom Action, then click Select Which Action, and Set Variable
  5. Click the variable name you added in step 1 and set its value
  6. Finish creating Rule 1
  7. In Apps | Rule Machine, create Rule 2 and add a trigger
  8. Click Select Actions to Run, then Select Action Type to add, then Condtional Actions
  9. For Select Which Action, click IF Expression THEN, then click Define Expression element *, and then -->New Condition
  10. Under Select capability for Action Condtion, scroll down and click Variable
  11. Select the variable created in step 1 and select a value to check. For example, if the variable is a boolean, you can check values of true or false.
  12. Click Done with this Condition, Done with IF Expression THEN
  13. Finally, add the action(s) you want to take when the conditional expression is true

I finally found this after an hour of working out how to make Local Variable or Private Boolean accessible from another rule, so just wanted to say thanks!

It seems weird to me that you can update another rules private boolean, but you cannot check another rules private boolean. I have no idea why this limitation exists? (I mean I know that makes it non-private, but I cant think of a reason why you would want it totally private anyway....)

@cjcharles You are welcome! I don't know - after figuring out I could do what I needed with humb variables, I never investigated private booleans. Maybe someone else will chime in...

Download the Hubitat app