Skip to content

AN-26091401 Email Alarm Notification

This application note configures ThinkLink to send an alarm email when temperature reaches 30°C and a recovery notification when it falls below 30°C.

1. Workflow and prerequisites

text
Device uplink → Thing model parser → Trigger model → ALARM RPC
                                                       ├─ Raise or clear an alarm record
                                                       └─ Email group → SMTP → Recipient

The device must already report data, and its thing model must expose temperature as a number. This example uses temperature; replace it if your model uses another field such as TP. Prepare SMTP credentials, a test recipient, and permission to configure notification groups, devices, and models. A system administrator configures SMTP.

This example evaluates valid reported temperatures. It is not a device-offline rule.

2. Configure SMTP

Open System Platform → System Config → SMTP Configuration and enter the settings supplied by your email provider.

FieldValue
hostSMTP server address
portPort required by your provider
secureMatch the port and provider settings; typically enabled for 465. Port 587 typically uses STARTTLS with secure disabled for the initial connection
userSender account login
passPassword or SMTP app password, as required by the provider

Click Submit. SMTP is shared across the deployment. If the platform already has a working email service, ask its administrator to confirm availability. Keep sender credentials out of trigger scripts.

See System Config.

3. Create an email notification group

Open Alarm Management → Notification Groups → Add.

FieldExample or action
Id Nameops-email
Nameops-email
EnableOn
Notification methodemail
ContactsActual recipient email addresses; multiple recipients are supported
RemarkTemperature alarm email notifications

Use ops-email for both Id Name and Name, and use the same value in the script to avoid confusing the two fields.

New groups are disabled by default. Turn Enable on before saving. A successful save does not prove delivery; complete the alarm test below.

Notification groups

See Notification Groups.

4. Bind ALARM RPC to the device

Open Maintenance → Device Management → target device → Details → RPC → Add. Select the built-in ALARM RPC and save. Confirm its Method is lowercase alarm.

ALARM creates or clears an alarm and dispatches notifications to the selected groups. Its built-in script does not need editing.

5. Create and bind a trigger model

Under Model Management → Trigger Models, create a model named “Temperature alarm email notification”.

Paste the following code directly into the script editor. It is a complete function body; do not add a function trigger_script(...) wrapper.

javascript
const threshold = 30;
const notify = ["ops-email"];
const temperature = device?.telemetry_data?.[thingModelId]?.temperature;

// Missing, string, or non-finite values neither raise nor clear an alarm.
if (!Number.isFinite(temperature)) return null;

const isAlarm = temperature >= threshold;

return {
  delayms: 0,
  abort_previous_timer: true,
  should_dispatch: true,
  actions: [{
    method: "alarm",
    params: {
      _eui: device.eui,
      name: "high_temperature_email",
      action: isAlarm ? "new" : "clear",
      title: "[" + device.name + "] High temperature",
      level: "high",
      desc: isAlarm
        ? "Temperature is at or above " + threshold + " C. Check the device."
        : "Temperature has recovered below " + threshold + " C.",
      notify: notify
    }
  }]
};

Adapt these values to your device:

SettingChange
ThresholdReplace threshold = 30 with the required temperature
Temperature fieldReplace the final .temperature with the actual field, such as .TP
Notification groupsReplace ["ops-email"]; multiple groups can use ["ops-email", "duty-email"]
Alarm nameKeep high_temperature_email stable; raising and clearing must use the same name

Save and bind the trigger model to the target device. Confirm the corresponding thing model exposes the required temperature. Creating a model or setting its thing-model constraints does not bind it to a device.

The current ALARM RPC accepts a string array in params.notify and converts it to the underlying notice_groups field. Do not use the legacy group parameter or a string containing JSON.

should_dispatch: true allows unchanged data to call the RPC; ALARM still suppresses duplicate alarms. This flow does not require additional MQTT forwarding or a wireless downlink.

For a shared script across devices, threshold and groups can instead be read from device.server_attrs.alarm_temp and device.server_attrs.notify. Confirm the threshold is a number and groups are an actual string array before enabling that version. The initial example configures both at the top of the script.

See Trigger Model and RPC Model.

6. Verify alarm and recovery delivery

Use a test device and test recipients. Report the following temperatures in sequence, checking Alarm Management → Latest Alarms, Alarm Logs, and the inbox.

StepTemperatureExpected result
125°CWith no active alarm initially, no alarm or recovery notification
231°CAlarm created and alarm email received
335°CThe same alarm remains active without another notification
429°CAlarm cleared and recovery notification received
528°CRemains normal without another recovery notification
631°CA new alarm and a new alarm email

The example keeps the alarm name, title, level, and abnormal-state description stable so ALARM can recognize duplicates. Do not insert changing readings or timestamps into the title or description, as this can cause repeated notifications. Email appearance depends on the deployed version and recipient client.

Automatic recovery requires a later valid normal reading. Missing data, invalid numeric values, or a device that stops reporting do not clear the alarm. If readings repeatedly cross the threshold, design hysteresis or duration conditions for your application.

7. Troubleshooting

SymptomChecks
Temperature exceeds the threshold but no alarm appearsTelemetry field and number type, trigger binding, and ALARM RPC binding
Alarm exists but no email arrivesEnabled notification group, recipients, notify array, SMTP settings, and server connectivity
Email send errorExecution logs for authentication failure, timeout, or recipient error; provider sending limits
No reported error, but inbox is emptySpam folder, corporate quarantine, and provider delivery records
Similar alarms keep arrivingChanging title, description, or level; readings repeatedly crossing the threshold
Temperature recovers but alarm remains activeA new valid normal reading, a returned clear action, and an unchanged alarm name

Mark all as read changes only the log reading state. It does not prove device recovery, alarm clearance, or email delivery. See Alarm Management.