本帖最后由 Aiden1 于 2019-11-18 00:42 编辑
没错,我是来交“作业”的首先非常感谢业界大佬 @Alexie 提供的Zigbee版的Sonoff_Basic_R3。 目前国内还没有售卖,但是WiFi版的已经可以买到了,如果有需要的话可以先买个WiFi版的,他们的外观和zigbee版的一样,Zigbee版的话估计还要等一段时间。 老样子还是先说一下体验,此次接入还是挺顺利的,正好手里有一个 CC2530 的模块我提前就把所需的协调器(网关)环境搭建好了就等开关模块到货,由于双十一大佬仓库那边耽搁了,今天才拿到货。使用起来感觉比之前的 WiFi 版要顺畅,之前 WiFi 版是放到灯里面的,外面还有一个铁盒子装起来的,信号也衰减了一大半,时不时就掉线了,这次的最主要是 zigbee 的不会受周围的干扰,因为我这边接了好多 WiFi 模块,设备一多延迟就特别大。虽然这次没有把之前的换掉,我感觉问题应该不大,我在网关上加了一根天线。首先我们来看一下外观和内部结构
说实话这次的做工质量比我之前的版本好了很多,外壳的材料也换成了 PC 材料,之前的貌似是 ABS 的。
听业界大佬描述无需 App 直接支持 Echo Plus / Echo show 等音箱直接接入控制(通过亚马逊 WWA 认证),支持三星 SmartThings Hub(通过三星 WWST 认证,同时海外博主实测兼容小米(Mijia)网关和欧瑞博 mini 网关接入,我没有上述的音响和网关,所以这次使用自建网关接入,最主要是接入 HA 所以就选择 zigbee2mqtt。
搭建网关环境:
所需工具和模块
zigbee2mqtt 运行起来之后就开始进出配对,在配对之前先修改一下树莓派上 zigbee2mqtt 的 configuration.yaml 使之允许设备加入,编辑 sudo nano /opt/zigbee2mqtt/data/configuration.yaml
homeassistant: true
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: 'mqtt://192.168.1.18' //mqtt
user: *******
password: *******
client_id: zigbee
include_device_information: true
复制代码
当然也可以在 HA 里面加入一个允许加入设备的开关,这样方便以后加入设备就不用每次编辑配置文件,这样配对的时候直接使用开关就好了。
input_select:
zigbee2mqtt_log_level:
name: Zigbee2mqtt Log Level
options:
- debug
- info
- warn
- error
initial: info
icon: mdi:format-list-bulleted
# Input boolean for enabling/disabling joining
input_boolean:
zigbee_permit_join:
name: Allow devices to join
initial: off
icon: mdi:cellphone-wireless
# Timer for joining time remaining (360 sec = 6 min)
timer:
zigbee_permit_join:
name: Time remaining
duration: 360
# Sensor for monitoring the bridge state
sensor:
- platform: mqtt
name: Zigbee2mqtt Bridge state
state_topic: "zigbee2mqtt/bridge/state"
icon: mdi:router-wireless
# Switch for enabling joining
switch:
- platform: mqtt
name: "Zigbee2mqtt Main join"
state_topic: "zigbee2mqtt/bridge/config/permit_join"
command_topic: "zigbee2mqtt/bridge/config/permit_join"
payload_on: "true"
payload_off: "false"
automation:
- alias: Zigbee2mqtt Log Level
initial_state: 'on'
trigger:
- platform: state
entity_id: input_select.zigbee2mqtt_log_level
to: debug
- platform: state
entity_id: input_select.zigbee2mqtt_log_level
to: warn
- platform: state
entity_id: input_select.zigbee2mqtt_log_level
to: error
- platform: state
entity_id: input_select.zigbee2mqtt_log_level
to: info
action:
- service: mqtt.publish
data:
payload_template: '{{ states(''input_select.zigbee2mqtt_log_level'') }}'
topic: zigbee2mqtt/bridge/config/log_level
- id: enable_zigbee_join
alias: Enable Zigbee joining
hide_entity: true
trigger:
platform: state
entity_id: input_boolean.zigbee_permit_join
to: 'on'
action:
- service: mqtt.publish
data:
topic: zigbee2mqtt/bridge/config/permit_join
payload: 'true'
- service: timer.start
data:
entity_id: timer.zigbee_permit_join
- id: disable_zigbee_join
alias: Disable Zigbee joining
hide_entity: true
trigger:
- entity_id: input_boolean.zigbee_permit_join
platform: state
to: 'off'
action:
- data:
payload: 'false'
topic: zigbee2mqtt/bridge/config/permit_join
service: mqtt.publish
- data:
entity_id: timer.zigbee_permit_join
service: timer.cancel
- id: disable_zigbee_join_timer
alias: Disable Zigbee joining by timer
hide_entity: true
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.zigbee_permit_join
action:
- service: mqtt.publish
data:
topic: zigbee2mqtt/bridge/config/permit_join
payload: 'false'
- service: input_boolean.turn_off
data:
entity_id: input_boolean.zigbee_permit_join
homeassistant:
customize:
timer.zigbee_permit_join:
friendly_name: 倒计时
input_boolean.zigbee_permit_join:
friendly_name: 允许设备加入
sensor.zigbee2mqtt_bridge_state:
friendly_name: Zigbee桥状态
group:
zigbee:
view: false
control: hidden
name: Zigbee网关
entities:
- input_boolean.zigbee_permit_join
- timer.zigbee_permit_join
- sensor.zigbee2mqtt_bridge_state
- switch.zigbee2mqtt_main_join
- automation.enable_zigbee_joining
- automation.disable_zigbee_joining
- automation.disable_zigbee_joining_by_timer
- input_select.zigbee2mqtt_log_level
- automation.zigbee2mqtt_log_level
复制代码
sonoff 开关首次上电会自动进入配对模式,如长时间没配对成功,设备可能退出了配对模式,长按手动开关 5 秒直到信号指示灯闪烁即可,网关没问题的话就会出现如下图的配对成功日志(实时日志可运行 sudo journalctl -u zigbee2mqtt.service -f 查看)
同时 HA 里面也会自动出现(前提已开启 MQTT 自动发现)一个类似 switch.0x00124b001f669712_switch 和 sensor.0x00124b001f669712_linkquality 的设备 ID,使用 switch.0x00124b001f669712_switch 就可以控制了。
如果没有开启自动发现或者自动发现没有生效时也可以再 HA 里面加入
注意这里的 <FRIENDLY_NAME> 为配对时的 friendlyName,类似 0x00124b001f669712,在实时日志里可以看到。
switch:
- platform: "mqtt"
state_topic: "zigbee2mqtt/<FRIENDLY_NAME>"
availability_topic: "zigbee2mqtt/bridge/state"
payload_off: "OFF"
payload_on: "ON"
value_template: "{{ value_json.state }}"
command_topic: "zigbee2mqtt/<FRIENDLY_NAME>/set"
sensor:
- platform: "mqtt"
state_topic: "zigbee2mqtt/<FRIENDLY_NAME>"
availability_topic: "zigbee2mqtt/bridge/state"
unit_of_measurement: "-"
value_template: "{{ value_json.linkquality }}"
复制代码
再附一张开关模块的 IO 口,期待各位大佬能开发出更好的固件
最后与我之前的模块对比一下,总体上内部结构都差不对,大小也差不多,zigbee 版的稍微大一点点,基本上普通 86 盒都能塞的下。