Ikea lemputės ir Xiaomi kubas - Zigbee2MQTT
Iš Aliexpress buvau atsisiuntęs Texas Instruments CC2531 USB adapterį su PCB antena. Pakeitus prietaiso firmware (programinę aparatinę įrangą),
juo galima valdytį daugybę belaidžių prietaisų, pvz. reguliuojamas Ikea lemputes.
Firmware atnaujinimui reikia iš Aliexpress siųstis programatorių, arba naudoti alternatyvų metodą - Raspberry Pi.
Naudojamas modulis
Texas Instruments CC2531 - USB connected Zigbee adapter with PCB antenna
Tradicinis flashinimas
https://www.zigbee2mqtt.io/information/flashing_the_cc2531.html
Kadangi neturiu programatoriaus o laukti kol atvyks iš Ali nėra kantrybės, renkuosi alternatyvą.
Alternatyvus flashinimas naudojant Raspberry Pi
Instrukcija čia: https://www.zigbee2mqtt.io/information/alternative_flashing_methods.html
Reikia sujungti min tris laidus su Raspi pinais. Maitinimo ir groundo nereikia - jie užtikrinami statant įrenginį į USB lizdą.
- pin 7 (reset) –> pin 35 (GPIO24, BCM19)
- pin 3 (DC) –> pin 36 (GPIO27, BCM16)
- pin 4 (DD) –> pin 38 (GPIO28, BCM20)
Pirmą kartą prijungiau ir ground, pradėjo svilti :). Pasirodo laikiau RPI atvirkščiai. Tos diagramos internete galėtų būti aiškesnės :)). Maniau sukepė projektas bet perjungus ir suvedus žemiau pateiktas eilutes paaiškėjo, kad viskas ok.
cd ~/bin
git clone https://github.com/jmichault/flash_cc2531.git
cd flash_cc2531
./cc_chipid
Rezultatas turi būti:
ID = b524.
Zigbee2MQTT diegimas
https://www.zigbee2mqtt.io/getting_started/running_zigbee2mqtt.html
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 # Should output v10.X, v12.X, v14.X or v15.X
npm --version # Should output 6.X or 7.X
sudo git clone https://github.com/Koenkk/zigbee2mqtt.git ~/bin/zigbee2mqtt
sudo chown -R pi:pi ~/bin/zigbee2mqtt
cd ~/bin/zigbee2mqtt
npm ci
Nustatymai koreguojami čia. Kol kas palieku viską pagal nutylėjimą.
vim ~/bin/zigbee2mqtt/data/configuration.yaml
Paleidimas
cd ~/bin/zigbee2mqtt
npm start
Sėkmingo starto pavyzdys:
$ npm start
> zigbee2mqtt@1.21.0 start /home/bob/bin/zigbee2mqtt
> node index.js
Building Zigbee2MQTT... (initial build), finished
Zigbee2MQTT:info 2021-08-20 17:59:19: Logging to console and directory: '/home/bob/bin/zigbee2mqtt/data/log/2021-08-20.17-59-19' filename: log.txt
Zigbee2MQTT:info 2021-08-20 17:59:19: Starting Zigbee2MQTT version 1.21.0 (commit #70891eec)
Zigbee2MQTT:info 2021-08-20 17:59:19: Starting zigbee-herdsman (0.13.124)
Zigbee2MQTT:info 2021-08-20 17:59:30: zigbee-herdsman started (restored)
Zigbee2MQTT:info 2021-08-20 17:59:30: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20201127,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info 2021-08-20 17:59:30: Currently 0 devices are joined:
Zigbee2MQTT:warn 2021-08-20 17:59:30: `permit_join` set to `true` in configuration.yaml.
Zigbee2MQTT:warn 2021-08-20 17:59:30: Allowing new devices to join.
Zigbee2MQTT:warn 2021-08-20 17:59:30: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info 2021-08-20 17:59:30: Zigbee: allowing new devices to join.
Zigbee2MQTT:info 2021-08-20 17:59:31: Connecting to MQTT server at mqtt://192.168.1.21
Zigbee2MQTT:info 2021-08-20 17:59:31: Connected to MQTT server
Zigbee2MQTT:info 2021-08-20 17:59:31: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'
Zigbee2MQTT:info 2021-08-20 17:59:31: MQTT publish: topic 'zigbee2mqtt/bridge/config', payload '{"commit":"70891eec","coordinator":{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20201127,"transportrev":2},"type":"zStack12"},"log_level":"info","network":{"channel":11,"extendedPanID":"0x00124b0014d94766","panID":6754},"permit_join":true,"version":"1.21.0"}'
Kuriam servisą, kad startuotų automatiškai
sudo vim /etc/systemd/system/zigbee2mqtt.service
[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/pi/bin/zigbee2mqtt
StandardOutput=inherit
# Or use StandardOutput=null if you don't want Zigbee2MQTT messages filling syslog, for more options see systemd.exec(5)
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
sudo systemctl enable zigbee2mqtt
sudo systemctl start zigbee2mqtt
systemctl status zigbee2mqtt.service
Naudingos komandos
# Stopping Zigbee2MQTT
sudo systemctl stop zigbee2mqtt
# Starting Zigbee2MQTT
sudo systemctl start zigbee2mqtt
# View the log of Zigbee2MQTT
sudo journalctl -u zigbee2mqtt.service -f
Poravimas su naujais įrenginiais
Nustatymuose turi būti aktyvus permit_join: true
. Vėliau dėl saugumo reikia nustatyti į false
, kad neprisijungtų nepageidaujami įrenginiai.
vim ~/bin/zigbee2mqtt/data/configuration.yaml
Poravimo instrukcijos skirtingiems įrenginiams
https://www.zigbee2mqtt.io/information/supported_devices.html
IKEA TRADFRI LED bulb E14 600 lumen
Ant stalo turiu dvi Ikea lemputes TRADFRI LED bulb E14 600 lm, LED1733G7
Vadovaujuosi instrukciją https://www.zigbee2mqtt.io/devices/LED1738G7.html
Lemputė su antena poruojasi automatiškai atstačius jos gamiklinius parametrus: https://www.youtube.com/watch?v=npxOrPxVfe0
Zigbee2MQTT:info 2021-08-20 18:06:39: Device '0x90fd9ffffe52adb0' joined
Zigbee2MQTT:info 2021-08-20 18:06:39: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x90fd9ffffe52adb0","ieee_address":"0x90fd9ffffe52adb0"},"type":"device_joined"}'
Zigbee2MQTT:info 2021-08-20 18:06:39: Starting interview of '0x90fd9ffffe52adb0'
Zigbee2MQTT:info 2021-08-20 18:06:39: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x90fd9ffffe52adb0","ieee_address":"0x90fd9ffffe52adb0","status":"started"},"type":"device_interview"}'
Zigbee2MQTT:info 2021-08-20 18:06:39: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":{"friendly_name":"0x90fd9ffffe52adb0"},"type":"device_connected"}'
Zigbee2MQTT:info 2021-08-20 18:06:39: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"interview_started","meta":{"friendly_name":"0x90fd9ffffe52adb0"},"type":"pairing"}'
Zigbee2MQTT:info 2021-08-20 18:06:43: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x90fd9ffffe52adb0","ieee_address":"0x90fd9ffffe52adb0"},"type":"device_announce"}'
Zigbee2MQTT:info 2021-08-20 18:06:43: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"announce","meta":{"friendly_name":"0x90fd9ffffe52adb0"},"type":"device_announced"}'
Zigbee2MQTT:info 2021-08-20 18:06:54: Successfully interviewed '0x90fd9ffffe52adb0', device has successfully been paired
Zigbee2MQTT:info 2021-08-20 18:06:54: Device '0x90fd9ffffe52adb0' is supported, identified as: IKEA TRADFRI LED bulb E14 600 lumen, dimmable, white spectrum, opal white (LED1733G7)
Zigbee2MQTT:info 2021-08-20 18:06:54: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":{"description":"TRADFRI LED bulb E14 600 lumen, dimmable, white spectrum, opal white","exposes":[{"features":[{"access":7,"description":"On/off state of this light","name":"state","property":"state","type":"binary","value_off":"OFF","value_on":"ON","value_toggle":"TOGGLE"},{"access":7,"description":"Brightness of this light","name":"brightness","property":"brightness","type":"numeric","value_max":254,"value_min":0},{"access":7,"description":"Color temperature of this light","name":"color_temp","presets":[{"description":"Coolest temperature supported","name":"coolest","value":250},{"description":"Cool temperature (250 mireds / 4000 Kelvin)","name":"cool","value":250},{"description":"Neutral temperature (370 mireds / 2700 Kelvin)","name":"neutral","value":370},{"description":"Warm temperature (454 mireds / 2200 Kelvin)","name":"warm","value":454},{"description":"Warmest temperature supported","name":"warmest","value":454}],"property":"color_temp","type":"numeric","unit":"mired","value_max":454,"value_min":250},{"access":7,"description":"Color temperature after cold power on of this light","name":"color_temp_startup","presets":[{"description":"Coolest temperature supported","name":"coolest","value":250},{"description":"Cool temperature (250 mireds / 4000 Kelvin)","name":"cool","value":250},{"description":"Neutral temperature (370 mireds / 2700 Kelvin)","name":"neutral","value":370},{"description":"Warm temperature (454 mireds / 2200 Kelvin)","name":"warm","value":454},{"description":"Warmest temperature supported","name":"warmest","value":454},{"description":"Restore previous color_temp on cold power on","name":"previous","value":65535}],"property":"color_temp_startup","type":"numeric","unit":"mired","value_max":454,"value_min":250}],"type":"light"},{"access":2,"description":"Triggers an effect on the light (e.g. make light blink for a few seconds)","name":"effect","property":"effect","type":"enum","values":["blink","breathe","okay","channel_change","finish_effect","stop_effect"]},{"access":7,"description":"Controls the behavior when the device is powered on","name":"power_on_behavior","property":"power_on_behavior","type":"enum","values":["off","previous","on"]},{"access":1,"description":"Link quality (signal strength)","name":"linkquality","property":"linkquality","type":"numeric","unit":"lqi","value_max":255,"value_min":0}],"model":"LED1733G7","supports_ota":true,"vendor":"IKEA"},"friendly_name":"0x90fd9ffffe52adb0","ieee_address":"0x90fd9ffffe52adb0","status":"successful","supported":true},"type":"device_interview"}'
Zigbee2MQTT:info 2021-08-20 18:06:54: Configuring '0x90fd9ffffe52adb0'
Zigbee2MQTT:info 2021-08-20 18:06:54: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"interview_successful","meta":{"description":"TRADFRI LED bulb E14 600 lumen, dimmable, white spectrum, opal white","friendly_name":"0x90fd9ffffe52adb0","model":"LED1733G7","supported":true,"vendor":"IKEA"},"type":"pairing"}'
Zigbee2MQTT:info 2021-08-20 18:06:56: MQTT publish: topic 'zigbee2mqtt/0x90fd9ffffe52adb0', payload '{"color_mode":"xy","linkquality":92}'
Zigbee2MQTT:info 2021-08-20 18:06:56: MQTT publish: topic 'zigbee2mqtt/0x90fd9ffffe52adb0', payload '{"color_mode":"xy","linkquality":86}'
Zigbee2MQTT:info 2021-08-20 18:06:56: Successfully configured '0x90fd9ffffe52adb0'
Xiaomi Mi/Aqara smart home cube
https://www.zigbee2mqtt.io/devices/MFKZQ01LM.html
Kubelis naudojamas kaip distancinio valdymo pultas.
Valdymo kubas poruojamas nuėmus dangtelį ir laikant LINK mygtuką 5 sekundes:
Zigbee2MQTT:info 2021-08-20 18:33:42: Device '0x00158d00051e02d2' joined
Zigbee2MQTT:info 2021-08-20 18:33:42: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00051e02d2","ieee_address":"0x00158d00051e02d2"},"type":"device_joined"}'
Zigbee2MQTT:info 2021-08-20 18:33:42: Starting interview of '0x00158d00051e02d2'
Zigbee2MQTT:info 2021-08-20 18:33:42: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00051e02d2","ieee_address":"0x00158d00051e02d2","status":"started"},"type":"device_interview"}'
Zigbee2MQTT:info 2021-08-20 18:33:42: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":{"friendly_name":"0x00158d00051e02d2"},"type":"device_connected"}'
Zigbee2MQTT:info 2021-08-20 18:33:42: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"interview_started","meta":{"friendly_name":"0x00158d00051e02d2"},"type":"pairing"}'
Zigbee2MQTT:info 2021-08-20 18:33:43: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00051e02d2","ieee_address":"0x00158d00051e02d2"},"type":"device_announce"}'
Zigbee2MQTT:info 2021-08-20 18:33:43: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"announce","meta":{"friendly_name":"0x00158d00051e02d2"},"type":"device_announced"}'
Zigbee2MQTT:info 2021-08-20 18:33:44: MQTT publish: topic 'zigbee2mqtt/0x00158d00051e02d2', payload '{"battery":74,"linkquality":123,"voltage":2955}'
Zigbee2MQTT:info 2021-08-20 18:33:46: MQTT publish: topic 'zigbee2mqtt/0x00158d00051e02d2', payload '{"action":"rotate_right","action_angle":13.4,"angle":13.4,"battery":74,"linkquality":147,"voltage":2955}'
Zigbee2MQTT:info 2021-08-20 18:34:29: Successfully interviewed '0x00158d00051e02d2', device has successfully been paired
Zigbee2MQTT:info 2021-08-20 18:34:29: Device '0x00158d00051e02d2' is supported, identified as: Xiaomi Mi/Aqara smart home cube (MFKZQ01LM)
Zigbee2MQTT:info 2021-08-20 18:34:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":{"description":"Mi/Aqara smart home cube","exposes":[{"access":1,"description":"Remaining battery in %","name":"battery","property":"battery","type":"numeric","unit":"%","value_max":100,"value_min":0},{"access":1,"description":"Voltage of the battery in millivolts","name":"voltage","property":"voltage","type":"numeric","unit":"mV"},{"access":1,"name":"action_angle","property":"action_angle","type":"numeric","value_max":360,"value_min":-360},{"access":1,"description":"Side of the cube","name":"action_from_side","property":"action_from_side","type":"numeric","value_max":6,"value_min":0,"value_step":1},{"access":1,"description":"Side of the cube","name":"action_side","property":"action_side","type":"numeric","value_max":6,"value_min":0,"value_step":1},{"access":1,"description":"Side of the cube","name":"action_to_side","property":"action_to_side","type":"numeric","value_max":6,"value_min":0,"value_step":1},{"access":1,"description":"Triggered action (e.g. a button click)","name":"action","property":"action","type":"enum","values":["shake","wakeup","fall","tap","slide","flip180","flip90","rotate_left","rotate_right"]},{"access":1,"description":"Link quality (signal strength)","name":"linkquality","property":"linkquality","type":"numeric","unit":"lqi","value_max":255,"value_min":0}],"model":"MFKZQ01LM","supports_ota":false,"vendor":"Xiaomi"},"friendly_name":"0x00158d00051e02d2","ieee_address":"0x00158d00051e02d2","status":"successful","supported":true},"type":"device_interview"}'
Zigbee2MQTT:info 2021-08-20 18:34:29: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":"interview_successful","meta":{"description":"Mi/Aqara smart home cube","friendly_name":"0x00158d00051e02d2","model":"MFKZQ01LM","supported":true,"vendor":"Xiaomi"},"type":"pairing"}'
Lempos ir kubas kartu: Node-Red logika
Šiandienos tikslas panaudoti kubo barbenimo ir sukiojimo funkcijas valdant suporuotas Ikea lemputes.
"toggle wall" funkcija:
var action = msg.payload.action;
var side = msg.payload.side;
var angle = msg.payload.angle;
node.warn(action);
node.warn(side);
if ( action == "tap") {
var now = global.get("out3");
if ( now !== 0) {
now = 0;
global.set("out3", 0);
} else {
now = 1;
global.set("out3", 1);
}
msg.payload = now;
return [null, msg];
}
if ( action == "rotate_right") {
msg.payload = {"state":"ON", "brightness":255};
return [msg, null];
}
if ( action == "rotate_left") {
msg.payload = {"state":"ON", "brightness":125};
return [msg, null];
}
// return msg;