Variables and constants
Variables in TapHome scripts: device values by abbreviation, Value info, group values, module and device variables, VAR and typed declarations, assignment, properties and context constants.
Device variables
Device values picked in the script editor are available under their abbreviation, for example Se, Mu or Te. A device that no longer exists reads as Null.
Se + 2;Most scripts only read device values. A script can change a device value in two places:
- In the Script smart rule, a read-write variable can be assigned. Each assignment becomes a device action.
- In a Packet parser listener script, assigning the abbreviation of a device value sets that value.
IF Se > 25
Mu := 1;
ENDAnywhere else an assignment stops the script with Can not directly set value to device variable.
Value info
Input variables of the Equation, Formula and Script smart rules, of the Formula limiting condition and of notification texts can be picked as Value info; the picker lists it as Value info of name of the value. Such a variable holds the current value together with its history:
| Property | Type | Contents |
|---|---|---|
Current | currentvalueinfo | CurrentValueTime, PreviousValue, PreviousValueTime, LastKnownValue, LastKnownValueTime |
History | historyvalues | FirstPeriodStartTime, Values; filled only for an aggregated value of the current period whose history is recorded, otherwise Null |
LastKnownValue is the most recent previous value that was neither NaN nor Null, and LastKnownValueTime is when the device had it.
# Se was picked as Value info of a temperature
IF ISNAN(Se.Current.PreviousValue)
RETURN(Se.Current.LastKnownValue);
END
Se.Current.PreviousValue;Available — Core 2026.1, build 36599.
Group values
A variable bound to a device group holds a groupvalue: Calculated is the value calculated for the group, Values are the values of its members. In arithmetic a group value behaves as its Calculated value.
Module and device variables
Variables defined on a Modbus or Packet parser module or device are available by name and keep their value between script runs. They pass data from a read script to service attributes, or from a listener script to device read scripts.
# Packet parser module read script: one request, the answer is kept for the device scripts
VAR response := SENDHTTPREQUEST("/status", "GET");
StatusJson := response.Content;Available — module variables of a collection type from Core 2026.1, build 39507.
Local variables
A local variable lives for one run of the script. It is declared with VAR, which takes the type of the initial value, or with an explicit type. In both cases the type is fixed for the whole script and every later assignment is converted to it.
VAR a := 5;
int b := 5;
string s := 5;
b := 2.6;
# Result: b = 3, converted to int, halves are rounded away from zero
VAR t := "a";
t := 5;
# Result: t = "5", VAR keeps the type of its first value
uint16 r := 70000;
# Result: r = 4464, a value out of range wraps around silentlyA typed declaration may leave out the initial value; the variable then gets the default of its type (0, FALSE, empty text, an empty collection). VAR always needs a value, VAR y; fails with Variable must have initial value provided.
datetime timestamp;
collection<uint16> block;
double ratio := 0.5;Rules:
- A name starts with a letter and contains only letters and digits;
_fails withOnly letters or numbers are allowed in variable name. - A name must not repeat a constant, a variable or a device abbreviation.
- A variable must be declared above its first use. There is no block scope: a variable declared inside
IFis visible afterEND.
The type keywords are listed on Data types.
Assignment
:= assigns and = compares. The compound operators +=, -=, *=, /=, <<=, >>=, &=, |= and ^= combine an operation with the assignment.
VAR x := 5;
x += 1;
x *= 2;
x <<= 1;
x;
# Result: 24A compound operator has the precedence of its operation, so
x -= a - bis evaluated as(x -= a) - b. Put the right side in parentheses:x -= (a - b);. See Precedence.
Properties
A property is read with .. One level can be written, nested properties can only be read (Unable to assign a value to a nested property), and read-only properties cannot be written.
VAR t := NOW();
t.Minute := 0;
t.Hour;
Se.Current.LastKnownValue;Properties can be read only from a named variable, constant or device variable. NOW().Hour is a parse error; store the value first.
Context constants
Context constants are read-only values that a smart rule or a listener script gives to its script:
| Constant | Available in | Contents |
|---|---|---|
TriggerName | Equation, Formula and Script smart rules | The abbreviation of the variable whose change started the rule, or the name of the trigger that fired. In the Equation smart rule from Core 2026.1, build 35936. |
LastState | Equation and Formula smart rules | The previous result; see Scripts in smart rules. |
RECEIVEDMSG | Packet parser listener script | The incoming message (receivedmessage). |
RECEIVEDBYTES | Packet parser listener script | Older form of the payload as a byte collection; prefer RECEIVEDMSG. |
Notification title and message scripts have these read-only constants:
| Constant | In a notification sent by |
|---|---|
SmartRuleName, LocationName | Any smart rule |
TriggerName | The true or false actions of an Equation smart rule |
CardName, DeviceName | An access event; CardName is Null for an unknown card |
DeviceName | A trigger action |
SensorNames | An alarm |
SensorNames, AlarmPhaseName | An alarm phase |
SensorNames, NumberOfSensors | A sensors action, for example open windows |