Skip to content
Stand with Ukraine flag

Connectivity Status

The Device State service tracks whether each device is active or inactive, updates a set of server-side attributes (or time-series) with connection timestamps, and emits connectivity events into the Rule Engine. This lets you build automations — notifications, alarms, dashboard indicators — that react to devices going offline or coming back online.

When a device connects, disconnects, or becomes inactive, ThingsBoard updates the following values:

FieldTypeDescription
activeBooleantrue if the device is currently active
lastConnectTimems since epochWhen the device last connected
lastDisconnectTimems since epochWhen the device last disconnected
lastActivityTimems since epochWhen the device last sent telemetry, attributes, or an RPC command
inactivityAlarmTimems since epochWhen the last inactivity event was fired

By default these are stored as server-side attributes. Set PERSIST_STATE_TO_TELEMETRY=true to store them as time-series data instead — useful when you need historical state graphs in dashboards. When stored as time-series, STATE_TELEMETRY_TTL controls the retention period (0 = unlimited).

The Device State service fires four event types into the Rule Engine. You can configure reactions to each using custom rule chains.

EventWhen it fires
ConnectDevice establishes a session (MQTT) or sends any request (HTTP/CoAP)
DisconnectSession closes (MQTT) or request completes (HTTP/CoAP)
ActivityAn inactive device sends telemetry, updates attributes, or sends an RPC command
InactivityNo activity received within DEFAULT_INACTIVITY_TIMEOUT seconds

A device is marked inactive when no activity is received for DEFAULT_INACTIVITY_TIMEOUT seconds (default: 600 s / 10 minutes). ThingsBoard checks all devices on a schedule controlled by DEFAULT_STATE_CHECK_INTERVAL (default: 60 s).

Transport session vs device inactivity — these are separate timeouts:

  • DEFAULT_INACTIVITY_TIMEOUT — when the Device State service marks a device inactive
  • TB_TRANSPORT_SESSIONS_INACTIVITY_TIMEOUT — when an open MQTT session is closed server-side

Keep the transport session timeout ≥ the device inactivity timeout to avoid a device being marked inactive while its session is still open.

For high-frequency devices, reporting every message to the Device State service can add load. The TB_TRANSPORT_ACTIVITY_REPORTING_STRATEGY setting (default: LAST) controls how often activity is forwarded.

Time is divided into consecutive reporting periods of fixed length (controlled by TB_TRANSPORT_SESSIONS_REPORT_TIMEOUT, default: 3000 ms).

StrategyWhat is reported
ALLEvery activity, immediately — most accurate, highest load
FIRSTFirst activity of each period immediately; last activity if no activity in the next period
LASTOnly the last activity, when the period ends — lowest load, slight delay
FIRST_AND_LASTFirst activity immediately + last activity at period end

Example — 10 000 devices sending telemetry every second with TB_TRANSPORT_SESSIONS_REPORT_TIMEOUT=3000 ms:

StrategyMessages / sec to Device State service
ALL10 000 (every message forwarded)
FIRST_AND_LAST≤ 6 667 (first + last per 3 s period)
FIRST≤ 3 334 (first per period; last only if quiet in next period)
LAST≤ 3 334 (one per period, at period end)

LAST cuts Device State service load by up to compared to ALL, at the cost of up to one reporting-period delay before lastActivityTime is updated.

Environment VariableDefaultDescription
DEFAULT_INACTIVITY_TIMEOUT600Seconds without activity before a device is marked inactive
DEFAULT_STATE_CHECK_INTERVAL60How often (seconds) ThingsBoard checks for inactive devices
PERSIST_STATE_TO_TELEMETRYfalseStore state fields as time-series instead of server-side attributes
STATE_TELEMETRY_TTL0TTL (seconds) for state time-series data; 0 = unlimited
TB_TRANSPORT_ACTIVITY_REPORTING_STRATEGYLASTActivity reporting strategy: ALL, FIRST, LAST, or FIRST_AND_LAST
TB_TRANSPORT_SESSIONS_REPORT_TIMEOUT3000Reporting period duration in milliseconds
TB_TRANSPORT_SESSIONS_INACTIVITY_TIMEOUT300000Milliseconds before an idle transport session is closed