Multi-device interaction in a single scenario in RIC platform
In this case, we will connect a Zigbee button to the RIC Zigbee platform, a Zigbee temperature and humidity sensor and a Node MCU board with an LED connected to it. By pressing the button, we will control the LED on/off.
We will show how to link devices connected to each other only through RIC in one scenario.
You can study the variety of Zigbee devices by clicking on this link.
In order to get data from devices, we will use the project Zigbee2mqtt.
YouTube link with this use case.
Creating a Model and Adding an Object
You can import the finished model of our Zigbee device in RIC:
This model already has temperature and humidity parameters, information about the number of clicks on the button.
Next, we create an object with this model.
For more information about creating a model and adding an object, see this article.
Zigbee Device Connection
- We connect one of the Zigbee-adapters to the computer, which will act as a coordinator.
- Download the project code Zigbee2mqtt.
- We set project dependencies with the npm install command in the project folder.
- Go to the configuration file editor (data/configuration.yaml) and specify server (mqtt ://dev.rightech.io) and client_id (object ID – mqtt-lesson_zigbee).
5. Run the program with the command node index.js.
6. Implement Pairing devices. How to do this is written on the page of the device itself.
We see the appearance of information about the temperature, humidity and clicks of the button.
The coordinator configuration and device connection were successful, the data comes to the platform, but they are not yet sorted according to the model.
This is because the model has not yet spelled out the correct topics in the parameter sources.
Note that the logs in the terminal show the top and the data itself:
- the topic consists of the base_topic we specified in the configuration file and the Zigbee device IEEE addr – the unique identifier of the Zigbee device;
- data is presented in the form of information in JSON format.
Return to the “Models” tab, enter the model, and edit the topic of nodes of type “Object”. These are the Temperature Sensor and Button nodes. Using them, the information that comes in JSON format is posted according to the model.
We edit the topics in the model:
- by temperature and humidity sensor
- by the button
For model changes to take effect, in the “Objects” section, select our object and, from the “Commands” tab, send the “Update model” command. The model is also automatically updated when the object is connected to the platform.
Creating an Automaton
Now we create a scenario in which, using a single click on the Zigbee button, the light will turn on, and the double click – turn off. Recall that the LED in turn is connected to another object and has a different model, so two models will appear in the automation (the model for the button, and the model for the LED).
Now, when you select a transition event or an action in a state, there is a choice of which model to perform it on.
General view of the automaton:
Add the required objects in the “Objects” tab.
Select the objects and click the “Start” button.
We go to any of the objects and see running automation on the “Services” tab.
We check that when you press the button once, the light turns off, and when you press twice, it turns off.
Try creating your IoT project with Rightech IoT Cloud now 🙂
And if you have any questions, welcome to our chat of like-minded fellas: