How to use Hub Variable within a Rule

Hi

Can Rule machine access Hub Variables?

Here's what I'd like to do.

I have a porch light connected to a dimmer switch. 10 different rules can control this light.

I need to change the dim levels in the rules. I'd like to avoid having to edit each rule individually.

Is there a way I can setup a global/hub variable that all the rules can use/access. IOW, global/hub variable "X" = 25% dim level, "Y" = 90% dim level.

Then all I need to do is change X and Y variable.

Is this doable? Is there a better way I should be looking at this?

Thanks!!


Please provide your hub model (C7, C8, etc.) and its platform version from Settings>Hub Details.

Check out the following post for help troubleshooting problems and gathering details that will help others to identify and solve the problem you are experiencing: ‼ READ FIRST - Before Posting in Get Help


I would start here, it’s an excellent primer, but short answer… it’s very doable. I have circadian automations the set global variables for dimming and color temp. then calls the automations that changes the bulb dim and color temp based off the set global variable.

In this example i’m setting a global variable for the color temp of my lifx bulbs then the calling the automation to set the color temp based off the global variable.

As mentioned above, this is certainly possible. However, the linked post is a bit old; Rule Machine (now "Rule Machine Legacy") once had an app-level feature called global variables, but now there is a feature called "hub variables" that is accessible to any app that chooses to add support for them, including modern versions of Rule Machine.

Here are the docs for that page:

https://docs2.hubitat.com/en/user-interface/settings/hub-variables

In a Rule 5.1 rule, you'll find various actions for setting or using the value of hub variables. The rule above is a modern rule that uses such a feature.

Rule Machine is a pretty complicated app, so if you're completely new to it, you might want to start with smaller, simpler rules just to get the hang of how it works. Some other apps can also use hub variables, not just Rule Machine (like "old" Rule Machine global variables), so you might not need to do everything there. For example, Room Lighting can use them (but not set them, so you'd still need something for that -- but these would probably be separate rules, anyway, unless you're setting it manually).

2 Likes

Is this what you want? It will work with local or global variables.

I think the OP want to change value of X & Y in other rules and then have another rule issue the commands to the various devices. If that is the case he'll need a global variable (Hub Variable).

Purists would frown at the use of global variables because of the unintended consequences of them, occasional unpredictability, and poor encapsulation. To each his own.