Skip to content

# Set Variable Action

The Set Variable action allows you to set the value of an expression-less Reactor variable. Expression-less variables are a common Reactor paradigm for storing temporary data, such as a mode, a counter/index value, or the previous/current state of a switch or setpoint of a thermostat, before changing it (you can then change it back to that previous value later). To create an expression-less variable, all you do is create a variable but leave the expression field blank. The variable will then take no value other than what you assign to it.

Expression-less variables only!

You are not allowed to change the value of a variable that has an expression associated with it. These variables always have the last evaluation result, and are read-only.

To set a variable value, choose the name of the variable from the dropdown list, and supply a constant value, or you can use the substitution form to specify an expression: `${{ temperature * 1.8 + 32 }}`. If you supply a constant value with no substitution, it will always be a string; if you use expression substitution as the entire value, the data type will be whatever type the expression result produces.

Consider using Script Action

Many users now prefer to use a Script Action when setting a variable to an expression result, assigning the value to the variable in the usual way (i.e. `variableName = expression`). The script in a Script Action is generally regarded as easier to read and support because you don't have to use the awkward substitution syntax. This is particularly true when you need a multi-step or multi-line expression to get the work done.

## Setting Global Variables

When assigning a value to a global variable, any dependent global variables are automatically re-evaluated and updated (unless the dependent variable has auto-evaluate turned off). Dependent variables are those that refer to the target of the Set Variable action. For example, if you have two global variables, where `A` is an expression-less variable and `B` is defined by the expression `A * A`, then whenever `A` is modified, `B` will be recomputed automatically using the new value of `A`.

If a global variable is used by a Rule-based local variable, or in a Rule's trigger condition, the Rule will be marked for re-evaluation — its trigger states will be updated and considered, and the Rule may SET or RESET as the trigger conditions direct.

## Setting Rule-based Local Variables

When assigning a value to a Rule-based local variable, dependent Rule-local variables are automatically re-evaluated and updated (see definition of dependent variables under Setting Global Variables above). If the rule-based variable is used in a trigger condition of the rule, the rule trigger state will be re-evaluated.

Infinite Loop Risk

Take care when making assignments to Global and Rule-based variables in Rule Reactions when the variable is also used in trigger conditions of the same Rule. You can create an infinite loop very easily.

See also: Expressions & Variables and Script Action

Updated: 2025-Sep-23