Skip to content
Stand with Ukraine flag

Device Inactivity Alarm

Monitor device connectivity and automatically create or clear an alarm when a device stops sending data.

Thermometer A1 (thermostat profile) sends temperature telemetry to ThingsBoard. When it stops reporting data, ThingsBoard marks it inactive and raises a Device inactive alarm. When the device reconnects, the alarm clears automatically.

Two approaches are covered:

  • Option 1: Alarm Rule — no-code, scoped to a device profile. Best for standard inactivity monitoring.
  • Option 2: Rule Engine — rule chain configuration, supports custom logic such as notifications or external forwarding.

Create a device:

  • Name: Thermometer A1
  • Device profile: thermostat

ThingsBoard’s Device State service automatically maintains two server attributes on every device:

  • activetrue when the device is active, false when inactive
  • inactivityAlarmTime — timestamp of the last inactivity event

You can import a ready-made alarm rule or build it manually.

Option 1. Import alarm rule

  • Download the Device Active/Inactive alarm rule as JSON file and import it into your instance.

When importing, set the thermostat as the target device profile.

Option 2. Create manually

Go to Alarms ⇾ Alarm rules and click + Add alarm rule ⇾ Create new alarm rule.

In the Alarm rule dialog, set:

  • Alarm type: Device inactive
  • Entity type: Device profile
  • Device profile: thermostat (here specify the device type of your device)

Click Add argument and configure it to read the active server attribute:

  • Entity type: Current entity
  • Argument type: Attribute
  • Attribute scope: Server attributes
  • Attribute key: active
  • Argument name: active

In the Trigger conditions section, set Severity to Critical, then click Add condition and configure:

  • Mode: Script
  • Script:
    return active == false;

Scroll down to Clear condition, click Add condition, and configure:

  • Mode: Script
  • Script:
    return active == true;

Click Add to save the alarm rule.

Open Thermometer A1 ⇾ Attributes ⇾ Server attributes. ThingsBoard writes active and inactivityAlarmTime automatically.

To simulate inactivity, edit the active attribute and set it to false:

Open Thermometer A1 ⇾ Alarms. A Device inactive Critical alarm appears:

Set active back to true to clear the alarm:

Use this approach when you need custom processing alongside the alarm — for example, sending a notification email, forwarding data to an external system, or chaining conditional logic.

The Rule Engine processes device connectivity events as special message types:

  • INACTIVITY_EVENT — fired when the device exceeds the inactivity timeout
  • ACTIVITY_EVENT — fired when the device resumes activity

The global default timeout is 600 seconds (state.defaultInactivityTimeoutInSec in thingsboard.yml).

To override it particular device, add an inactivityTimeout server attribute (value in milliseconds):

  • Key: inactivityTimeout
  • Type: Integer
  • Value: 60000 (60 seconds)

Open your Root Rule Chain and create two nodes:

Create Alarm node:

  • Name: Create Inactivity Alarm
  • Alarm type: Inactivity Timeout

Clear Alarm node:

  • Name: Clear Inactivity Alarm
  • Alarm type: Inactivity Timeout

Connect these two nodes to the existing Message Type Switch node:

  • Message Type Switch ⇾ Inactivity Event ⇾ Create Inactivity Alarm
  • Message Type Switch ⇾ Activity Event ⇾ Clear Inactivity Alarm