Skip to content

Cookie preferences

We use cookies for our own analytics, to see how our campaigns perform and, if you allow it, to load content from other services such as the Google site search. We never sell your data. Necessary cookies keep the site working and cannot be switched off. See our Cookie Policy for details and our Privacy Policy for how we handle personal data.

Security, load balancing and remembering your cookie choice.

Show us which pages people read, how they find the site and where they get stuck, so we can improve it (Google Analytics, Microsoft Clarity).

Show us which of our ad campaigns bring visitors to the site and remember the campaign or partner link you arrived from (Google Ads, LinkedIn, Meta, partner program). We do not use these cookies to build advertising profiles.

Load the site search from Google when you use it. Google sets its own cookies and shows ads in the search results.

© 2026 The ThingsBoard Authors

Rule Engine

The Rule Engine is the data processing backbone of ThingsBoard. Every incoming telemetry reading, attribute update, device lifecycle event, or RPC call becomes a Message that flows through a Rule Chain — a visual pipeline of Rule Nodes that filter, enrich, transform, or act on it.

IoT Hub

Skip building a Rule Chain node by node — find a pre-built template in the ThingsBoard IoT Hub that fits your use case and plug it into your setup in just a few clicks.

Browse the catalog

A Rule Engine Message is an immutable, serializable data structure representing a single event:

Field Description
Message ID Universally unique identifier (UUID) of the message
Originator The entity that generated the message (Device, Asset, etc.)
Type What triggered the message — e.g. POST_TELEMETRY_REQUEST, INACTIVITY_EVENT
Payload JSON body with the event data
Metadata Key-value pairs with contextual data (device name, type, custom fields added by nodes)

For the full list of built-in type strings, originators, metadata fields, and payload shapes, see Rule Engine Message Types.

A Rule Node processes one incoming message at a time and produces one or more outgoing messages. Nodes are the building blocks of Rule Chains and fall into seven categories — see Rule Nodes for the full reference.

A Rule Chain is a directed graph of Rule Nodes connected by relations. When a node produces an outgoing message, the relation type (e.g. Success, Failure, True, False, or a custom name) determines which connected nodes receive it next.

The Root Rule Chain is the default entry point for all incoming messages. There is exactly one Root Rule Chain per tenant at a time. You can define any number of additional chains; both the root and additional chains can forward messages to each other using the rule chain flow node. See Forward Messages to Another Rule Chain.

A device profile can override routing for all its devices with two settings:

Setting Effect
Default rule chain Messages from devices of this profile are routed to the specified chain instead of the Root Rule Chain
Queue Messages from devices of this profile are placed in the specified queue instead of the default Main queue

An asset profile has the same two settings for messages from its assets.

This lets you isolate processing logic and queue priorities per device or asset type without modifying the root chain.

Every message processing attempt ends as Success, Failure, or Timeout:

Result When it occurs
Success The last node in the processing path completes successfully
Failure A node produces a Failure output and no downstream node handles it
Timeout Overall processing time exceeds the configured threshold

A message is only marked as Failure if the failure output is unhandled. Connecting a node to the Failure relation (e.g. a log or fallback write) means the failure is handled and the message can still end as Success:

To track success, failure, and timeout counts across all rule chains, use the statistics dashboard. To investigate why a specific node failed, enable debug mode on that node.

Only tenant users can create and manage rule chains: tenant administrators and users whose role grants permissions on the Rule Chain resource. Customer users cannot.

  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Click + Add rule chain ⇾ Create new rule chain in the top-right corner.
  3. Enter a name and click Add.
  4. Click the rule chain row to open the editor and add nodes. See Edit a Rule Chain.

Go to Data processing ⇾ Rule chains in the left sidebar and click the rule chain row. The editor opens: rule nodes are listed by category on the left, and the rule chain is on the canvas.

Action How
Add a node Drag a node from the left panel onto the canvas. Enter a Name and the node settings, then click Add.
Configure a node Double-click the node. See Configure and Test a Rule Node.
Connect two nodes Drag from the point on the right side of a node to the point on the left side of another node. In Add link, select one or more Link labels, for example True, and click Add. The list shows the relations that the source node supports; other labels are not accepted. For some nodes, such as switch, you can also type a new label and click Create a new one!
Change a link Click the link, then click the pencil icon next to its label. Change the Link labels in Rule node link details and click the check mark (Apply changes) in the panel header.
Delete a link Click the link, then click ✕ next to its label.
Delete nodes and links Select them and click Delete selected nodes and connections (trash icon) in the bottom-right corner, or press Delete.

Changes take effect only after you save them. Click Apply changes (check mark icon in the bottom-right corner, or Ctrl+S, ⌘S on macOS) to save the rule chain, or Decline changes (✕ icon, or Ctrl+Z, ⌘Z on macOS) to discard all unsaved changes. There is no step-by-step undo.

