Skip to content
Stand with Ukraine flag

Calculated Fields

Calculated fields transform raw sensor data into actionable insights in real time. Instead of just storing telemetry, you define a calculation rule and ThingsBoard automatically generates derived values — stored as time series or attributes — the moment data arrives.

Calculations draw from multiple sources: incoming telemetry, entity attributes, or data from related assets and devices. Results are immediately ready for dashboards, alarms, and automation.

Executions can be chained: the output of one field triggers the next, enabling multi-step processing pipelines. ThingsBoard automatically prevents infinite loops — if the same calculated field appears twice in a single execution chain, the chain is stopped.

Calculated fields apply at two levels:

If both an entity-level and a profile-level calculated field match the same entity, both run.

Available since ThingsBoard 4.0. The Aggregation and Geofencing types were added in 4.3.

TypeBest for
SimpleSingle math expression: +, -, *, /, sqrt, pow, abs, min, max
ScriptMulti-step logic, conditionals, rolling windows, multiple outputs (TBEL)
PropagationCopy or compute values and push them to related entities via relations
GeofencingGPS zone detection — INSIDE/OUTSIDE status and ENTERED/LEFT events
Related entities aggregationAvg, min, max, sum, count across multiple child or parent entities
Time series data aggregationHourly/daily/weekly KPIs from historical telemetry of the current entity

The creation process is identical for Devices, Assets, Device profiles, and Asset profiles.

  1. Open the Calculated fields page.
  2. Click the + Add calculated field ⇾ Create new calculated field in the top-right corner.
  3. Configure the General, Arguments, Calculation, and Output sections.
  4. Click Add to save.
FieldDescription
TitleDescriptive name reflecting the field’s purpose
Entity typeThe device, asset, or profile to which the field is applied
TypeThe calculated field type — determines which configuration sections are available

Arguments define which data the calculated field reads and exposes as named variables for the calculation. Each argument maps a data source to a named variable. Choose the entity to read from (current entity, a specific Device/Asset, Customer, tenant, or owner), then select one of three types:

  • Attribute — a single attribute value (Server, Client, or Shared scope) with an optional default fallback.
  • Latest telemetry — the most recent value of a telemetry key, with an optional default fallback.
  • Time series rolling (Available in Script and Propagation fields) — a sliding historical window of telemetry values, exposing aggregation methods (mean(), sum(), min(), max(), and more).
    For the full rolling argument API, see Script — Rolling Argument API.

The calculation block depends on the selected type:

TypeCalculation model
SimpleSingle mathematical expression
ScriptTBEL function returning a JSON object or array
PropagationArguments-only (direct copy) or TBEL script
GeofencingZone group configuration
Related entities aggregationAggregation metrics (avg, min, max, sum, count)
Time series data aggregationAggregation metrics over historical intervals

See each type’s page for full details and examples.

All field types store results on the same entity where the field is applied. The only exception is the Propagation type, which writes its output to related entities.

Results are stored as either time series or attributes:

Storage typeContentNotes
Time seriesJSON object or array, with or without a timestampEnable Use latest timestamp to align with argument data time
AttributeJSON object without timestampStored in Server or Shared scope

Controls how the result is processed after calculation.

StrategyBehavior
Process right away (default)Result is stored directly, bypassing Rule Chains with minimal latency
Process via Rule ChainsThingsBoard generates a POST_TELEMETRY_REQUEST or POST_ATTRIBUTES_REQUEST message and routes it to the entity’s Default Rule Chain

Time series options:

OptionDescription
Save to time seriesStores historical values in the time series database
Save to latest valuesUpdates the latest value store if the timestamp is newer
Send to WebSocketsPushes updates to active WebSocket subscribers (no database write)
Send to Calculated fieldsForwards updates to other calculated fields, enabling chained dependent fields
Custom TTLSets a custom storage duration; if disabled, the Tenant Profile TTL applies

Attribute options:

OptionDescription
Save to databaseWrites the attribute to persistent storage
Send to WebSocketsPushes updates to active WebSocket subscribers (no database write)
Send to Calculated fieldsNotifies other calculated fields about attribute changes
Update attribute only on value changeWrites only when the value actually changes
Send attributes updates notificationGenerates an “Attributes Updated” event

The result is not stored directly. Instead, ThingsBoard generates a POST_TELEMETRY_REQUEST or POST_ATTRIBUTES_REQUEST message and routes it to the entity’s Default Rule Chain.

Use this strategy when you need additional processing — filters, scripts, conversions, enrichment, routing, or forwarding. The Rule Chain must include a Save time series or Save attributes node to persist results.

