Star

Guides

Explore ThingsBoard tutorials and guides.

Create Alarm when the Device is offline

This tutorial is to show you how to create an alarm when the device is offline for a certain period of time using RuleEngine.

Use Case

Let’s assume the following use case:

Therefore, in this case, you will need to configure ThingsBoard Rule Engine to:

Background

The ThingsBoard Device State service is responsible for monitoring the device connectivity state and triggering the device connectivity events that are pushed to Rule Engine.

ThingsBoard supports four types of events:

Event TypeDescription
Connect triggered when the device connects to ThingsBoard.
Disconnect triggered when the device disconnects from ThingsBoard.
Activity triggered when the device pushes a telemetry, an attribute update or RPC command.
Inactivity triggered when the device is inactive for a certain period of time.

This tutorial will explain in details the device Inactivity event and it will show you how to:



Adding the Device

image



Configuring the Device

image



Configuring the Rule Chain

The following screenshot shows the initial Root Rule Chain. Please, note that the irrelevant rule nodes have been removed from the Root Rule Chain.

image

The default rule chain has been modified by adding the following two action nodes:

The following screenshot shows how the final Rule Chain should look like:

image

Also, you can create the new Rule Chain from scratch. The following section shows you how to create it.

Creating a new Rule Chain (Tutorial of Inactivity Event)

image image

Adding the required nodes

In this tutorial, you will create 5 nodes as it will be explained in the following sections:

Message Type Switch node

Add the Message Type Switch node and connect it to the Input node.

This node will route the incoming messages according to the message type, namely:

Enter the Name field as Message Type Switch, then click the ADD button.

image

Save Timeseries node

Add the Save TimeSeries node and connect it to the Message Type Switch node with a relationship type Post telemetry.

This node will store the TimeSeries data from the incoming Message payload into the database and link it to the Device that is identified by the Message Originator.

Enter the Name field as Save Time Series.

image

Save Server Attributes node

Add the Save Attributes node and connect it to the Message Type Switch node with a relationship type Post attributes.

This node will store attributes from the incoming Message payload into the database and link them to the Entity that is identified by the Message Originator.

Enter the Name field as Save Server Attributes.

image

Create Inactivity alarm node

Add the Create alarm node and connect it to the Message Type Switch node with a relationship type Inactivity Event.

This node tries to load the latest Alarm with the configured Alarm Type for the Message Originator. If Uncleared Alarm exists, then this Alarm will be updated, otherwise, a new Alarm will be created.

image

Clear Inactivity alarm node

Add the Clear alarm node and connect it to the Message Type Switch node with a relationship type Activity Event.

This Node loads the latest Alarm with the configured Alarm Type for the Message Originator and Clear the Alarm if it exist.

image


This Rule chain is now ready and you need to save it.



How to verify the Rule Chain and Post telemetry

image

Try to post temperature = 20. Alarm should be created a minute after the telemetry post:

curl -v -X POST -d '{"temperature":20}' http://localhost:8080/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

***you need to replace $ACCESS_TOKEN with the actual device token**

image

image


Also, you can:

Please refer to the first two links under the See Also section to see how to do this.



See Also

Next steps