Skip to content
Stand with Ukraine flag

Send Slack Message on Alarm

Configure ThingsBoard to automatically send a Slack message when an alarm is created. This guide extends the Create and Clear Alarms recipe by using the Notification Center to deliver alarm-based Slack notifications.

Assume your refrigeration equipment has a temperature sensor that periodically publishes telemetry to ThingsBoard. The normal operating range is 2 °C5 °C. When a reading goes outside this range:

  • An alarm is created by the alarm rules.
  • A Slack message is sent to the responsible user.

Before proceeding:

  • Complete the Create and Clear Alarms recipe — the alarm rules configured there are required for this guide.
  • Configure Slack settings in ThingsBoard with a valid Bot User OAuth Token.

Review the following documentation for background:

The Notification Center delivers notifications to users. It consists of three components:

  • Recipients — define who receives notifications.
  • Templates — define the notification content and delivery method.
  • Rules — define the conditions under which notifications are sent.

Create a recipient that targets a specific Slack user via direct message.

  1. Navigate to Notification Center ⇾ Recipients.
  2. Click Add recipients (+) in the top-right corner.
  3. Configure the recipient:
    • Name: Direct message to Slack
    • Type: Slack
    • Slack channel type: Direct message
    • Conversation: enter the target Slack user’s name
  4. Click Add.

Create a template that defines the Slack message body using alarm variables.

  1. Navigate to Notification Center ⇾ Templates.
  2. Click Add template (+) in the top-right corner.
  3. Setup — configure the template:
    • Name: Alarm notification to Slack
    • Type: Alarm
    • Delivery methods: toggle Slack on
  4. Click Next.
  5. Compose — expand the Slack section and enter the message: A ${alarmType} has been detected on the ${alarmOriginatorName} device: ${details.data} °C.
  6. Click Add.

Template variables used:

  • ${alarmType} — the alarm type name (e.g. High temperature).
  • ${alarmOriginatorName} — the name of the device that triggered the alarm.
  • ${details.data} — the reported telemetry value, populated by the alarm rule.

Create a rule that links the alarm trigger to the template and recipient.

  1. Navigate to Notification Center ⇾ Rules.
  2. Click Add rule (+) in the top-right corner.
  3. Basic settings — configure the rule:
    • Rule name: New alarm to Slack
    • Trigger: Alarm
    • Template: Alarm notification to Slack
    • Escalation chain ⇾ First recipient: Direct message to Slack
  4. Click Next.
  5. Alarm trigger settings — configure the filter:
    • Alarm type list: Any type
    • Alarm severity list: Any severity
    • Notify on: Alarm created
  6. Click Add.

Publish a temperature value that triggers the alarm (above 5 °C).
Use the Check Connectivity feature or the command below:

Terminal window
curl -v -X POST \
--header "Content-Type: application/json" \
--data '{"temperature": 25}' \
http://thingsboard.cloud/api/v1/$ACCESS_TOKEN/telemetry

A new alarm is created and the Slack message is sent to the configured recipient. The message body is populated from the template variables.