Guides

Explore NDU 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.

Prerequisites

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 NDU:

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:

image

image


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


image

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

Configuration:

image

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

image

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

image

Node C: Script Transformation

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

1
2
3
4
5
6
    var newMsg = {};
    if(msg.smoke == 'true'){
          newMsg.method = 'ON';  
    } 
    newMsg.params={};
    return {msg: newMsg, metadata: metadata, msgType: msgType};

image

Node D: RPC call request node

image

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
1
return msg.smoke== 'true';

image

Node F: Clear Alarm

image

Node G: Create alarm

image

Node H: Rule Chain

image

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

image



How to verify the Rule Chain and Post telemetry

1
2
3
curl -v -X POST -d '{"smoke":"true"}' http://smartapp.netcad.com/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"

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


imageimage


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