NeuroAgent

Complete Guide: Telemetry Data in Alarm Notifications

Learn how to properly insert telemetry data values into ThingsBoard alarm notification emails. Discover the correct template syntax and rule chain configuration to display actual temperature readings instead of hard-coded values.

How to Insert Telemetry Data Values in Notification Center Alarm Emails

I have a Create Alarm node in my rule chain that triggers an alarm when the temperature exceeds a threshold. Currently, the temperature value is hard-coded to 24.9 degrees in the alarm node JavaScript script, but I need to include the actual telemetry temperature value in the alarm email notification.

In the notification template within the notification center, I’ve attempted to insert the telemetry temperature value using these syntax approaches:

  1. ${alarmDetails.temperature}
  2. ${alarm.details.temperature}

Unfortunately, neither of these syntax options worked correctly. How can I properly insert telemetry data values into the body of alarm notification emails?

NeuroAgent

To insert telemetry data values into alarm notification emails in ThingsBoard, you need to use the correct template syntax and ensure your alarm rule chain properly passes telemetry data. The syntax you tried (${alarmDetails.temperature} and ${alarm.details.temperature}) is close but not quite right - the correct approach involves using ${attributeName} syntax in your alarm details template and configuring your rule chain to include the telemetry data.


Contents

Understanding Alarm Notification Templates

ThingsBoard uses a template-based system for alarm notifications where you can dynamically insert various types of data. According to the official documentation, alarm templates support dynamic substitution of telemetry or attribute values using a specific syntax.

The alarm notification template system works by:

  1. Alarm Details Template: An optional template that allows you to include dynamic telemetry or attribute values
  2. Template Parameters: Built-in variables like recipientTitle, alarmType, severity, etc.
  3. Custom Variables: Values passed through your rule chain configuration

For temperature data specifically, you need to ensure the telemetry value is properly exposed in the alarm context before it can be used in notifications.

Proper Telemetry Data Syntax

The correct syntax for accessing telemetry data in alarm notifications is:

javascript
${attributeName}

Where attributeName is the name of the attribute or telemetry field you want to access. For temperature data specifically, you would use:

javascript
${temperature}

This syntax is different from what you attempted because:

  • ${alarmDetails.temperature} tries to access nested properties that don’t exist in the template context
  • ${alarm.details.temperature} follows an incorrect path structure
  • ${temperature} directly accesses the telemetry value that should be available in the template context

Important: The telemetry data name in the template must match exactly how it’s defined in your alarm rule chain and device telemetry.

Configuring Your Alarm Rule Chain

To make telemetry data available in alarm notifications, you need to configure your alarm rule chain properly. Here’s the step-by-step process:

Step 1: Create Alarm Node Configuration

In your Create Alarm node, instead of hard-coding the temperature value, you should:

  1. Use Transform Script Node: Add a Transform Script node before the Create Alarm node to process the telemetry data
  2. Pass Telemetry Data: Configure the alarm creation to include the actual telemetry value

Example Transform Script:

javascript
// Extract the actual temperature from incoming telemetry
var temperature = msg.temperature; // or msg.data.temperature depending on your message structure

// Create alarm details with the actual temperature value
var alarmDetails = {};
alarmDetails.temperature = temperature;
alarmDetails.timestamp = new Date().toISOString();

msg.alarmDetails = alarmDetails;
return [msg, metadata];

Step 2: Configure Create Alarm Node

In the Create Alarm node configuration:

  • Alarm Details: Enable this field and set it to reference your telemetry data
  • Use the alarm details in notifications: This makes the data available to templates

Step 3: Set Up Notification Template

In the Notification Center:

  1. Create or edit your alarm notification template
  2. Use the correct syntax ${temperature} where you want the temperature value to appear

Example Template Structure:

Subject: High Temperature Alert for ${deviceName}

Dear ${recipientTitle},

An alarm has been triggered for device ${deviceName} due to high temperature.

Temperature Reading: ${temperature}°C
Alarm Severity: ${severity}
Alarm Type: ${alarmType}
Timestamp: ${timestamp}

Please take immediate action to address this issue.

Regards,
ThingsBoard Monitoring System

Template Setup and Examples

Basic Temperature Notification Template

Here’s a complete example of a working alarm template for temperature notifications:

