A variable is any value that does not stay the same. It varies in some way. It could be a value from a device, or it could be time as two examples. There are many types of possilble variable values. It might be easier to understand if I give one example of how I use a variable.

I have a thermostat that has the capability to display outdoor temperature. I wanted it to specifically display the temperature from the outdoor sensor of my weather station. To do this, I needed to send the temperature of my outdoor sensor to the thermostat as a message. If you haven’t already learned, with Hubitat you can send a variable in a message by putting the variable name in-between percent signs (i.e. %variablename%).

So in this example, I ask the hub to store the temperature of my outdoor sensor as the variable outdoortemp, and then using Rule Machine, I send the message %outdoortemp% to the outside temperature attribute of my thermostat and voila! The display on my thermostat shows the current outdoor temperature.

But where did the “outdoortemp” come from??
And %outdoortemp% where are u typing this..

Why does it need to be a variable why can’t you just tell RM to display current temp of weather station why use a variable ? Seems to me all a variable does is rename something

Display it where? The way I want to display the outdoor temp is on my thermostat, and the way to display it is to send a message to the thermostat. There's no option in the driver of my particular thermostat to choose the temperature of another device, so I store the current temperature of my outdoor thermostat as a variable.

Where did the variable “outsidetemp” come from ??

That is the key question. There has to be a problem to solve before the tool matters. Here are a few examples from my own system. Sometimes they are absolutely needed (i.e. storing the value of a calculation), but often they just make the logic easier.

Hub Variable
I created a variable to store my next alarm time. The information is sent from my phone and stored within Hubitat. I can then access that information to make rules or to display on a dashboard.

When the alarm time changes, the variable updates. Each rule that uses the alarm time will now have access to this updated information.

Local Variables
I happen to use webCoRE for automations, but I am sure that other tools work similarly.

One of my most common automations is turning on a light when motion is sensed, dimming after a period of no motion, and then finally turning off. It was tedious to keep creating similar rules over and over. By defining variables, I could just duplicate a rule (piston in webCoRE) and only tweak a few variables.

I also created a boolean variable that tracks whether the light was turned on due to motion. It stores that information until the light turns off and resets the variable. I want the light to behave differently based on how it was turned on. If motion is sensed at 3am, then a dim light is preferred. If I turn the light on manually, then it is probably something urgent (pet yacking) and I want full brightness. Again, it all comes down to what problem is being solved.


Now I’m really confused I thought we were talking variables not Rules?? Still don’t know where variable come from Aggh!!

We are talking about variables, but what good is storing a variable if you don't eventually use it somewhere? I'm attempting to show you an example of how a variable can be used to answer one of your original questions.

You’re assuming I know how to store information in a variable which I don’t !! I don’t even know where variables come from..

Here you create a variable type and give it a name (any name you want).

This is an action from the above rule that takes the value from my outdoor temperature sensor and stores it in the variable "outdoorTemp" that I created.

The action in the rule that follows it, sends the stored value in the variable to my thermostat's display.

If you needed a variable that stored a value and only wanted to use it within a single rule, you create and name the local variable within that rule instance. There's a section to create a 'local variable' on the rule actions page:

If you needed a variable to be used in multiple rules and/or needed to create a device for that variable (the device connector can be used so that the variable can be added to a dashboard to display it's value) You create those in Settings > Hub Variables. That's a 'hub variable':

Also every rule has a built in 'Private Boolean' (True/False) variable that can be accessed. These confused the life out of me at first. They're very handy to stop a rule from re-triggering before all the actions are completed from the first time it triggered. You do this by making 'Private Boolean is True' a required expression for the rule. Then the first action in the rule is 'Set Private Boolean False' and the very last action in the rule is 'Set Private Boolean True' (allowing the rule to be triggered again.


I am more confused than ever.. why would I need a variable to represent a device when I can just use the device seem where just renaming things ??

Maybe another example. Let's say I want to turn on an exhaust fan, but only if the average temperature is above 85°F. Let's also say I have 3 temperature sensors spread throughout the house. With these I could write a rule that says every time one of the sensors reports a change recalculate the average of the 3 sensors and store it in a variable called avgHouseTemp. Another rule could then look at avgHouseTemp and decide if it needed to turn on the fan or turn it off.

1 Like

You don't - case closed :rofl:

1 Like

Where are u getting “avghousetemp” from??? I understand it’s a hub variable but how do u put info in it.. how do u get the temp sensor info into the variable there’s no way to link them in the variable setup

You write a rule/piston/app to read the sensor data, calculate the average and write it to the variable.

Hub Variables are created once in the settings.

Then as an action in a rule you can set them to some value:

This is how I progressed with variables:

  • WTF is a variable - people keep talking about them
  • I don't need them my automation rules work fine
  • I want my rule to do something a bit more complicated as I've got an idea for something that would be cool
  • To the community - How do I do this - I can't think of a way to do this with my rule?
  • From the community - Create a variable, do x, y, and z to make your rule work

Now it made no sense at first. However once you have a need for them and you have them set up in your rules to do something more complicated, you can see from your own rules use how it's working and you'll start to find ways to use them to solve problems.

1 Like

Curious how would u get RM to avg the 3 sensors