Logic and diagnostics
TapHome script functions for unknown values and device diagnostics: ISNULL, ISNAN, EQUALS, SLEEP, ADDERROR, ADDWARNING, ADDINFO and DEBOUNCE.
These functions test values for Null and NaN, compare decimal numbers with a tolerance, pause a device script and report messages on a device. NaN is an unknown number, Null is a missing value — see Data types. The minimum Core version of each function is in Version requirements.
ISNULL
ISNULL returns TRUE when a value is Null, a missing value — for example LastState on the first run of a Formula smart rule, or PARSEJSON with error ignoring when the path is not found.
| |
Returns — bool. Any type of value is accepted. NaN is a number, not a missing value, so ISNULL(NaN) is FALSE.
Example
IF(ISNULL(LastState), 0, LastState);
# Result: 0 on the first run of a Formula smart rule, then the previous resultSee also — ISNAN, Scripts in smart rules.
ISNAN
ISNAN returns TRUE when a number is NaN, an unknown value — for example the value of a device that is in error or has not been read yet.
| |
Returns — bool.
Remarks — NaN is never equal to anything. A comparison with the literal NaN, such as x = NaN, is rejected when you save the script. The argument must be a number: ISNAN(Null) stops the script with a run-time error, so test ISNULL first when a value can also be missing.
Example — write 0 when a device is in error or returns NaN
Use IF(ISNAN(x), 0, x) to pass on a number even while the source device is in error:
IF(ISNAN(x), 0, x);
# Result: 0 while the device is in error or returns NaN, otherwise xWhen the value can be Null as well, check it first — OR does not evaluate its right side when the left side is already TRUE:
IF(ISNULL(value) OR ISNAN(value), 0, value);Errors — Comparison with NaN is always false. Use the IsNaN method to check for NaN value. (when saving the script).
EQUALS
EQUALS returns TRUE when two numbers differ by at most a tolerance (epsilon, 0.005 by default); use it instead of = for decimal values such as temperatures.
| |
Parameters
| Name | Type | Description |
|---|---|---|
number1, number2 | number | Values to compare. |
epsilon | number, optional | Largest difference still counted as equal. Default 0.005. |
Returns — bool. Two NaN values count as equal, so EQUALS(NaN, NaN) is TRUE. A Null argument is a run-time error.
Example
EQUALS(21.499, 21.5);
# Result: TRUE
EQUALS(21.4, 21.5, 0.01);
# Result: FALSE
EQUALS(NaN, NaN);
# Result: TRUESLEEP
SLEEP pauses a Modbus or Packet parser script for the given number of milliseconds (0 – 10 000) and returns that number.
| |
Remarks — While the script waits, the module does not poll its devices, so keep the pause short, typically a gap a device needs between two writes.
Example
MODBUSW(H, 100, Uint16, 1);
SLEEP(200);
MODBUSW(H, 101, Uint16, 1);Errors
- SLEEP function not allowed in this context. — the script belongs to a smart rule (Equation, Formula or Script) or to a notification; it cannot be saved.
- Interval ‘X’ is out of range (0-10000) — at run time.
Available — Modbus and Packet parser scripts.
ADDERROR, ADDWARNING, ADDINFO
ADDERROR, ADDWARNING and ADDINFO show an error, a warning or an information message on the device in the TapHome app and return TRUE.
| |
Parameters
| Name | Type | Description |
|---|---|---|
code | whole number, optional | Identifies the message. Messages with different codes are shown side by side; a new message with the same code, or a second message without a code, replaces the previous one. |
text | string | Message shown in the app. |
Remarks — The messages are evaluated on every run: a message disappears as soon as a run of the script no longer raises it.
Example
VAR alarm := MODBUSR(H, 599, Uint16);
IF(alarm > 0, ADDERROR("There are " + alarm + " active alarms"));
IF(GETBIT(MODBUSR(H, 600, Uint16), 0) = 1, ADDERROR(1, "Alarm 1 active"));
IF(GETBIT(MODBUSR(H, 600, Uint16), 1) = 1, ADDWARNING(2, "Filter change due"));Errors — ADDERROR function not supported here. (or ADDWARNING, ADDINFO) in any script not listed under Available.
Available — read scripts of Modbus modules and devices; read, write and listener scripts of Packet parser. Not in Modbus write and initialize scripts, service attributes and service actions of either integration, smart rules or notifications.
See also — Modbus functions, Packet parser functions.
DEBOUNCE
DEBOUNCE ignores the values of one device value read from the device for the given number of milliseconds and checks the value again when that time ends; writes to the device are not affected.
| |
Parameters
| Name | Type | Description |
|---|---|---|
deviceVariable | device variable | Abbreviation of the device value, for example St. An expression is not accepted. |
milliseconds | number | Length of the window, 0 or more. |
Returns — the interval. On a device value without a debounce filter the call does nothing.
Example
DEBOUNCE(St, 500);Errors
- DEBOUNCE - Function is not available — the script is not a device script listed under Available.
- DEBOUNCE - invalid argument, must be a device variable
Available — Core 2026.1, build 36599 and later · Modbus device read and write scripts, Packet parser read, write and listener scripts.