Let’s assume your device is using DHT22 sensor to collect and push temperature readings to ThingsBoard. DHT22 sensor is good for -40 to 80°C temperature readings. We want generate Alarms if temperature is out of good range.
In this tutorial we will configure ThingsBoard Rule Engine to
We assume you have completed the following guides and reviewed the articles listed below:
Add Device entity in ThingsBoard. Its name is Thermostat Home and its type is Thermostat.
In this section, we explain the purpose of each node in this tutorial:
In this tutorial, we modified our Root Rule Chain and also created Rule Chain Create & Clear Alarms
The following screenshots show how the above Rule Chains should look like:
Download the attached json file for the Create & Clear Alarms rule chain.
Create Node D as shown on the image above in the root rule chain to forward telemetry to the imported rule chain.
The following section shows you how to create this rule chain from scratch.
Go to Rule Chains -> Add new Rule Chain
New Rule Chain is created. Press Edit button and configure Chain.
In this rule chain, you will create 3 nodes as it will be explained in the following sections:
If the temperature is in the expected interval the script will return False, otherwise True will be returned.
Add the Create alarm node and connect it to the Filter Script node with a relation type True.
This node loads the latest Alarm with configured Alarm Type for Message Originator, namely Thermostat Home
if the published temperature is not at expected range (filter script node returns True).
Enter the Name field as Create alarm and the Alarm type as Critical Temperature.
Add the Clear Alarm node and connect it to the Filter Script node with a relation type False.
This node loads the latest Alarm with configured Alarm Type for Message Originator Thermostat Home
and Clears alarm if it exists in case if the published temperature is in expected range (script node returns False).
Enter the Name field as Clear Alarm and the Alarm type as Critical Temperature.
The following screenshot shows the initial Root Rule Chain.
The initial Rule Chain has been modified by adding the following node:
Add the Rule Chain node and connect it to the Filter Script node with a relation type True.
This node forwards incoming Message to specified Rule Chain Create & Clear Alarms.
Enter the Name field as Create & Clear Alarms.
The following screenshot shows how the final Root Rule Chain should look like:
For posting device telemetry we will use the Rest APIs, Telemetry upload APIs. For this we will need to copy device access token from the device Thermometer.
Let’s pushed debug mode button in Clear Alarm and Create Alarm node to verify the results.
sent temperature = 99. Alarm should be created:
Lets post temperature = 180. Alarm should be updated:
Lets post temperature = 30. Alarm should be cleared:
Also, you can:
configure Alarm Details function in the Create and Clear Alarm nodes.
configure the Dashboard by adding an alarm widget to visualize the alarms.
define an additional logic for alarm processing, for example, sending an email.
Please refer to the links from the second to the fourth under the See Also section to see how to do this.
Validate incoming telemetry tutorial - for more information about how to validate an incoming telemetry using the Script Filter node.
Create & Clear Alarms: alarm details: guide - to learn how to configure Alarm Details function in Alarm nodes.
Create & Clear Alarms: configure dashboard guide - to learn how to add an Alarm widget to the dashboard.
Send Email tutorial.
Getting started guides - These guides provide quick overview of main ThingsBoard features. Designed to be completed in 15-30 minutes.
Installation guides - Learn how to setup ThingsBoard on various available operating systems.
Connect your device - Learn how to connect devices based on your connectivity technology or solution.
Data visualization - These guides contain instructions how to configure complex ThingsBoard dashboards.
IoT Data analytics - Learn how to use rule engine to perform basic analytics tasks.
Hardware samples - Learn how to connect various hardware platforms to ThingsBoard.
Advanced features - Learn about advanced ThingsBoard features.
Contribution and Development - Learn about contribution and development in ThingsBoard.