zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

硬件准备

小米蓝牙插座,型号: Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

zigbee设备,型号: CC2531设备

参考链接:
https://github.com/Koenkk/zigbee2mqtt
https://www.zigbee2mqtt.io/

https://www.92ez.com/?action=show&id=23390

zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备_第1张图片

CC2531设备识别并安装pyCCSniffer

pyCCSniffer工具是使用德州仪器的CC2531 USB加密狗来嗅探数据包,剖析它们并将它们打印到控制台。

查看usb设备, 插入CC2531设备后
lsusb
显示CC2531设备
Bus 001 Device 003: ID 0451:16ae Texas Instruments, Inc. 

cd /opt

git clone https://github.com/andrewdodd/pyCCSniffer.git
cd pyCCSniffer
python pyCCSniffer.py
apt install python-pip 
pip install future   
pip install pyusb 安装失败,升级pip就成功了: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4hIAE4/pyusb/
pip install libusb
pip install --upgrade pip
pip install pyusb

成功显示
python pyCCSniffer.py
CC2531 USB Dongle <Channel: 11>
-------------------------------
Commands:
c: Print current RF Channel
h,?: Print this message
[11,26]: Change RF channel
s: Start/stop the packet capture
d: Toggle frame dissector
a*: Set an annotation (write "a" to remove it)
p: Print all capture packets
q: Quit

python pyCCSniffer.py -L /root/zigbee.log -D INFO
输入s


没有这个目录
ls -l /dev/ttyACM0

ls -l /dev/bus/usb/001/003 拔掉之后就没有了
ls -l /dev/bus/usb/001/005

lsusb  换了一个CC2531设备后
Bus 001 Device 004: ID 0451:16a8 Texas Instruments, Inc. 

就有这个目录了
ls -l /dev/ttyACM0

ls -l /dev/bus/usb/001/004

安装Zigbee2MQTT

安装Zigbee2MQTT
sudo curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

sudo apt-get install -y nodejs git make g++ gcc

node --version
npm --version

sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt

cd /opt/zigbee2mqtt
npm ci

vim /opt/zigbee2mqtt/data/configuration.yaml

advanced:
    network_key: GENERATE

npm install
启动
npm start


> [email protected] start /opt/zigbee2mqtt
> node index.js

                Zigbee2MQTT requires node version ^10 || ^12 || ^14 || ^15 || ^16, you are running v8.10.0!

Zigbee2MQTT:info  2022-09-30 14:38:47: Logging to console and directory: '/opt/zigbee2mqtt/data/log/2021-09-30.14-38-45' filename: log.txt
Zigbee2MQTT:info  2022-09-30 14:38:47: Starting Zigbee2MQTT version 1.21.1 (commit #4a51e0c0)
Zigbee2MQTT:info  2022-09-30 14:38:47: Starting zigbee-herdsman (0.13.138)
Zigbee2MQTT:info  2022-09-30 14:38:51: zigbee-herdsman started (resumed)
Zigbee2MQTT:info  2022-09-30 14:38:51: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20190608,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info  2022-09-30 14:38:51: Currently 0 devices are joined:
Zigbee2MQTT:warn  2022-09-30 14:38:51: `permit_join` set to  `true` in configuration.yaml.
Zigbee2MQTT:warn  2022-09-30 14:38:51: Allowing new devices to join.
Zigbee2MQTT:warn  2022-09-30 14:38:51: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info  2022-09-30 14:38:51: Zigbee: allowing new devices to join.
Zigbee2MQTT:info  2022-09-30 14:38:51: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:info  2022-09-30 14:38:52: Connected to MQTT server
Zigbee2MQTT:info  2022-09-30 14:38:52: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'

使用MQTT工具连接服务:mqtt://localhost,如MQTTX工具
监听mqtt的topic可以收到数据
zigbee2mqtt/#

如下部分数据:
Topic: zigbee2mqtt/bridge/logging QoS: 0
{"level":"info","message":"Connected to MQTT server"}

Topic: zigbee2mqtt/bridge/logging QoS: 0
{"level":"info","message":"MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'"}

使用小米插座 型号:Xiao Mi zigbee ZNCZ02LM 控制成功

Xiao Mi zigbee ZNCZ02LM 测试成功

注意:
要使用支持zigbee的插座或设备: https://www.zigbee2mqtt.io/information/supported_devices.html
小米蓝牙网关版本,型号:ZNCZ07CM 不支持zigbee 所以连不上

Xiao Mi zigbee ZNCZ02LM 设备按下按钮5秒左右, 灯闪烁,日志打印: Device '0x00158d00012ccbc2' joined 成功加入

 Zigbee2MQTT:info  2022-09-30 14:39:29: Device '0x00158d00012ccbc2' joined
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2"},"type":"device_joined"}'
Zigbee2MQTT:info  2022-09-30 14:39:29: Starting interview of '0x00158d00012ccbc2'
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2","status":"started"},"type":"device_interview"}'
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2"},"type":"device_announce"}'
Zigbee2MQTT:info  2022-09-30 14:39:30: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":81,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:39:31: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":84,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:39:32: Successfully interviewed '0x00158d00012ccbc2', device has successfully been paired
Zigbee2MQTT:info  2022-09-30 14:39:32: Device '0x00158d00012ccbc2' is supported, identified as: Xiaomi Mi power plug ZigBee (ZNCZ02LM)
Zigbee2MQTT:info  2022-09-30 14:39:32: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":{"description":"Mi power plug ZigBee","exposes":[{"features":[{"access":7,"description":"On/off state of the switch","name":"state","property":"state","type":"binary","value_off":"OFF","value_on":"ON","value_toggle":"TOGGLE"}],"type":"switch"},{"access":5,"description":"Instantaneous measured power","name":"power","property":"power","type":"numeric","unit":"W"},{"access":1,"description":"Sum of consumed energy","name":"energy","property":"energy","type":"numeric","unit":"kWh"},{"access":1,"description":"Measured temperature value","name":"temperature","property":"temperature","type":"numeric","unit":"°C"},{"access":7,"description":"Enable/disable the power outage memory, this recovers the on/off mode after power failure","name":"power_outage_memory","property":"power_outage_memory","type":"binary","value_off":false,"value_on":true},{"access":1,"description":"Link quality (signal strength)","name":"linkquality","property":"linkquality","type":"numeric","unit":"lqi","value_max":255,"value_min":0}],"model":"ZNCZ02LM","supports_ota":true,"vendor":"Xiaomi"},"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2","status":"successful","supported":true},"type":"device_interview"}'

使用MQTT工具发送数据控制插座的开关 OFF为关闭 ON为打开

注意观察小米插座上的指示灯的状态

zigbee2mqtt/0x00158d00012ccbc2/set
{
  "state": "OFF"
}

{
  "state": "ON"
}

Zigbee2MQTT:info  2022-09-30 14:47:14: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":81,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:47:24: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":86,"power":0,"state":"OFF","temperature":38}'

你可能感兴趣的:(mqtt_iot,zigbee,mqtt)