안녕하세요? 직비2Mqtt 설정을 해보겠습니다.
오늘 글은 사족을 그만 쓰고 진행합니다.
1. 장비
CC디버거 / 케이블 / CC2531 이 필요합니다.
대충 아래의 구성으로 진행이 됩니다.
둘다 USB와 연결하여 진행합니다.
CC디버거를 다른 제품 라즈베리나 아두이노로 대체할 수 있다고 하는데 저는 일단 그냥 쉽게 디버거를 샀습니다.
2. 플래슁
https://www.ti.com/tool/FLASH-PROGRAMMER
상기에서 V1을 받습니다.
그리고 드라이버를 하기 링크에서 받아서 설치합니다.
http://www.ti.com/general/docs/lit/getliterature.tsp?baseLiteratureNumber=swrc212&fileType=zip
그리고 올릴 펌웨어는 아래 파일입니다.
아래와 같이 진행합니다.
드라이버가 잡혀있지 않아서 수동으로 설치합니다.
다음으로 플래쉬 프로그램을 실행하여 hex 를 선택합니다. (인식이 되지 않는다면 2가지 장비를 모두 뽑고 다시 꽂아주세요)
플래슁이 완료 되었습니다.
3. 케이싱
최근에 산 3D 프린터 장난감으로 하나 뽑고 케이싱을 해줍니다.
캬 멋지게 케이싱이 되었습니다.
4. Zigbee2Mqtt 설치하기
일단 GTMINI 와 아래와 같이 연결했습니다.
셋탑을 NAS 로 써버리는 이런 부분은... 상당히 제품이 안정적이라서 좋습니다.
일단 테스트로 하기와 같이 연결했고 시그널 부분으로 USB 연장 젠더를 쓰시는 게 좋습니다.
오늘은 테스트로 전에 보일러 / 조도 센서 켜고 끄기 딜레이 부분으로 조도 센서만 CC2531 로 연결해볼 생각입니다.
이후 장치가 아래와 같이 올라옴을 확인합니다.
root@aml:~# ls /dev | grep ACM
ttyACM0
root@aml:~# ls -l /dev/serial/by-id
total 0
lrwxrwxrwx 1 root root 13 Jun 28 22:17 usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B0014D90D06-if00 -> ../../ttyACM0
그리고 z2m 프로그램을 설치합니다.
root@aml:~# cd /opt
root@aml:/opt# ls
containerd dwconnector epg hass java kocom miconnector plexepg py-kms scripts
root@aml:/opt# git clone https://github.com/Koenkk/zigbee2mqtt.git z2m
Cloning into 'z2m'...
remote: Enumerating objects: 39, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (26/26), done.
Receiving objects: 46% (5083/11033), 5.23 MiB | 1.67 MiB/s s
일단 dockerfile 이 있어서 해당 파일로 빌드를 해서 구동해보겠습니다. 이 이유는 nodejs 버전 의존성 문제 때문에 귀찮을 껄 회피하기 위해서 입니다. 컨테이너로 돌려버리면 이걸 신경 안써도 되는 부분이 있습니다.
root@aml:/opt/z2m# ls
azure-pipelines.yaml docker index.js LICENSE package.json scripts update.sh
data images lib npm-shrinkwrap.json README.md test
root@aml:/opt/z2m# cd docker/
root@aml:/opt/z2m/docker# ls
docker-compose.yml Dockerfile README.md run.sh
root@aml:/opt/z2m/docker#
root@aml:/opt/z2m/docker# docker build -t z2m .
Sending build context to Docker daemon 5.632kB
Step 1/16 : FROM node:12-alpine as base
12-alpine: Pulling from library/node
29e5d40040c1: Already exists
1f330c3b5d7d: Pull complete
895ca0c2289d: Pull complete
0a71dcab8e97: Pull complete
Digest: sha256:45694caf08b27f851b10f2ce30e986249d3b06590fefb7d327ba9a4fbd371d2b
Status: Downloaded newer image for node:12-alpine
---> 393c48988b6f
Step 2/16 : WORKDIR /app
---> Running in e584608cd948
Removing intermediate container e584608cd948
---> 69d39169241b
Step 3/16 : RUN apk add --no-cache tzdata eudev
---> Running in e0a0513aa668
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/7) Installing udev-init-scripts (33-r0)
Executing udev-init-scripts-33-r0.post-install
(2/7) Installing eudev-libs (3.2.9-r1)
(3/7) Installing libblkid (2.34-r1)
(4/7) Installing xz-libs (5.2.4-r0)
(5/7) Installing kmod (26-r0)
(6/7) Installing eudev (3.2.9-r1)
(7/7) Installing tzdata (2020a-r0)
Executing busybox-1.31.1-r9.trigger
Executing eudev-3.2.9-r1.trigger
OK: 12 MiB in 23 packages
Removing intermediate container e0a0513aa668
---> 53dad4097a89
Step 4/16 : COPY package.json .
COPY failed: stat /var/lib/docker/tmp/docker-builder606272958/package.json: no such file or directory
네? 흠... 결국에 열받아서 그냥 dockerhub 에 있는 것으로 설치해야겠습니다.
상기 문제 잡다가 시간이 걸릴 것 같네요.
찾아보니 arm64 이미지도 있어서 구동이 가능할 것으로 보입니다.
z2m 소스를 지우고 컨테이너 데이터 용으로 쓰기 위해 청소를 합니다.
root@aml:/opt/z2m/docker# cd ..
root@aml:/opt/z2m# rm -rf *
컨테이너를 실행하기 위해 하기 명령을 입력합니다.
root@aml:/opt/z2m# docker run -it --name z2m --restart always --net=host -v /opt/z2m:/app/data --device=/dev/ttyACM0 -e TZ=Asia/Seoul -v /run/udev:/run/udev:ro --privileged=true koenkk/zigbee2mqtt
Unable to find image 'koenkk/zigbee2mqtt:latest' locally
latest: Pulling from koenkk/zigbee2mqtt
29e5d40040c1: Already exists
ff40ec0f33aa: Pull complete
5c1f59b6a373: Pull complete
15bf46738169: Pull complete
1682d6484776: Pull complete
23bcb1037123: Pull complete
97c9ad42e623: Pull complete
dfac931f9aab: Pull complete
ab51897955ad: Pull complete
c56adc66652b: Pull complete
cb9390f4f164: Pull complete
b6cd12647e01: Pull complete
71736ddaba5e: Pull complete
Digest: sha256:ff142238679c562a88977bf162ca6b6eff95e88d38f18086ea43e55ec3a981fb
Status: Downloaded newer image for koenkk/zigbee2mqtt:latest
Using '/app/data' as data directory
Creating configuration file...
> zigbee2mqtt@1.14.0 start /app
> node index.js
zigbee2mqtt:info 2020-06-28 22:42:56: Logging to console and directory: '/app/data/log/2020-06-28.22-42-56' filename: log.txt
zigbee2mqtt:info 2020-06-28 22:42:56: Starting zigbee2mqtt version 1.14.0 (commit #9009de2)
zigbee2mqtt:info 2020-06-28 22:42:56: Starting zigbee-herdsman...
zigbee2mqtt:info 2020-06-28 22:43:02: zigbee-herdsman started
zigbee2mqtt:info 2020-06-28 22:43:02: Coordinator firmware version: '{"type":"zStack12","meta":{"transportrev":2,"product":0,"majorrel":2,"minorrel":6,"maintrel":3,"revision":20190608}}'
zigbee2mqtt:info 2020-06-28 22:43:02: Currently 0 devices are joined:
zigbee2mqtt:warn 2020-06-28 22:43:02: `permit_join` set to `true` in configuration.yaml.
zigbee2mqtt:warn 2020-06-28 22:43:02: Allowing new devices to join.
zigbee2mqtt:warn 2020-06-28 22:43:02: Set `permit_join` to `false` once you joined all devices.
zigbee2mqtt:info 2020-06-28 22:43:02: Zigbee: allowing new devices to join.
zigbee2mqtt:info 2020-06-28 22:43:03: Connecting to MQTT server at mqtt://localhost
zigbee2mqtt:info 2020-06-28 22:43:03: Connected to MQTT server
zigbee2mqtt:info 2020-06-28 22:43:03: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'
zigbee2mqtt:info 2020-06-28 22:43:03: MQTT publish: topic 'zigbee2mqtt/bridge/config', payload '{"version":"1.14.0","commit":"9009de2","coordinator":{"type":"zStack12","meta":{"transportrev":2,"product":0,"majorrel":2,"minorrel":6,"maintrel":3,"revision":20190608}},"log_level":"info","permit_join":true}'
^Czigbee2mqtt:info 2020-06-28 22:43:08: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'offline'
zigbee2mqtt:info 2020-06-28 22:43:08: Disconnecting from MQTT server
zigbee2mqtt:info 2020-06-28 22:43:08: zigbee-herdsman stopped
대충 실행되는 것을 보았으니, 중단 하고 이미지를 지운 다음에 백그라운드로 실행해줍니다.
root@aml:/opt/z2m# docker stop z2m
z2m
root@aml:/opt/z2m# docker rm z2m
z2m
root@aml:/opt/z2m# docker run -d --name z2m --restart always --net=host -v /opt/z2m:/app/data --device=/dev/ttyACM0 -e TZ=Asia/Seoul -v /run/udev:/run/udev:ro --privileged=true koenkk/zigbee2mqtt
8d38a41ecae944bf9406bb18fa4848de82646972f06b04e2812be87d78d96b66
root@aml:/opt/z2m# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d38a41ecae9 koenkk/zigbee2mqtt "./run.sh" 20 seconds ago Up 19 seconds z2m
b89194ace9e0 homeassistant/home-assistant:stable "/init" 6 weeks ago Up 16 minutes hass
05f8baf5729e portainer/portainer "/portainer" 6 weeks ago Up 16 minutes 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp portainer
설정 파일이 바인드된 디렉터리에 아래처럼 생겼을 것입니다.
root@aml:/opt/z2m# ls
configuration.yaml database.db log state.json
설정 내용이 아래와 같습니다. 조인이 허용되어 있고, 홈 어시스턴트 디스커버리는 OFF 이네요. 일단 ON 시켜 두고 HA와 연동합니다.
root@aml:/opt/z2m# cat configuration.yaml
# Home Assistant integration (MQTT discovery)
homeassistant: false
# allow new devices to join
permit_join: true
# MQTT settings
mqtt:
# MQTT base topic for zigbee2mqtt MQTT messages
base_topic: zigbee2mqtt
# MQTT server URL
server: 'mqtt://localhost'
# MQTT server authentication, uncomment if required:
# user: my_user
# password: my_password
# Serial settings
serial:
# Location of CC2531 USB sniffer
port: /dev/ttyACM0
root@aml:/opt/z2m# docker restart z2m
z2m
5. 디바이스 페어링
일단 상기에서 조인을 True 로 설정해서 로그를 보면서 페어링이 되는지 확인합니다.
본래 ST 허브에서 페어링을 풀어주고, 리셋을 통해 페어링을 시도합니다.
로그를 보면 페어링이 되었다고 나오네요 ㅎㅎ
root@aml:/opt/z2m/log/2020-06-28.22-47-26# tail -f log.txt
info 2020-06-28 22:47:29: Coordinator firmware version: '{"type":"zStack12","meta":{"transportrev":2,"product":0,"majorrel":2,"minorrel":6,"maintrel":3,"revision":20190608}}'
info 2020-06-28 22:47:29: Currently 0 devices are joined:
warn 2020-06-28 22:47:29: `permit_join` set to `true` in configuration.yaml.
warn 2020-06-28 22:47:29: Allowing new devices to join.
warn 2020-06-28 22:47:29: Set `permit_join` to `false` once you joined all devices.
info 2020-06-28 22:47:29: Zigbee: allowing new devices to join.
info 2020-06-28 22:47:29: Connecting to MQTT server at mqtt://localhost
info 2020-06-28 22:47:29: Connected to MQTT server
info 2020-06-28 22:47:29: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'
info 2020-06-28 22:47:29: MQTT publish: topic 'zigbee2mqtt/bridge/config', payload '{"version":"1.14.0","commit":"9009de2","coordinator":{"type":"zStack12","meta":{"transportrev":2,"product":0,"majorrel":2,"minorrel":6,"maintrel":3,"revision":20190608}},"log_level":"info","permit_join":true}'
info 2020-06-28 22:51:26: Device '0x04cf8cdf3c78d428' joined
info 2020-06-28 22:51:26: Starting interview of '0x04cf8cdf3c78d428'
info 2020-06-28 22:51:26: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"device_connected","message":{"friendly_name":"0x04cf8cdf3c78d428"}}'
info 2020-06-28 22:51:26: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"pairing","message":"interview_started","meta":{"friendly_name":"0x04cf8cdf3c78d428"}}'
info 2020-06-28 22:51:27: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"device_announced","message":"announce","meta":{"friendly_name":"0x04cf8cdf3c78d428"}}'
info 2020-06-28 22:51:30: MQTT publish: topic 'homeassistant/sensor/0x04cf8cdf3c78d428/battery/config', payload '{"unit_of_measurement":"%","device_class":"battery","value_template":"{{ value_json.battery }}","state_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","json_attributes_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","name":"0x04cf8cdf3c78d428_battery","unique_id":"0x04cf8cdf3c78d428_battery_zigbee2mqtt","device":{"identifiers":["zigbee2mqtt_0x04cf8cdf3c78d428"],"name":"0x04cf8cdf3c78d428","sw_version":"Zigbee2mqtt 1.14.0","model":"MiJia light intensity sensor (GZCGQ01LM)","manufacturer":"Xiaomi"},"availability_topic":"zigbee2mqtt/bridge/state"}'
info 2020-06-28 22:51:30: MQTT publish: topic 'homeassistant/sensor/0x04cf8cdf3c78d428/illuminance/config', payload '{"unit_of_measurement":"-","device_class":"illuminance","value_template":"{{ value_json.illuminance }}","state_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","json_attributes_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","name":"0x04cf8cdf3c78d428_illuminance","unique_id":"0x04cf8cdf3c78d428_illuminance_zigbee2mqtt","device":{"identifiers":["zigbee2mqtt_0x04cf8cdf3c78d428"],"name":"0x04cf8cdf3c78d428","sw_version":"Zigbee2mqtt 1.14.0","model":"MiJia light intensity sensor (GZCGQ01LM)","manufacturer":"Xiaomi"},"availability_topic":"zigbee2mqtt/bridge/state"}'
info 2020-06-28 22:51:30: MQTT publish: topic 'homeassistant/sensor/0x04cf8cdf3c78d428/illuminance_lux/config', payload '{"unit_of_measurement":"lx","device_class":"illuminance","value_template":"{{ value_json.illuminance_lux }}","state_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","json_attributes_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","name":"0x04cf8cdf3c78d428_illuminance_lux","unique_id":"0x04cf8cdf3c78d428_illuminance_lux_zigbee2mqtt","device":{"identifiers":["zigbee2mqtt_0x04cf8cdf3c78d428"],"name":"0x04cf8cdf3c78d428","sw_version":"Zigbee2mqtt 1.14.0","model":"MiJia light intensity sensor (GZCGQ01LM)","manufacturer":"Xiaomi"},"availability_topic":"zigbee2mqtt/bridge/state"}'
info 2020-06-28 22:51:30: MQTT publish: topic 'homeassistant/sensor/0x04cf8cdf3c78d428/linkquality/config', payload '{"icon":"mdi:signal","unit_of_measurement":"lqi","value_template":"{{ value_json.linkquality }}","state_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","json_attributes_topic":"zigbee2mqtt/0x04cf8cdf3c78d428","name":"0x04cf8cdf3c78d428_linkquality","unique_id":"0x04cf8cdf3c78d428_linkquality_zigbee2mqtt","device":{"identifiers":["zigbee2mqtt_0x04cf8cdf3c78d428"],"name":"0x04cf8cdf3c78d428","sw_version":"Zigbee2mqtt 1.14.0","model":"MiJia light intensity sensor (GZCGQ01LM)","manufacturer":"Xiaomi"},"availability_topic":"zigbee2mqtt/bridge/state"}'
info 2020-06-28 22:51:40: Successfully interviewed '0x04cf8cdf3c78d428', device has successfully been paired
info 2020-06-28 22:51:40: Device '0x04cf8cdf3c78d428' is supported, identified as: Xiaomi MiJia light intensity sensor (GZCGQ01LM)
info 2020-06-28 22:51:40: Configuring '0x04cf8cdf3c78d428'
info 2020-06-28 22:51:40: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"pairing","message":"interview_successful","meta":{"friendly_name":"0x04cf8cdf3c78d428","model":"GZCGQ01LM","vendor":"Xiaomi","description":"MiJia light intensity sensor","supported":true}}'
info 2020-06-28 22:51:42: MQTT publish: topic 'zigbee2mqtt/0x04cf8cdf3c78d428', payload '{"battery":100,"voltage":3100,"linkquality":84}'
info 2020-06-28 22:51:43: MQTT publish: topic 'zigbee2mqtt/0x04cf8cdf3c78d428', payload '{"battery":100,"voltage":3100,"linkquality":84,"illuminance":20454,"illuminance_lux":110}'
info 2020-06-28 22:51:43: Successfully configured '0x04cf8cdf3c78d428'
6. HA 와 연동
일단 HA 에 커스텀 컴포넌트를 설치하지 않아도 HA 의 MQTT 디스커버리가 설정되어 있어서 아래와 같이 자동으로 나옵니다.
일단 오늘은 시간이 늦어서 HA Custom Component 는 보지 않기로 했습니다. 있는지도 잘 모르... 겠습니다.
그럼 이전에 설정했던 보일러 자동화 부분을 수정하겠습니다.
315 - id: '1591270647462'
316 alias: turn on bolier water mode (light sensor)
317 description: ''
318 trigger:
319 - above: '90'
320 entity_id: sensor.0x04cf8cdf3c78d428_illuminance_lux
321 for: 00:00:01
322 platform: numeric_state
323 condition:
324 - condition: and
325 conditions:
326 - condition: state
327 entity_id: input_boolean.home_state
328 state: 'on'
329 - condition: state
330 entity_id: switch.boiler_bath_onoff
331 state: 'off'
332 action:
333 - data: {}
334 entity_id: switch.boiler_bath_onoff
335 service: switch.turn_on
336 - id: '1591270865868'
337 alias: turn off boiler water mode (light sensor)
338 description: ''
339 trigger:
340 - below: '70'
341 entity_id: sensor.0x04cf8cdf3c78d428_illuminance_lux
342 for: 00:00:01
343 platform: numeric_state
344 condition:
345 - condition: state
346 entity_id: switch.boiler_bath_onoff
347 state: 'on'
348 action:
349 - data: {}
350 entity_id: switch.boiler_bath_onoff
351 service: switch.turn_off
이후 반응속도를 보았습니다.
이전에 ST 허브 --> HA 로 센서 연동 반응 속도 입니다.
Z2M 반응 속도 입니다.
오 .. 매우 빠르네요.. 반응이...
일단 ST 에 붙어있는 직비를 다 빼야겠습니다. 그리고 Z2M 으로 옮겨야겠네요 ㅎㅎㅎ
ST 는 허브 없이 다원 플러그 받는 용도로만 쓰게 될 것 같은 느낌이 듭니다.
일단 여기까지 ... 마치겠습니다.
감사합니다.
'IoT' 카테고리의 다른 글
HomeAssistant 샤오미 공기청정기 / 선풍기 연동 (0) | 2020.07.02 |
---|---|
다원 와이파이 플러그 로컬 컨트롤 설정하기 (stkang90 님) (5) | 2020.07.02 |
다원 플러그 API 키 사태 대응하기 (2) | 2020.06.13 |
HomeAssistant 조도 센서를 활용한 보일러 온수 ON/OFF (0) | 2020.06.04 |
HomeAssistant 초보자 설정 (0) | 2020.05.27 |
댓글