## `variables`

Returns a list of the defined global variables and their current values as an array of objects.

Example (GET): `curl 'http://host-ip:8111/api/v1/variables'`

    [{
        "name": "alpha",
        "expr": "time()",
        "index": 1,
        "serial": 357,
        "mdt": 1634912369613,
        "value": 1635981908351,
        "since": 1635981908351
    }, {
        "name": "timeStamp",
        "expr": "t=dateparts(time()),str(t.year)+\"-\"+str(t.month)+\"-\"+str(t.day)",
        "index": 5,
        "mdt": 1634912360804,
        "serial": 223,
        "value": "2021-11-3",
        "since": 1635940828855
    },{
        "name": "attic_dewpoint",
        "expr": "((( entity( \"hubitat>76\" ).attributes.temperature_sensor.value  - 32 ) / 1.8 ) - ((100 - entity( \"hubitat>76\" ).attributes.humidity_sensor.value )/5.0)) * 1.8 + 32",
        "index": 17,
        "mdt": 1634912360806,
        "serial": 51,
        "value": 47.48,
        "since": 1636053296940
    },{
        "name": "testVar",
        "expr": "",
        "index": 13,
        "mdt": 1634912360804,
        "serial": 274,
        "value": null
        "since": 1638334834698
    }]

See `variable/:name` below for an explanation of the fields in each element.

## `variable/:name`

Returns the value of the named global variable.

Example: (GET) `curl 'http://host-ip:8111/api/v1/variable/attic_dewpoint'`

    {
        "name": "attic_dewpoint",
        "expr": "((( entity( \"hubitat>76\" ).attributes.temperature_sensor.value  - 32 ) / 1.8 ) - ((100 - entity( \"hubitat>76\" ).attributes.humidity_sensor.value )/5.0)) * 1.8 + 32",
        "index": 17,
        "mdt": 1634912360806,
        "serial": 51,
        "value": 47.48,
        "since": 1636053296940
    }

A 404 error is returned if the global variable is not defined (you cannot create a variable using this endpoint).

The following are the fields of the response:

- `name` — the name of the variable;
- `expr` — the expression associated with the variable, if any;
- `index` — the user-specified ordinal position of the expression (i.e. sort order);
- `mdt` — the timestamp of the last modification to the variable's definition (i.e. when the expression was last modified, not its value);
- `serial` — the serial number of the variable/expression definition;
- `value` — the last known value of the variable, which can be a primitive type (boolean, number, string, null), an object, or an array.
- `since` — the last modification time of the variable's value.

## `variable/:name/set`

Sets the value of the named global variable. The variable named must be expressionless; that is, its expression must be empty. It is not possible to set the value of expression-driven variables, and attempting to do so will result in an error.

Example: (GET) `curl 'http://host-ip:8111/api/v1/variable/testVar/set?value=123'`

In the above trivial example, the value written to the variable will always be a string data type (even though it looks like a number here). Be careful when assigning booleans and null, because supplying `value=true` or `value=null` on the request will result in the words true or null assigned as strings, respectively.

Example: (PUT) `curl -X PUT -H 'content-type: application/json' -d '{ "value": 123 }' 'http://host-ip:8111/api/v1/variable/testVar/set'`

Using the HTTP PUT method with a JSON request body lets you set any standard JSON data type (string, boolean, number, null, object, array) as the new value. The passed JSON must be an object having a `value` key, the value of which will be the new assigned value on the variable.

Because JSON does not natively support a date/time data type, Reactor generally uses Unix timestamps. See Dates/Times. Reactor does not look for and parse values in the data that may look like dates. The data given is stored as received, and it is up to the user's further processing to handle field contents.

In both cases, a successful assignment of the value returns the same JSON response as the `variable/:name/get` request with the updated value. A 400 error is returned if the named variable is not expressionless. A 404 error is returned if the global variable is not defined (this endpoint cannot create variables).

Note that setting a value on a global variable may cause re-evaluation of dependent variables and rules.

## `variable/:name/update`

Note: this endpoint is new in build 25260.

Cause a re-evaluation of the named global variable. If the variable is expressionless, its value is not modified by this endpoint. If the expression evaluation results in the same value as the variable's current value, no change will be signalled (dependent variables will not be updated, and Rules referencing the global variable are not re-evaluated).

The returned response is the same as that of the `variable/:name/get` endpoint, with the updated value. If the variable is not defined, a 404 error is returned.

Example: (GET) `curl 'http://host-ip:8111/api/v1/variable/testVar/update'`

Updated 2025-09-17