Notifications are very useful when developing applications that require someone’s attention if something happens to it.
In this tutorial, you will learn how to notify someone when the temperature of a device reaches warning levels.
Let’s simulate a machine that heats over time and if the temperature goes over 71 someone should take action.
Add a Device
First, create a custom https device called “Custom Device” that will simulate your real device. Click on the Devices tab in the menu.
Click “Add Device”
Next, select https devices and choose the “Custom https” device
Note: Notifications can be implemented for any device type. We are using a custom https device for simplicity because it initializes with no additional dashboards or payload parsers.
Name your device and save
Navigate to the device emulator and send the default package by clicking the arrow to send the payload. This will initialize the temperature variable for your device with a value of 71.
Add a Dashboard
Now, let’s create a dashboard to show the temperature of your device.
Go to dashboards, then press the addition symbol on the right.
Let’s name our device “Custom Device Dashboard” and then save.
With the dashboard and now displayed, let’s add a widget.
Choose the Display widget, “Custom Device” for the device, and “temperature” for the variable and then click save.
Create an Action
Now that we have our dashboard and widget set up, we will create an action. Click “Actions” in the menu.
Name the alert, choose “Variable” as the trigger, and select “Push notification to Myself” as the type of action.
After creating the action, select the device associated with the action and the variable that will trigger it. Also add a trigger unlock condition. Here we will set the unlock trigger to unlock when the temperature falls below 35. In a real world application, a device would repeatedly send data the device bucket. If there was no unlock condition, the user would receive multiple notifications for the same issue. By creating an unlock condition, we can prevent that from happening. Now, the action will not be triggered following the initial trigger unless the temperature falls below 35.
Note If the device receives values for the temperature variable that exceed 40, the action will be triggered. Because we initialized temperature at 71, sending that payload would trigger the action.
Now, re-send the default payload.
You should receive a notification. Access the given message for the action by clicking the notification icon.
Tips: watch the video for this here