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 95 someone should take action.

First, create a device called "machine 1" that will simulate your real machine, then, let's create a dashboard to show the temperature of your device.
Go to dashboards, then add a new one. Let's call it "Machinery".

For the notification to point to a dashboard, you need the dashboard's id, to do this, click on the gear icon on the top right, then go to the section "More", there you will find the Dashboard id, copy it and go back to the dashboard.

Add a widget to show the temperature, select "Gauge".

On variable, select "Temperature" from your device "Machine 1" and save.

You should have a widget like the one in the image below.

Now, go to analysis on the left menu, and add a new one.

Go to the section "Examples", download the "Send Notification" example and extract it.

Now go back to the section "General Information" and fill up the form with the following information:

Name: Notification
Time interval: Timer disabled
Run this script from: Tago
Script language: Node
File name: Upload the file "index.js" that you've just downloaded and extracted

Now go to the section "Environment variables" and add the following parameters:

title: The title of your notification
message: The message of your notification
dashboard_id: The id that you have just copied from your dashboard

Then click on save.

Now you will need to set up an action to trigger the analysis when the temperature reaches a certain value.
Go to action and create a new one. Type the name of the action, then on action to be taken, choose "Run analysis", then, select the analysis "Notification" that you have just created.

Go to the section Trigger.
On "Set trigger configuration", select the variable temperature, on condition, select greater than, on type, select number on value type the 95.
By doing this, every time the temperature goes over 95, this action will run the notification analysis.

Now, you should set a reset trigger.
Let the option "Lock trigger" set to yes.
By doing this, every time the analysis is ran, the trigger will lock, so you don't receive multiple notifications after the temperature goes higher than 95.

On Reset Trigger configuration, select the variable temperature, the condition set less than, on type, select number, and on value, type 95 and save.
By doing this, if the trigger is locked, when the temperature goes under 95 again, it will release the trigger, so if the temperature goes over 95 you will be notified again.

Now to simulate sending data to the dashboard, let's add an input to it.
Go to the dashboard, add a new widget, select input, on variable select temperature and save.

Now type the temperature and send, if you type a number greater than 95, everyone that has this dashboard shared with, will receive a notification with the link to the dashboard.

The notification icon on the top right corner will show you the number of available notifications.
If you click on it, it will show you the notifications.