TapHome has one script language for smart rules, notifications and device integrations. The syntax and the functions are the same everywhere; only the available variables, constants and functions depend on where the script runs. The app for Android, Windows and macOS highlights the syntax in the script editor; the iOS app shows the script without highlighting.
Where scripts are used
The same script language runs in smart rules, notifications and the Modbus and Packet parser integrations:
| Context | What the script does | Specific to the context |
|---|---|---|
| Equation smart rule | One expression over device values. TRUE runs the true actions, FALSE the false actions. | LastState, TriggerName |
| Formula smart rule | Computes a value that is written to every output device. | LastState, TriggerName |
| Script smart rule | Reads device values and assigns new ones; each assignment becomes a device action. | Read-write variables, TriggerName |
| Formula limiting condition | Decides whether a smart rule may run. | TRUE lets the rule run |
| Notification title and message | Builds the text of a notification. | Must return text; notification constants |
| Modbus module read script | Polls the module, typically to raise device errors. | MODBUS* functions |
| Modbus device read and write scripts | Converts registers into a device value and a requested value back into registers. | The read result becomes the device value |
| Modbus initialize script | Runs once after the module connects. | Typically MODBUSWNE |
| Packet parser read and write scripts | Sends a request or a command over HTTP, FTP, TCP, UDP or MQTT; for HTTP and FTP it also processes the answer. | SENDHTTPREQUEST, SENDDATA, MQTTPUBLISH |
| Packet parser listener script | Handles every incoming TCP or UDP packet and MQTT message. | RECEIVEDMSG |
| Service attributes and actions (Modbus, Packet parser) | Diagnostic rows and buttons with parameters in the app. | Action parameters by their abbreviation |
SLEEP is rejected in smart rules and notifications (the Formula limiting condition is the exception). ADDERROR, ADDWARNING and ADDINFO work only in device scripts. What each smart rule passes to its script is on Scripts in smart rules and notifications; the integrations have their own pages, Modbus functions and Packet parser functions.
Script result
A script is a list of statements. The value of the last evaluated statement is the result of the script. RETURN ends the script early with the given value.
VAR a := 1;
VAR b := 2;
a + b;
# Result: 3The result of a device read script must fit the device value, otherwise the script fails with Return value 'X' does not match required return type constraint:
| Device value | Allowed result |
|---|---|
| Switch state, reed contact | TRUE or FALSE (numbers are accepted), NaN, Null |
| Multi-value switch state | Number (a whole number selects the state; a decimal value is not rejected), NaN, Null |
| Any other value | Number, NaN, Null |
NaN means “the value is unknown”, Null means “there is no value”. How the two behave in expressions is described in Null and NaN.