Skip to content
Stand with Ukraine flag

AI Predictive Maintenance

This guide builds an end-to-end IoT anomaly detection pipeline: devices send vibration, temperature, and acoustic data → Calculated Fields maintain a rolling window → an AI request rule node classifies anomalies → ThingsBoard creates alarms and sends notifications.

  • ThingsBoard version 4.2+.
  • Device(s) capable of sending the required telemetry values (this guide emulates them with curl).
  • LLM provider credentials (OpenAI, Azure OpenAI, etc.) — see AI models.

Expected telemetry keys (per device):

KeyTypeDescription
vibrationfloatVibration level in mm/s
temperaturefloatTemperature in °C
acousticDevfloatAcoustic deviation from baseline in %

AI output (JSON):

{
"anomaly": "Bearing Wear",
"summary": "Vibration has reached 7.4 mm/s and temperature is at 86 °C accompanied by irregular acoustic patterns, indicating bearing wear. Recommend immediate bearing inspection and replacement to avoid catastrophic failure."
}

The calculated field maintains a rolling window of the last 100 readings (configurable, maximum 1000) and forwards them to the rule engine as a single message.

  1. Download and import the EquipmentSensor device profile into your ThingsBoard instance.

  2. Download and import the calculated field into the EquipmentSensor device profile.

Key notes:

  • Rolling window time range is set to 1 day.
  • The number of stored values is set to 100. The default maximum is 1000, configurable in system settings.
  • The TBEL script outputs the rolling values in a single message to the rule engine:
// Output raw values of the rolling arguments
return {
"acousticDevRecords": acousticDevRecords,
"temperatureRecords": temperatureRecords,
"vibrationRecords": vibrationRecords
};

The rule chain analyzes the rolling window data, classifies anomalies, and generates a plain-language summary. It works with OpenAI or any other configured LLM provider.

  1. Download the Equipment Health Analysis rule chain JSON file.

  2. Import the rule chain and review its nodes.

  3. Update the EquipmentSensor profile to reference the Equipment Health Analysis rule chain.

Important details:

  • System and user prompts can reference incoming message data using templatization:
    • $[*] — entire message body
    • ${'{*}'} — entire message metadata
    • $[key] — a specific message body field
    • ${'{key}'} — a specific metadata value
  • Supported response formats: TEXT, JSON, and JSON Schema (this guide uses JSON Schema).
  • A deduplication node with a 5-second interval is used to reduce AI token usage.
  1. Create a test device Equipment Sensor 1 with the EquipmentSensor profile.

  2. Copy the Check connectivity command from the device details.

    Your command will look something like this:

    Terminal window
    curl -v -X POST http://$THINGSBOARD_HOST_NAME/api/v1/$YOUR_DEVICE_ACCESS_TOKEN/telemetry \
    --header Content-Type:application/json \
    --data "{temperature:25}"

    Replace $THINGSBOARD_HOST_NAME with the host of your ThingsBoard instance, and $YOUR_DEVICE_ACCESS_TOKEN with your device’s access token.

  3. No alarm case — send normal readings.

    Terminal window
    curl -v -X POST http://$THINGSBOARD_HOST_NAME/api/v1/$YOUR_DEVICE_ACCESS_TOKEN/telemetry \
    --header Content-Type:application/json \
    --data '{"vibration":4.2,"temperature":70,"acousticDev":5}'

    No alarm is created because the values are within normal ranges.

  4. Bearing wear detection — send anomalous readings.

    Terminal window
    curl -v -X POST http://$THINGSBOARD_HOST_NAME/api/v1/$YOUR_DEVICE_ACCESS_TOKEN/telemetry \
    --header Content-Type:application/json \
    --data '{"vibration":8.2,"temperature":88,"acousticDev":5}'

    An alarm is created. Example AI output:

    {
    "anomaly": "Bearing Wear",
    "summary": "Vibration has reached 7.4 mm/s and temperature is at 86 °C accompanied by irregular acoustic patterns, indicating bearing wear. Recommend immediate bearing inspection and replacement to avoid catastrophic failure."
    }
  5. Misalignment detection — send a different anomaly pattern.

    Terminal window
    curl -v -X POST http://$THINGSBOARD_HOST_NAME/api/v1/$YOUR_DEVICE_ACCESS_TOKEN/telemetry \
    --header Content-Type:application/json \
    --data '{"vibration":32.2,"temperature":38,"acousticDev":5}'

    An alarm is created. Example AI output:

    {
    "anomaly": "Misalignment",
    "summary": "A sudden vibration spike to 32.2 mm/s without a corresponding temperature rise or acoustic deviation indicates likely misalignment in the drive train. Please perform an immediate shaft-and-coupling alignment check to prevent further mechanical damage."
    }

API costs are controlled by the provider’s API key and billing — ThingsBoard does not track usage or enforce limits internally. To manage costs effectively:

  • Deduplication — use the deduplication node to batch incoming messages (e.g., 5-second window) so the AI is called once per batch, not per telemetry message.
  • Early filters — skip the AI call entirely if all metrics are within normal bands. Add a script filter node before the AI request node.
  • Payload compacting — send statistics (min, mean, max, standard deviation, trend) instead of full arrays if the prompt allows.
  • Model selection — smaller models (e.g., gpt-4o-mini) are significantly cheaper per token than large models while still providing good anomaly classification.
ProblemSteps
No alarms created1. Verify raw device data appears in the Latest telemetry tab. 2. Enable and review calculated field debug events. 3. Enable and review the corresponding rule node debug events.
High costsIncrease the deduplication period, tune the prompt to use fewer tokens, or switch to a cheaper AI model.
  • Configure additional AI models to compare different providers.
  • Add notifications to alert operators when alarms are created.
  • Experiment with AI prompts and share your feedback with the community.