Each calculated field has a Debug toggle. When enabled, ThingsBoard records execution details for every run — the resolved argument values and timestamps that triggered execution, plus the result or any error.

Enable debug mode during field creation or toggle it on an existing field using the Debug button in the row.

Click the Events icon in the calculated field row to inspect recorded events:

FieldDescription
Entity IDThe entity where the field executed
Message IDUnique execution identifier
Message typeWhat triggered the execution (telemetry update, attribute update, etc.)
ArgumentsResolved argument values and timestamps
ResultOutput generated by the field
ErrorFailure reason (only shown when execution failed)

For Script and Propagation (Calculation result mode) fields, click Test with this message in an event row to open the interactive testing panel:

  • Left panel — TBEL script editor; modify the script without saving changes
  • Top-right panel — Argument list; adjust values and timestamps to simulate different inputs
  • Bottom-right panel — Execution output or error
  1. Modify the script or argument values as needed.
  2. Click Test to execute the function with the provided inputs.
  3. Review the output JSON structure and values.
  4. Click Save to keep changes.
  5. Apply the changes to the calculated field configuration to activate the updated logic.

Calculated fields integrate with the ThingsBoard Rule Engine. Execution is triggered automatically whenever telemetry or attributes are processed by:

  • Save Time Series node — triggers when new telemetry is persisted
  • Save Attributes node — triggers when client, shared, or server-side attributes are updated
  • Calculated Fields node — dedicated node for manual invocation or complex chaining

Calculated fields execute on each incoming data update. There are no additional per-field rate limits — the effective execution rate is bounded by the device’s incoming telemetry rate.

Calculated field reprocessing applies the current calculation logic to historical telemetry. Use it to backfill results for data that arrived before the field was created, or to regenerate historical results after modifying an existing field.

  1. Go to the Calculated fields page.
  2. Click the Reprocess calculated field icon next to the desired field.
  3. Define the time interval for reprocessing.
  4. Click Reprocess — the system recalculates and updates historical telemetry.
  5. Click Finish when the process completes.

Example: A Smart Device has been sending temperature and humidity for weeks. You add a dewPoint calculated field today. Without reprocessing, dewPoint appears only from this moment. After reprocessing, dewPoint is backfilled for the entire selected historical period.

The Task Manager is accessible from the left navigation menu under Advanced features ⇾ Task Manager. It lists all background processing tasks, including calculated field reprocessing jobs.

ColumnDescription
Created timeWhen the task was initiated
TypeTask type — e.g. “Calculated field reprocessing”
EntityThe device or asset the task ran against
StatusCurrent state: pending, running, completed, or failed
ProgressCompletion percentage

Each row also provides action icons to view task details, inspect results, or delete the record.

Calculated field configurations can be exported as JSON and imported into any ThingsBoard instance.

Export:

  1. Go to the Calculated fields page.
  2. Click the Export icon in the calculated field row.

Import:

  1. Go to the Calculated fields page.
  2. Click the + Add calculated field ⇾ Import calculated field.
  3. Upload the JSON configuration file and click Import.
  4. Specify the entity or profile to which the field will be applied.
  5. Review any highlighted argument errors.
  6. Click Add to complete the import.
  1. In the calculated field row, click the Delete (trash) icon.
  2. In the confirmation dialog, click Yes to confirm.

All calculated field limits are configurable per tenant in Tenant Profiles → Calculated fields. The table below lists the default values:

LimitDefaultDescription
Calculated fields per entity5Maximum number of calculated fields on a single entity or profile
Arguments per calculated field10Maximum number of arguments per field
Data points per rolling argument1000Maximum number of { ts, value } records in a time series rolling window
State size32 KBMaximum total state stored per calculated field (geofencing zone state, rolling window cache, etc.)
Single value argument size16 KBMaximum size of a single attribute or latest telemetry argument value
Max relation levels (Related entities)2Maximum depth of a relation path when resolving related entities
Min update interval (Related entities)0 sMinimum allowed refresh interval for zone or entity relation caches
Min aggregation interval60 sMinimum allowed aggregation interval (Time series data aggregation type)
Min deduplication interval10 sMinimum allowed deduplication interval (Related entities aggregation type)
Intermediate aggregation interval300 sHow often intermediate (in-progress interval) aggregation results are stored
Reevaluation check interval60 sHow often the system checks for and processes missed aggregation intervals
Relation search entity limit1000Maximum entities resolved at the last level of a relation path