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.
Message
Section titled “Message”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.
Rule Node
Section titled “Rule Node”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.
Rule Chain
Section titled “Rule Chain”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.
Root Rule Chain
Section titled “Root Rule Chain”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.
Route Messages by Device or Asset Profile
Section titled “Route Messages by Device or Asset Profile”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.
Message Processing Results
Section titled “Message Processing Results”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.
Managing Rule Chains
Section titled “Managing Rule Chains”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.
Create a Rule Chain
Section titled “Create a Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Click + Add rule chain ⇾ Create new rule chain in the top-right corner.
- Enter a name and click Add.
- Click the rule chain row to open the editor and add nodes. See Edit a Rule Chain.
Edit a Rule Chain
Section titled “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.
Configure and Test a Rule Node
Section titled “Configure and Test a Rule Node”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.
Create a Nested Rule Chain
Section titled “Create a Nested Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Open the chain that contains the nodes you want to extract.
- 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.
- 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.
- Click Apply changes to save the current chain.
Forward Messages to Another Rule Chain
Section titled “Forward Messages to Another Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Open the rule chain that will reference the target chain.
- From the Flow palette, drag a rule chain node onto the canvas.
- Enter a Name, select the target rule chain, and click Add.
- Wire one or more connections from the relevant node output of your existing flow into the rule chain node, then click Apply changes.
Import a Rule Chain
Section titled “Import a Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Click + Add rule chain ⇾ Import rule chain in the top-right corner.
- Upload the JSON file and click Import.
- The imported chain opens in the editor. Review it and click Apply changes to save it.
Export a Rule Chain
Section titled “Export a Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Click the Export rule chain icon in the desired row.
A JSON file is saved to your computer.
Set a Rule Chain as Root
Section titled “Set a Rule Chain as Root”- Go to Data processing ⇾ Rule chains in the left sidebar.
- Click the Make rule chain root (flag) icon in the row of the rule chain you want to set as root, and confirm.
Delete a Rule Chain
Section titled “Delete a Rule Chain”- Go to Data processing ⇾ Rule chains in the left sidebar.
- 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.
Queues
Section titled “Queues”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.
Monitoring
Section titled “Monitoring”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.
Custom REST API Calls
Section titled “Custom REST API Calls”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.
Example: Temperature Validation
Section titled “Example: Temperature Validation”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.
- Go to Data processing ⇾ Rule chains and open the Root Rule Chain.
- 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
temperaturepass the filter, so other telemetry is still saved:Click Add.return msg.temperature == null || (msg.temperature >= -40 && msg.temperature <= 80); - Delete the Post telemetry link between Message Type Switch and Save Timeseries: click the link, then click ✕ next to its label.
- Connect Message Type Switch to Temperature Validation with the Post telemetry label.
- Connect Temperature Validation to Save Timeseries with the True label.
- Connect Temperature Validation to Log Other with the False label.
- 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):
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):
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.
Was this helpful?