- Use case
- Prerequisites
- 1. Provision asset and devices
- 2. Emulate telemetry using Rule Engine
- 3. Import a calculated field on the asset
- 4. Verify the configuration
- 5. Visualize data using a dashboard (optional)
- Next steps
This guide demonstrates how to calculate a telemetry delta using data from two different devices in ThingsBoard and store the result as asset telemetry.
As an example, we will calculate the temperature difference between indoor and outdoor thermometers installed in a warehouse. The calculated value is stored as a new telemetry key and can be used for monitoring, visualization, or alerting.
This guide is introductory and focuses on demonstrating the core capabilities of the platform, rather than building configurations from scratch.
For this reason, predefined calculated field configurations are provided and imported during the setup.
After importing these configurations into your ThingsBoard instance, you can examine their structure, logic, and behavior, and then adapt them to suit your own use cases.
Use case
Assume you have a warehouse equipped with two temperature sensors:
- Indoor Thermometer
- Outdoor Thermometer
Your objective is to:
- Collect telemetry from both devices
- Calculate the absolute temperature difference between the indoor and outdoor readings
- Store the result as telemetry on the warehouse asset
- Visualize and monitor this value in real time
This example demonstrates cross-entity data aggregation, where telemetry from multiple devices is processed at the asset level.
Prerequisites
Before proceeding, it is recommended to review the ThingsBoard Calculated fields documentation.
This topic provides the necessary foundation for understanding entity relationships and data processing mechanisms used in this example.
1. Provision asset and devices
In ThingsBoard, an asset is an abstract entity used to represent logical objects such as buildings, warehouses, or production lines.
In this example, the asset represents a warehouse and is used to store aggregated telemetry from multiple devices.
Create the asset:
- Navigate to Entities ⇾ Assets.
- Click the “+ Add asset” button in the top-right corner, select “Add new asset” and create:
• Asset name: Warehouse A
• Asset profile: warehouse
Create two devices:
- Download the CSV file containing the device configuration:
thermometers_device_data.csv - Navigate to Entities ⇾ Devices.
- Click the “+ Add device” button in the top-right corner and select “Import device”.
- Upload the CSV file and follow the import wizard instructions.
CSV configuration details:
- CSV delimiter: ,
- Column mapping:
- Name: Indoor Thermometer, Outdoor Thermometer
- Type: thermometer
2. Emulate telemetry using Rule Engine
Since this example uses virtual devices, telemetry must be generated artificially.
Use Rule Engine to periodically publish random temperature values.
For simplicity, the generators are added to the Root Rule Chain, although in production setups a dedicated rule chain should be used instead.
- Navigate to Rule chains.
- Open the Root Rule Chain.
- Drag and drop a Generator node onto the canvas.
- Select Indoor Thermometer as the originator.
- Replace the generator function with the appropriate emulator script.
- Repeat the same steps for the Outdoor Thermometer device.
- Connect both Generator nodes to the Entity type filter node using the Success relation.
- Apply changes.
Indoor Thermometer emulator script:
1
2
3
4
5
var indoorTemperature = toFixed(Math.random()*10 + 18, 2);
var msg = { indoorTemperature: indoorTemperature };
var metadata = { data: 40 };
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, metadata: metadata, msgType: msgType };
This generator simulates indoor temperatures in the range of approximately 18–28 °C.
Outdoor Thermometer emulator script:
1
2
3
4
5
var outdoorTemperature = toFixed(Math.random()*10 + 16, 2);
var msg = { outdoorTemperature: outdoorTemperature };
var metadata = { data: 40 };
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, metadata: metadata, msgType: msgType };
This generator simulates outdoor temperatures in the range of approximately 16–26 °C.
Verification
After the generators start running:
- Open Entities ⇾ Devices ⇾ Indoor Thermometer ⇾ Latest telemetry.
- Open Entities ⇾ Devices ⇾ Outdoor Thermometer ⇾ Latest telemetry.
You should see continuously updated temperature values.
3. Import a calculated field on the asset
Calculate the temperature difference between the two thermometers and store it as asset telemetry.
- Download the calculated field configuration file:
temperature_delta_based_on_2_devices_cf.json. - Navigate to the Calculated fields page.
- Click the “+ Add calculated field” button in the top-right corner and select “Import calculated field”.
- Upload the calculated field configuration file.
- Select the warehouse asset profile as the target entity so the calculated field is applied automatically to all relevant assets.
- Update the calculated field arguments as follows:
• First argument:
• Entity type: Device
• Device name: Indoor Thermometer
• Argument type: Latest telemetry
• Time series key: indoorTemperature
• Argument name: indoorTemperature
• Second argument:
• Entity type: Device
• Device name: Outdoor Thermometer
• Argument type: Latest telemetry
• Time series key: outdoorTemperature
• Argument name: outdoorTemperature - Click Add to complete the import.
Calculation logic
1
abs(indoorTemperature - outdoorTemperature)
This calculates the absolute temperature difference regardless of which value is higher.
Once saved, the asset automatically receives updated deltaTemperature telemetry.
4. Verify the configuration
- Open Entities ⇾ Assets ⇾ Warehouse A ⇾ Latest telemetry.
- Confirm that the deltaTemperature key is present and updates in real time.
This confirms that:
- Telemetry is received from both devices
- The calculated field executes correctly
- The result is stored on the asset
5. Visualize data using a dashboard (optional)
To monitor temperature differences visually:
- Download the prepared Warehouse dashboard JSON file.
- Import it into ThingsBoard.
- After the import, update the entity alias by setting Warehouse A as the target entity to ensure its data is displayed correctly.
The dashboard should display a real-time chart and table showing the temperature difference between the indoor and outdoor thermometers.
Next steps
-
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
-
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
-
Data visualization - These guides contain instructions on how to configure complex ThingsBoard dashboards.
-
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
-
Advanced features - Learn about advanced ThingsBoard features.
-
Contribution and Development - Learn about contribution and development in ThingsBoard.