This tutorial will show how to dynamically add & remove device from the device group based on incoming data from device.
- Use case
- Prerequisites
- Model definition
- Message Flow
- Configuring the Rule Chain
- Validating the flow
- Next steps
Use case
Let’s assume your device is reporting temperature readings to ThingsBoard and you would like to visualize devices that have reported temperature > 50°C.
In this tutorial we will configure ThingsBoard Rule Engine to automatically update “High temperature devices” group members based on incoming temperature readings from the device. You can use this tutorial as a basis for much more complex filtering.
Prerequisites
We assume you have completed the following guides and reviewed the articles listed below:
- Getting Started guide.
- Rule Engine Overview.
Model definition
We will operate with Temperature sensor device that has name “Sensor A” and type “DHT22”.
Message Flow
In this section, we explain the purpose of each node in this tutorial.
Root rule chain
-
Node A: Rule Chain node
- We modify the default root rule chain to forward all telemetry to new “Add device to group” rule chain
New “Add device to group” rule chain
-
Node B: Script filter node
- Checks that the incoming message from device contains temperature readings
- If message from device contains temperature readings it is forwarded to Node C
-
Node C: Script filter node
- Checks that the incoming message temperature is > 50°C
- If temperature > 50°C message is forwarded to Node D
- If temperature <= 50°C message is forwarded to Node E
-
Node D: Add to Group node
- Adds device to the group
- Constructs group name by substituting deviceType metadata value
- Automatically creates device group if needed
-
Node E: Remove from Group node
- Removes device from the group
- Constructs group name by substituting deviceType metadata value
Configuring the Rule Chain
Download and import attached json file as a new “Add device to group” rule chain. Please note that all nodes have debug enabled. This affects performance. Create Node A as shown on the image above in the root rule chain to forward telemetry to new rule chain.
Validating the flow
Publish temperature readings on behalf of the new device and observe new group automatically created:
Next steps
-
入门指南 - 快速学习ThingsBoard相关功能。
-
安装指南 - 学习如何在各种操作系统上安装ThingsBoard。
-
连接设备 - 学习如何根据你的连接方式或解决方案连接设备。
-
可 视 化 - 学习如何配置复杂的ThingsBoard仪表板说明。
-
数据分析 - 学习如何使用规则引擎执行基本的分析任务。
-
硬件样品 - 学习如何将各种硬件平台连接到ThingsBoard。
-
高级功能 - 学习高级ThingsBoard功能。
-
开发指南 - 学习ThingsBoard中的贡献和开发。