How to use variables?

Hello everyone,

As a novice Hubitat user, I'm looking through the Settings. This brings me to "Hub Variables".

I've looked at the documentation to find out exactly what this is and how I can use it. I have the idea that RM can use this for example. But how?

Can someone tell me what the power of the variables is? I want to get the best out of the Hubitat.
And just to get it visual for myself, can someone give me an example of a hub variable and how this variable can be used in Rule Machine.

Who can explain this to me and give me the support? What is the power of the variables? Does anyone have an example of how to use variables in their own "smart" environment.

I am very curious.

Greetz,
Martijn

There is some explanation here (for hub variables)

2 Likes

Here is one simple example where I used a global variable. My wife was complaining the laundry room light would come back on after she turned the switch off. The light is controlled via motion sensor in Room Lighting. She doesn't have to turn the switch off but she does out of habit. So I set up a RM rule to set a global variable (Laundry room lights enable) to false for 10 seconds after the switch is turned off. Room Lighting is setup to limit activation when the variable is false.

1 Like

Hi @Sakman ,

Sorry, I feel like I sound really stupid, but what is the variable in this example? Because you can enter a variable String, Time and a few more.
Can you indicate that?

And what does that look like for you under Settings > Hub Variables? Can I see that? Maybe I'll understand it better then.

I really appreciate your help.
What a wonderful community with fast help!

The variable is "Laundry room lights enable". It is a boolean variable which means it can either be true or false.

Screenshot 2023-03-21 111503

Hopefully, this isn't taken as snarky. But, you might not be aware of the documentation/help files available at the top of the forum. If you click that link, and then search for variables, there is a rather comprehensive of hot to create and use them here: Hub Variables (Settings) | Hubitat Documentation

That said, here is a list of my variables. The two highlighted are used in a rule in RM that allows me to put a hold on my thermostat if the outside temperature is below the low limit variable or above the high limit variable. This prevents my thermostat from going into away mode when the temps are low or high enough that the house takes too long to recover (for my wife's preferences).

In this case, I created a connector so that I can put the variables on a dashboard and change them if I want to. This way, I can update the rule values without having to go into Rule machine and edit each line where the variable is used. Also, in this rule, "Thermostat Hold" is just a virtual device that prevents my modes from allowing away mode when I leave the house. I chose a virtual switch in this case because a boolean variable would work, but I really only needed a switch I could put on a dashboard. That is a couple extra steps (Create Boolean with a connector, then go to devices and add the device if using a hub variable as opposed to just creating a virtual device to add to the dashboard)

My general rules for variables:
If it is a boolean that I need to manually change then I use a virtual switch.
If it is a boolean that I can let an app or rule machine change, then I use a hub or rule variable
If it is any other variable type (number, string, etc), I just use a hub or rule variable. If that variable needs to be manually changed/updated, I create the connector(and it has to be a hub variable at that point). Otherwise, I do not create a connector.
If you need a variable to be used by more than one rule, or otherwise globally available, then use a hub variable. If the variable is only used by a single rule, then I prefer a rule variable.

Variables

RM Rule - Same Variables highlighted

image

1 Like

Hi @tray_e ,

Thanks for the tip! I No, I don't see it as snarky :slight_smile:

I took the documentation myself, but it didn't make me any wiser. Then my second step is to look on this forum, I didn't get any wiser from this either, so I created this topic. For example, I was searching for examples of variables. So I can see visual how to use it myself.

There is indeed a lot of documentation, but with regard to the variables it is a general story (in my opinion) with no claer examples. Then it is not clear to me how to use it.

Thanks for your information. The hubitat is a great hub. But it is sometimes very technical. That's cool. But a lot to figure out. But I love this community.

Not sure if you are asking about variables in general (local vs hub) or specifically about Hub (or global) variables. Local variable are only available within the rule that created them. Hub variables can be accessed within any of the rules. I am assuming this is the type you are asking about.

I dont know how/when others use them but for me its usually to prevent writing (& maintaining) multiple rules each with only subtle differences. With a hub variable I can write one rule to achieve many different things. For example, I have multiple cases/rules where I want to send a message to another server. In order to do this I have to repeat several steps (assign the variable value, remove the spaces from the message, send the message,etc). If I assign the message to a gblMessage I dont have to repeat all the other steps needed to send it to the server. I simply call one rule that does all the rest

Example:
Rule # 1

  • set gblMsg = " Camera has come back online"
  • call Rule # 2 (image shown below)

Rule # 2

I may have multiple variations of rule # 1 but with a Hub variable I only need one Rule # 2

Hope that makes sense

1 Like

I use them all over but as a example:

I have light switches which turn on zigbee lights in that instance there is no way to know when the light has been turned on by the switch or from any other way from the network. So when the switch turns on the light it also sets a hub variable to true. When you turn off the switch by the switch or any other means the variable is set back to false.
I then use this variable to disable the lights from automatically being turned off within room lighting.

Some HV

A rule

3 Likes

Hi @cdikland
Thanks, this is a great example!

Hi @BorrisTheCat ,
Thnx for this example. It makes the hub variables clear.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.