Global/Local Variables

can someone show me a example of a global variable? i have read the thread from hubitat and i cant get my head around it.

Here is a simple example where I used Global Variables in a 4.0 rule for luminance high and low. I use a dashboard tile to input the values with the global variable connector. This way I was able to tune the values without re-opening the rule and editing. Also the Boolean isDarkOutside is a global variable and used in other rules as a trigger.

FYI global variables are superseded by hub variables in the latest versions of the hub and RM. Same basic principle but more flexible because they are maintained by the hub itself and not by rule machine. This means they can be used more easily by other apps.

1 Like

could you have a breakdown of this if possible, coz i got a rule that opens curtains when it gets over 70lux. and a lux sensor inside when it gets over "X" the curtains close as the sun is on that side of the house in the afternoon. but they never open untill the outside lux sensor gets below 70lux. this works fine but i have a button that overrides it and pauses the rule which im trying to avoid.

You need to break down what you are trying to do into simple states and steps:

  • Outside Lux sensor > x set Outside Lux to "True" if now set Outside Lux to "False"
  • Inside Lux sensors > x set Inside Lux to "True" if not set Inside Lux to "False"
  • If Outside Lux true and Inside Lux true do this
  • If Outside Lux true and Inside Lux false do this
  • If Outside lux false and Inside Lux true do this
  • If Outside Lux false and Inside Lux false do this

This is the easiest way I can visualize what you may want to do.

How you write the rules is up to you and how you use variables is based on the scope of where they would be used.

Here's how I do something similar... I use modes and scenes but the idea is the same.

Hmm. Very interesting!!
May I ask how you do this.
I get the global var and connector bit. It's the adjusting from a dashboard tile I don't get.
Would you mind telling me how you do it.

If you use a Variable Number tile when you tap on it, it allows a new number to be entered.

Thanks for the quick reply.
Just been playing and managed to figure it out. I like it!!!!!!!

1 Like

Yep I used to do this with many platforms though their dashboards that is why variables are so powerful. And with a macro language like Rule Machine you don't have to write apps or device drivers to do it.

ok, i still need a little more info. does anyone know if the devs has put a video of global variables up?

i have tried to mess about and i cant even copy that screenshot to try to get a understanding whats going on. in variables, whats the connector for "lux_indoor_lower_limit(80) <<<< its the number i cant replicate. also when trying to "compare to a..." i choose variable and nothing comes up

80 is the illuminance value that existed at the time you looked at that. Show the rule you have setup, that you can't get to do what you want.

Are the new hub variables only accessible from 4.1 rules? I tried to update a 4.0 rule, but I don't see the hub variable when I'm entering a new IF statement.

Hub Variables are not supported in any version of Rule before Rule 5.0, when they were introduced. We are now using Rule 5.1. Before 5.0, Rule-4.0 and Rule-4.1 used Global Variables implemented in Rule Machine.

Yes, I mean 5.1. So in order to use them, I need to re-code the rules from 4.1 to 5.1?

1 Like

Also wondering similar thing - any way we could set the value of a global variable value created in RM Legacy in Rule-5.1?

Not sure what you're asking. But if the question is accessing a value of an Legacy Global variable in a Rule 5.1, or vice versa, accessing a Hub Variable in an older Legacy rule, you could do this via a connector. Both 4.1 Global Variables, and Hub Variables allow connectors to be defined. These are simply virtual devices that mirror the value of the variable itself. Setting the variable sets the device, and vice versa. Such devices can be accessed in ANY app.

1 Like

@bravenel just a quick improvement hopefully in RM 5.1 , I have a hub variable for a time value (number) in a rule I want to use it as a delay on an action in minutes but it has no option to switch so the variable is used in seconds, no biggy just times by 60.

Could RM be updated to have the option between seconds/minutes/ hours when using a variable for delays

No. Too much UI complexity.

OK,. If I selected the hh:mm:ss option instead could I use the %variablename% in the minutes field?