To configure a rule node, double-click it in the editor. The configuration window is specific to each node type.

Nodes with TBEL/JS scripts provide a Test … function button, for example Test filter function. Use it to verify the script with custom inputs before deploying. The test dialog has four panels:

Panel Content
Message (top left) Message type and payload
Metadata (top right) Metadata key-value pairs
Function (bottom left) The TBEL/JS function
Output (bottom right) Execution result

Click Test to run the function, and Save to copy the edited script back to the node.

  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Open the chain that contains the nodes you want to extract.
  3. Select at least two nodes and the links between them — drag a selection rectangle around the group, or Ctrl-click each node and each link individually. If the links are not selected, Create nested rule chain does not appear in the menu, and Ctrl+R reloads the browser page instead, discarding unsaved changes.
  4. Press Ctrl+R (⌘R on macOS), or right-click the selection and choose Create nested rule chain. Enter a Name and click Create. ThingsBoard saves the new rule chain and replaces the selected nodes in the current chain with a single rule chain node pointing at it.
  5. Click Apply changes to save the current chain.
  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Open the rule chain that will reference the target chain.
  3. From the Flow palette, drag a rule chain node onto the canvas.
  4. Enter a Name, select the target rule chain, and click Add.
  5. Wire one or more connections from the relevant node output of your existing flow into the rule chain node, then click Apply changes.
  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Click + Add rule chain ⇾ Import rule chain in the top-right corner.
  3. Upload the JSON file and click Import.
  4. The imported chain opens in the editor. Review it and click Apply changes to save it.
  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Click the Export rule chain icon in the desired row.

A JSON file is saved to your computer.

  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Click the Make rule chain root (flag) icon in the row of the rule chain you want to set as root, and confirm.
  1. Go to Data processing ⇾ Rule chains in the left sidebar.
  2. Click the Delete (trash) icon in the desired row and confirm. To delete several chains, select their checkboxes and click the Delete icon in the table header. The Root Rule Chain cannot be deleted.

Rule Engine uses message queues to guarantee delivery under load, handle traffic spikes, and control the order in which messages are processed. See Queues for configuration details, submit and retry strategies, and the three built-in queues.

ThingsBoard provides a Statistics dashboard for tracking throughput, failures, and exceptions across all queues, and Debug mode for per-node message tracing. See Rule Engine Monitoring for the full reference, including the debug event columns, the two debug modes, and the step-by-step troubleshooting workflow.

ThingsBoard provides an HTTP API to send custom requests directly to the Rule Engine and return the processing result in the response body — useful for extending the platform API, enriching calls with device/asset attributes, or powering custom widgets.

Use the rule-engine-controller endpoints from the REST API reference. The entity ID in the request becomes the message originator. If omitted, the calling user entity is used. The request creates a REST_API_REQUEST message. To return a response, route it to a rest call reply node; otherwise the call times out.

A DHT22 sensor reports temperatures between −40 °C and +80 °C. Any reading outside that range should be discarded and logged instead of saved. You need a device whose profile uses the Root Rule Chain (see Route Messages by Device or Asset Profile). The steps use the editor actions described in Edit a Rule Chain.

  1. Go to Data processing ⇾ Rule chains and open the Root Rule Chain.
  2. From the Filter palette, drag a script node onto the canvas. Enter the name Temperature Validation and replace the default script with this one. Messages without temperature pass the filter, so other telemetry is still saved:
    return msg.temperature == null || (msg.temperature >= -40 && msg.temperature <= 80);
    Click Add.
  3. Delete the Post telemetry link between Message Type Switch and Save Timeseries: click the link, then click ✕ next to its label.
  4. Connect Message Type Switch to Temperature Validation with the Post telemetry label.
  5. Connect Temperature Validation to Save Timeseries with the True label.
  6. Connect Temperature Validation to Log Other with the False label.
  7. Click Apply changes.

To test the filter, go to Devices & assets ⇾ Devices, open the device, and click Copy access token. In the commands below, replace $ACCESS_TOKEN with the token.

Test — out-of-range value (99 °C):

Terminal window
curl -X POST -d '{"temperature":99}' \
https://eu.thingsboard.cloud/api/v1/$ACCESS_TOKEN/telemetry \
-H "Content-Type:application/json"

The value does not appear on the device’s Latest telemetry tab: the filter returned false and sent the message to Log Other, which writes it to the ThingsBoard server log.

Test — valid value (24 °C):

Terminal window
curl -X POST -d '{"temperature":24}' \
https://eu.thingsboard.cloud/api/v1/$ACCESS_TOKEN/telemetry \
-H "Content-Type:application/json"

The value appears on the device’s Latest telemetry tab: the filter returned true, and Save Timeseries stored it.