html
<html>
<body>
    <h2>Temperature Alarm Alert</h2>
    <p><strong>Device:</strong> ${deviceName}</p>
    <p><strong>Temperature:</strong> ${temperature}°C</p>
    <p><strong>Threshold:</strong> ${threshold}°C</p>
    <p><strong>Severity:</strong> ${severity}</p>
    <p><strong>Alarm Type:</strong> ${alarmType}</p>
    <p><strong>Timestamp:</strong> ${timestamp}</p>
    <p><strong>Location:</strong> ${location}</p>
</body>
</html>

Multiple Telemetry Values Template

If you need to include multiple telemetry values:

html
<html>
<body>
    <h2>Environmental Monitoring Alert</h2>
    <table border="1" cellpadding="5">
        <tr>
            <th>Metric</th>
            <th>Value</th>
            <th>Threshold</th>
        </tr>
        <tr>
            <td>Temperature</td>
            <td>${temperature}°C</td>
            <td>${tempThreshold}°C</td>
        </tr>
        <tr>
            <td>Humidity</td>
            <td>${humidity}%</td>
            <td>${humidityThreshold}%</td>
        </tr>
        <tr>
            <td>Pressure</td>
            <td>${pressure} hPa</td>
            <td>${pressureThreshold} hPa</td>
        </tr>
    </table>
</body>
</html>

Troubleshooting Common Issues

Issue 1: Telemetry Data Not Available

Symptom: Template placeholders like ${temperature} appear as literal text instead of showing values.

Solutions:

  1. Check Rule Chain Configuration: Ensure your Transform Script node properly passes telemetry data to the alarm details
  2. Verify Data Names: Make sure the field name in ${temperature} matches exactly with what’s defined in your alarm details
  3. Test with Debug Mode: Enable debug logging in ThingsBoard to see what data is actually available

Issue 2: Alarm Not Triggering with Telemetry

Symptom: Alarms don’t trigger when you expect them to based on telemetry data.

Solutions:

  1. Check Telemetry Format: Ensure your device is sending telemetry data in the expected format
  2. Verify Alarm Rules: Confirm your alarm condition logic is correct
  3. Test with Known Values: Use specific test values to verify the alarm triggering mechanism

Issue 3: Notification Not Sending

Symptom: Alarms trigger but notifications aren’t sent.

Solutions:

  1. Check Notification Configuration: Verify recipients, template selection, and escalation settings
  2. Test Email Settings: Ensure email server configuration is working correctly
  3. Check Notification Logs: Look for error messages in ThingsBoard logs

Best Practices

1. Use Consistent Naming Conventions

Always use consistent field names across your rule chain, device telemetry, and notification templates. This reduces confusion and debugging time.

2. Include Contextual Information

Don’t just include the raw telemetry value. Add context like:

  • Device name and location
  • Timestamp of the reading
  • Threshold values that were exceeded
  • Severity levels

3. Handle Multiple Scenarios

Your templates should handle various alarm scenarios:

  • Different severity levels
  • Multiple telemetry thresholds
  • Different device types

4. Test Templates Before Deployment

Always test your notification templates with sample data before deploying them to production. Use the ThingsBoard UI to preview how templates will render with actual alarm data.

5. Use HTML for Rich Formatting

For professional-looking notifications, use HTML formatting in your templates to create structured, readable emails with proper styling.


Conclusion

To successfully insert telemetry data values into alarm notification emails in ThingsBoard:

  1. Use the correct syntax: ${attributeName} (not the nested syntax you tried)
  2. Configure your rule chain properly: Use Transform Script nodes to pass telemetry data to alarm details
  3. Test thoroughly: Verify both alarm triggering and notification delivery
  4. Follow best practices: Use consistent naming and include contextual information

The key insight is that telemetry data must be explicitly passed through your rule chain and made available in the alarm details context before it can be referenced in notification templates. Once you have the proper data flow established, using ${temperature} (or whatever your telemetry field is named) will correctly display the actual temperature values in your alarm emails.

Sources

  1. ThingsBoard Documentation - Notification center
  2. ThingsBoard Documentation - Working with alarms
  3. ThingsBoard Documentation - Rule Engine 2.0 tutorials
  4. Stack Overflow - How to send telemetry data in notification center alarm email
  5. ThingsBoard Documentation - Device profiles