Smart home on wheels ... Alice. Part 2. ZIGBEE

Continuation of the epic with voice control


In the previous part, through Alice, the voice was controlled by MiLight controllers. But such controllers are not at all in every house, which greatly limits our capabilities. Therefore, I set out to expand the voice control to ordinary lamps, lamps, chandeliers, and so on, but with a minimal alteration of the standard lighting system. All that will be needed for such a system is the replacement of conventional switches with smart switches operating according to the ZigBee protocol and the installation of a USB ZigBee coordinator CC2531. Naturally, from the previous article, we already have a smart Yandex column and a customized mess.

The cost of CC2531 cost 250 rubles, the programmer for it CC-Debugger Texas Instrument - 500 rubles. The Livolo VL-C701Z-11 touch smart switches were the most expensive - about 2000 rubles apiece, and a little later the Aqara Wall Switch Zigbee button switch was also added around 2000.

Initially, I planned to control the switches through the proprietary ZigBee gateway router Livolo C700ZW-12, connect it to the open hub and steer using Alice through yandex2mqtt. I connected the glands to electricity, set up the application from Livolo on the phone. I saw the gateway switches, connected, and everything worked perfectly from the phone. But the open hub with the router could not be merged due to the lack of the necessary functionality in the open hub.

I had to abandon the gateway and merge the switches directly with the CC2531 dongle. And here the zigbee2mqtt project from the friend Koenkk helped with this . As a result, we managed to connect the ZigBee coordinator with smart switches, first check their operation through queries in the mqtt topic for analysis, and then configure the control using Alice.

So, how did the setup

go : 1. Flash the CC2531 sniffer with the coordinator’s firmware and plug it into the usb port. In order to avoid messages about a lack of power, it’s better to connect at least 2A to a 5V power supply. We check that the stick in the system is correctly defined: ls -l / dev / serial / by-id will show something like usb-Texas_Instruments_TI_CC2531_USB_CDC ___ 0X00124B0458ED3DDF-if00 -> ../../ttyACM0. The presence of the last piece of output "-> ../../ttyACM0" is very important if that. A stick can decide without this part and nothing will work. Flashing the stick helped me with such a problem.

2. Install Zigbee2mqtt , but do not start.

3. It is important to configure /opt/zigbee2mqtt/data/configuration.yaml correctly. The fact is that Livolo smart switches operate on channel 26, so this channel must be explicitly set in the file. And it is also important to pay attention to the number of spaces at the beginning of the lines of the file. To check the syntax of the configuration file, you can use the YAML validator .

4. After the configuration file is registered correctly and the dongle is stuck, run zigbee2mqtt. Then we stomp to the switches, start pairing and look at the console output. There will be a line of data exchange, mutual rassharkivaniya between devices and finally something like this: MQTT publish: topic 'zigbee2mqtt/0x001*********a8c9', payload '{"state_left":"OFF","state_right":"OFF","linkquality":60}'. This means that the switch is connected and sent its status. If you run a couple more consoles, then you can control the light through the mqtt-topic: turn off- mosquitto_pub -d -h localhost -t zigbee2mqtt/0x001*********a8c9/left/set -m OFF -u a**** -P *****and turn - mosquitto_pub -d -h localhost -t zigbee2mqtt/0x001*********a8c9/left/set -m ON -u a**** -P *****and you can also check the team in Topeka mosquitto_sub -d -h localhost -t zigbee2mqtt/0x001*********a8c9/left/set -u a**** -P *****. By the way, for Livolo and Aqara, topics differ not only in identifiers 0x0 ..., but also in structure. The structure of topics for supported devices can be found here .

5. After we have verified that we can manage devices through mqtt, we will pair everything with Yandex. Some nuance has appeared here. Commands for controlling devices through zigbee2mqtt came to topics in the form of ON / OFF, and yandex2mqtt as it turned out gives 1/0. The solution to this problem was to edit the /mnt/data/root/yandex2mqtt/device.js file in yandex2mqtt. Do you need to replace int = val in the switch in the “on” case? to 'on': 'off' instead of '1': '0'. Naturally, the switching commands had to be corrected in the open hub in the corresponding topics. Without this, the light on Milight would cease to work. And the most interesting thing was revealed right there - since yandex2mqtt and zigbee2mqtt publish everything on the local mqtt server, it seems that zenbee devices do not need an open hub to manage devices.The bundle works directly - yandex (Alice) -yandex2mqtt-mqtt-zigbee2mqtt-device zigbee. Even unexpectedly somehow. But let's continue. We’ll file the device control topic in the configuration file /mnt/data/root/yandex2mqtt/config.js into a new virtual device, update the list of devices in the Yandex dialog system and you can kick Alice to turn on the light.

6. It was also possible to connect a pair of Xiaomi sensors, a leakage sensor and a temperature / humidity / pressure sensor to the system. They work on 2032 batteries. Naturally, they are not controlled, but they simply periodically drop information such #033[32mzigbee2mqtt:info #033[39m 2020-05-04 21:12:21: MQTT publish: topic 'zigbee2mqtt/0x0015************', payload '{"battery":91,"voltage":2985,"temperature":26.2,"humidity":28.65,"pressure":1006.9,"linkquality":52}' - # #033[32mzigbee2mqtt:info #033[39m 2020-05-04 21:21:07: MQTT publish: topic 'zigbee2mqtt/0x001************7', payload '{"battery":100,"voltage":3025,"linkquality":0,"water_leak":true}' as a leak sensor in a glass of water into topics . So far, there is no particular benefit, but if all this is otparsit and do something reactive such as sending SMS or digits to some web muzzle, then it will be very good.

And a little video:



All Articles