TapHome Icon

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 highlights the syntax in the script editor.

Where scripts are used

The same script language runs in smart rules, notifications and the Modbus and Packet parser integrations:

ContextWhat the script doesSpecific to the context
Equation smart ruleOne expression over device values. TRUE runs the true actions, FALSE the false actions.LastState, TriggerName
Formula smart ruleComputes a value that is written to every output device.LastState, TriggerName
Script smart ruleReads device values and assigns new ones; each assignment becomes a device action.Read-write variables, TriggerName
Formula limiting conditionDecides whether a smart rule may run.TRUE lets the rule run
Notification title and messageBuilds the text of a notification.Must return text; notification constants
Modbus module read scriptPolls the module, typically to raise device errors.MODBUS* functions
Modbus device read and write scriptsConverts registers into a device value and a requested value back into registers.The read result becomes the device value
Modbus initialize scriptRuns once after the module connects.Typically MODBUSWNE
Packet parser read and write scriptsSends 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 scriptHandles 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: 3

The 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 valueAllowed result
Switch state, reed contactTRUE or FALSE (numbers are accepted), NaN, Null
Multi-value switch stateNumber (a whole number selects the state; a decimal value is not rejected), NaN, Null
Any other valueNumber, 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.

Pages in this section

The script language reference has four groups of pages: a guide to the language, the functions by area, the integration functions and reference lists.

Guide

  • Syntax and control flow — statements, comments, literals, IF, SWITCH, WHILE and DO loops, RETURN.
  • Data types — numbers, text, structured and enum types, collections, .Type, type promotion, Null and NaN.
  • Variables and constants — device variables, group values, module variables, VAR and typed declarations, properties, context constants.
  • Statistics and value info — statistics of a device, Value info with the time of the last change, the previous value and the values of finished periods.
  • Operators — operator list, precedence, short-circuit evaluation, Excel equivalents.
  • Scripts in smart rules and notifications — Equation, Formula, Script, the Formula limiting condition and notifications.

Functions

Integrations

  • Modbus functions — register types, MODBUSR, MODBUSW, MODBUSWNE, MODBUSRBLOCK, MODBUSWBLOCK, MODBUSWBLOCKNE.
  • Modbus data types — data types of the Modbus functions, byte order variants, 64-bit types, text.
  • Modbus scripts and prefetch — which scripts a Modbus module and device have, when they run, prefetch and caching.
  • Packet parser functions — HTTPREQUEST, SENDHTTPREQUEST, SENDDATA, MQTTPUBLISH, FTPDOWNLOAD, FTPUPLOAD, COMPLETESERVICEATTRIBUTE, COMPLETESERVICEACTION.
  • Listener scripts — the listener script of a Packet parser module, RECEIVEDMSG and RECEIVEDBYTES.

Reference