---
title: "Logic and diagnostics"
description: "TapHome script logic and diagnostics: test Null and NaN, write 0 when a device is in error, compare decimals with EQUALS, report device errors with ADDERROR, debounce values."
url: "https://taphome.com/en/docs/script/logic-and-diagnostics/"
language: en
lastmod: 2026-10-13
generator: hugo
ai:
  topics: ["scripting-language","nan-handling","null-handling","device-errors","diagnostics"]
  questions: ["How do I check whether a value is Null or NaN in a TapHome script?","How do I write the value 0 when a device is in error or returns NaN instead of a number?","How do I compare two decimal numbers with a tolerance?","How do I show a custom error or warning on a Modbus or Packet parser device?","Why does ADDERROR fail with \"function not supported here\"?","Can I use SLEEP in a smart rule?","What does DEBOUNCE do in a device script?"]
---

# Logic and diagnostics

TapHome script functions for unknown values and device diagnostics: ISNULL, ISNAN, EQUALS, SLEEP, ADDERROR, ADDWARNING, ADDINFO and DEBOUNCE.

Last updated: 2026-10-13

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](https://taphome.com/en/docs/script/data-types/). The minimum Core version of each function is in [Version requirements](https://taphome.com/en/docs/script/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.

```text
ISNULL(value)
```

**Returns** — `bool`. Any type of value is accepted. `NaN` is a number, not a missing value, so `ISNULL(NaN)` is `FALSE`.

**Example**

```taphome
IF(ISNULL(LastState), 0, LastState);
# Result: 0 on the first run of a Formula smart rule, then the previous result
```

**See also** — [ISNAN](https://taphome.com/en/docs/script/logic-and-diagnostics/#isnan), [Scripts in smart rules](https://taphome.com/en/docs/script/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.

```text
ISNAN(number)
```

**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:

```taphome
IF(ISNAN(x), 0, x);
# Result: 0 while the device is in error or returns NaN, otherwise x
```

When the value can be `Null` as well, check it first — `OR` does not evaluate its right side when the left side is already `TRUE`:

```taphome
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).

**See also** — [ISNULL](https://taphome.com/en/docs/script/logic-and-diagnostics/#isnull), [EQUALS](https://taphome.com/en/docs/script/logic-and-diagnostics/#equals).

## 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.

```text
EQUALS(number1, number2)
EQUALS(number1, number2, epsilon)
```

**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**

```taphome
# difference is within the default epsilon 0.005
EQUALS(21.499, 21.5);
# Result: TRUE
# difference 0.1 is above the given epsilon 0.01
EQUALS(21.4, 21.5, 0.01);
# Result: FALSE
# two NaN values count as equal
EQUALS(NaN, NaN);
# Result: TRUE
```

## SLEEP

`SLEEP` pauses a Modbus or Packet parser script for the given number of milliseconds (0 – 10 000) and returns that number.

```text
SLEEP(milliseconds)
```

**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**

```taphome
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`.

```text
ADDERROR(text)
ADDERROR(code, text)
ADDWARNING(text)
ADDWARNING(code, text)
ADDINFO(text)
ADDINFO(code, text)
```

**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**

```taphome
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](https://taphome.com/en/docs/script/modbus/), [Packet parser functions](https://taphome.com/en/docs/script/packet-parser/).

## 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.

```text
DEBOUNCE(deviceVariable, milliseconds)
```

**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**

```taphome
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** — TapHome Next 2026.1.36599+ · Modbus device read and write scripts, Packet parser read, write and listener scripts.
