Sending Email & Text Alerts using Azure Logic Apps
These instructions show how to use Logic Apps to call the IoT Ensemble warm query every 12 hours and check if the Temperature of any of the results is greater than 90. If so, it sends an email alert. Before we get started, here's an overview of the entire Logic App with the steps collapsed.
Step 1: HTTP
For the first step of the Logic App, search for 'HTTP'.
Configure the HTTP trigger with the following settings from your IoT Ensemble account. This example is using the Warm Query.
- How often do you want to check for items?:
Use your primaryKey or secondaryKey from the IoT Ensemble API Keys for the lcu-subscription-key value. For example:
In the HTTP trigger above, use the 'How often do you want to check for items' fields to control how often the HTTP trigger calls the IoT Ensemble Warm Query for new data.
Step 2: Compose
For the next step of the Logic App, search for 'Compose'.
For the Compose step we need to list an example JSON payload the Logic App will receive from the HTTP trigger. For the IoT Ensemble Warm Query, you can use the following:
Copy/paste the JSON payload above into the Compose input:
Step 3: Parse JSON
For the next step of the Logic App, search for 'Parse JSON'.
For the Parse JSON content, use the dynamic
Outputs object from the previous Compose step. For the Schema, click the 'Use sample payload to generate schema' link and it will automatically generate the schema based on the
Outputs object. Refer to the screenshot below:
Step 4: Initialize Variable
For the next step of the Logic App, search for 'Initialize Variable'. We want to initialize a variable that we can set to True when a condition is met.
In this example, I'm checking if the 'Temperature is greater than 90'. For the variable name I'm going to use 'TempOver'. The Type is a
Boolean and the default value is
Step 5: For Each
For the next step of the Logic App, search for 'For Each'. Select the 'Control' option.
Within the Controls, select the 'For each' action.
For the output, select the dynamic
Payloads object from the previous Parse JSON step.
Click the 'Add an Action' button to add an action to the For Each. Search for 'Condition'.
For this condition, I'm checking if the
Temperature is greater than 90 AND if the
DeviceID is equal to Emulated-1.
If the condition is True, I added a 'Set Variable' action and selected the
TempOver variable I setup earlier. For the value, I'm setting it to True, to indicate the condition was met. For this example I'm not doing anything when the condition is False.
Step 6: Check Temp Condition
For the next step of the Logic App, we want to add another 'Condition'.
For this condition, we want to check if the
TempOver variable is equal to True.
Step 7: Send Email
When the 'TempOver variable is equal to True' condition is met, we can add an action to send an email alert. Click the 'Add an action' button and search for 'Send Email'. Select the 'Office 365 Outlook' option.
Fill in the email Body, Subject, and To fields based on your needs.
Step 8: Email to Text (SMS)
Texting via email is easy. Type in the recipient's mobile number in front of the "@" sign based on the SMS Gateway. For example, if your recipient’s mobile number is 1-123-456-7891 and their carrier is AT&T, you would type in the following address in the "send to" box:
firstname.lastname@example.org. Almost every single carrier has its own address for this specific purpose, here is a list of all the major carriers’ email to SMS gateways:
- T-Mobile – email@example.com
- Virgin Mobile – firstname.lastname@example.org
- AT&T – email@example.com
- Sprint – firstname.lastname@example.org
- Verizon – email@example.com
- Tracfone – firstname.lastname@example.org
- Ting – email@example.com
- Boost Mobile – firstname.lastname@example.org
- U.S. Cellular – email@example.com
- Metro PCS – firstname.lastname@example.org
Overview of Steps
Here's an overview of the entire Logic App with the steps collapsed. The Logic App calls the IoT Ensemble warm query every 12 hours and checks if the Temperature of any of the results is greater than 90. If so, it sends an email alert.