Explore ThingsBoard tutorials and guides.

Check Relation between Entities

The purpose of this tutorial is to show how the Check Relation node can be used to check the relation between Entities.

Use case

Let’s assume the following use case:

However, there are different ways for the realization of this case, for example, it can be implemented using the Switch node that routes incoming Message to one or multiple output chains.
For more information about how to use the Switch node, please check the link to The article of Switch Node in the See Also section.


You need to read the following guides before you start this tutorial:

Adding the devices and creating the relation between them

Add two Device entity in ThingsBoard:

Create a relation of the type Uses:

The following screenshots show how to do this:

image image

Message flow

In this section, we explain the purpose of each node in this tutorial:

Configure Rule Chains

In this tutorial, we modified our Root Rule Chain and also created Rule Chain Related Fire Alarm System

The following screenshots show how the above Rule Chains should look like:



Download the attached json file for the Root Rule Chain. Don’t forget to mark this rule chain as root.


Also, you need to create Related Fire Alarm System Rule Chain or you can download the attached json file for this Chain and import it.

The following section shows you how to create it.

Go to Rule Chains -> Add new Rule Chain



New Rule Chain is created. Press Edit button and configure Chain.

Adding the required nodes

In this rule chain, you will create 4 nodes as it will be explained in the following sections:

Node A: Check Relation
FieldInput Data
Name Check Relation
Direction To
Type Device
Device Fire Alarm System
Relation type Uses


Node B: Change Orignator
FieldInput Data
Name Change Originator
Originator source Related
Direction From
Max relationship level 1
Relation type Uses
Entity type Device


Node C: Script Transformation

This node will transform an original message into RPC request message.

    var newMsg = {};
    if(msg.smoke == 'true'){
          newMsg.method = 'ON';  
    return {msg: newMsg, metadata: metadata, msgType: msgType};


Node D: RPC call request node


This Rule chain is ready and we should save it.

Modify Root Rule Chain

The initial Rule Chain has been modified by adding the following nodes:

Node E: Filter Script
return msg.smoke== 'true';


Node F: Clear Alarm


Node G: Create alarm


Node H: Rule Chain


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


How to verify the Rule Chain and Post telemetry

curl -v -X POST -d '{"smoke":"true"}'$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

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


Also, you can:

Please refer to the third and fourth links under the See Also section to see how to do this.

See Also

Next steps