MQTT Rule: SMS Alerts using Plivo
Overview
The MQTT trigger allows you to create rules that activate based on device data sent through MQTT. This guide will walk you through setting up an MQTT trigger for monitoring device temperature and sending an SMS alert when it exceeds a threshold.
Setting Up the MQTT Trigger
Step 1: Select Trigger Type
In the rule engine interface, select "MQTT" as your trigger type, and click on "Edit" once you create the rule.
Step 2: Configure MQTT Settings
Configure the MQTT trigger with the following options:
Data Kind: Select "Device Data"
Devices: Select the specific devices you want to monitor (Note: leaving this empty will trigger this rule for all the devices in your project having the selected data point definition)
\
Step 3: Select Data Point
Choose the data point corresponding to the temperature sensor. This will make all fields from the selected data point definition available as inputs in your rule. (Along with the mqtt_device_id
and mqtt_device_name
to identify which one of your devices triggered this rule)
Creating the Rule Logic
Step 4: Set Up Condition
Add a condition to check if the temperature exceeds 28°C:
temperatureValue > 28;
Note: To reference a variable in the conditions, you do not need to enclose it in double curlies ({{ }}
)
Step 5: Configure Action
In the true sequence (when condition is met), add an HTTP action to call an external SMS service (e.g., Plivo). Pass in your phone number and a text template (defined by enclosing your message in $Text(…)
. We'll use this template: $Text(The surrounding temperature of your device {{mqtt_device_name}} is too hot! Please go and have a look!)
Note: To know more about creating HTTP actions, check out the HTTP Action guide!
How It Works
- When a device sends temperature data via MQTT, it triggers the rule.
- The rule checks if the temperature exceeds 28°C.
- If true, it sends an HTTP request to the SMS service to alert about high temperature.
Accessing Data Fields
- All fields from the selected data point are available as top-level inputs in your rule.
- Reference these fields directly in conditions and actions using their names (e.g.,
temperature
,humidity
) - To reference these fields anywhere else, you need to enclose them in double-curly braces (e.g.,
{{temperature}}
,{{humidity}}
)
Best Practices
- Ensure your devices are configured to send data to the correct MQTT topics.
- Test your rule with various temperature values to confirm it triggers correctly.
- Monitor your SMS service usage to avoid unexpected costs.
Troubleshooting
- If the rule isn't triggering, verify the MQTT connection and topic subscriptions.
- Check that the data point fields match what your devices are sending.
By following this guide, you can create powerful, automated responses to your IoT device data using MQTT triggers in the rule engine.