小米网关 (Aqara)
小米网关 (Aqara) integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] 允许您将 小米
该中心有两个版本:v1 和 v2。
-
v1 可以与 Home Assistant 无缝配合使用。
-
v2 在启用本地 API 时可能不太简单。甚至可能需要您打开设备以实现此功能。小米建议这项功能正在开发中。如果您有 Hub 2 并且遇到问题,请查看 故障排除 部分。
支持的设备
- Aqara 空调伴侣 (lumi.acpartner.v3)
- Aqara 智能门锁 (lock.aq1)
- Aqara 壁装开关 (双开)
- Aqara 壁装开关 (单开)
- Aqara 壁装开关 LN (双开)
- Aqara 壁装开关 LN (单开)
- Aqara 无线开关 (双开)
- Aqara 无线开关 (单开)
- 电池
- 按钮第一代 (单击、双击、长按)
- 按钮第二代 (单击、双击)
- 立方体
- 门窗传感器 (第一代和第二代)
- 燃气泄漏检测器 (报告警报和密度)
- 网关 (光线、照明传感器、铃声播放)
- 智能窗帘
- 动态传感器 (第一代和第二代)
- 插头,也叫插座 (Zigbee 版本,报告耗电量、电力负载、状态以及设备是否在使用)
- 烟雾探测器 (报告警报和密度)
- 温湿度传感器 (第一代和第二代)
- 振动传感器
- 壁挂插头 (报告耗电量、电力负载和状态)
- 水漏传感器
- 小米米家网关 (lumi.gateway.v2, lumi.gateway.v3)
不支持的设备
- 小米 Aqara 网关 (lumi.gateway.aqhm01),因为无法在米家应用中激活开发模式。
- 网关收音机
- 网关按钮
- 小米米空调伴侣 (lumi.acpartner.v2)
- Aqara 智能空调控制器集线器 (lumi.acpartner.v1)
- Aqara 壁装开关的解耦模式 (单开 & 双开)
- 燃气和烟雾检测器的额外警报事件:模拟警报、电池故障警报 (仅烟雾探测器)、灵敏度故障警报、I2C 通信故障
设置
按照您的手机和米家应用中的设置流程进行操作。在这里,您将能够根据 本教程
要在您的安装中启用 小米网关 (Aqara),请转到 设置 > 设备与服务。小米 Aqara 网关应自动被发现并显示在概览中。点击配置并按照步骤指定可选设置。如果您的 Aqara 网关未自动显示,请点击右下角的 + 图标。然后,搜索 “xiaomi_aqara” 并进入设置。通过简单地多次重复设置,可以配置多个网关。
实体
小米网关 (Aqara) 集成支持以下实体。
遮罩
遮罩实体允许您控制连接的 Aqara 遮罩。您可以执行以下操作:
- 打开遮罩。
- 关闭遮罩。
- 停止遮罩运动。
- 将遮罩移动到特定位置。
- 查看遮罩的当前位置。
灯光
灯光实体允许您控制小米网关的内部灯光。该实体名为 light.gateway_light_28ffffffffff
。您可以执行以下操作:
- 开启和关闭灯光。
- 设置亮度。
- 使用 HS 或 RGB 颜色编码设置颜色。
要求是您已设置 小米 aqara。
锁
Aqara 锁无法通过 Home Assistant 控制。然而,锁实体允许您查看以下数据:
-
属性
changed_by
提供最后一次成功解锁的用户/密钥 ID。 -
如果有人尝试解除设备锁定但失败超过 3 次,
verified_wrong_times
属性将递增。成功解锁时计数器重置。
二进制传感器
二进制传感器实体允许您从您的 小米
支持的二进制传感器类型
支持的二进制传感器列表,包括以下属性(如果可用):名称、型号、Zigbee 实体、状态、事件、关键字和事件值。
-
运动传感器 (第一代)
- 型号:RTCGQ01LM
- Zigbee 实体:motion
- 状态:on, off
- 事件:
xiaomi_aqara.motion
-
运动传感器 (第二代)
- 型号:RTCGQ11LM
- Zigbee 实体:sensor_motion.aq2
- 状态:on, off
- 事件:
xiaomi_aqara.motion
-
小米门窗传感器 (第一代)
- 型号:MCCGQ01LM
- Zigbee 实体:magnet
- 状态:on, off
-
Aqara 门窗传感器 (第二代)
- 型号:MCCGQ11LM
- Zigbee 实体:sensor_magnet.aq2
- 状态:on, off
-
烟雾探测器
- 型号:JTYJ-GD-01LM/BW
- Zigbee 实体:smoke
- 状态:on, off
-
燃气泄漏检测器
- 型号:JTQJ-BF-01LM/BW
- Zigbee 实体:natgas
- 状态:on, off
-
水漏传感器
- 型号:SJCGQ11LM
- Zigbee 实体:sensor_wleak.aq1
- 状态:on, off
-
按钮(第一代)
- 型号:WXKG01LM
- Zigbee 实体:switch
- 状态:on (通过长按触发), off
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
long_click_press
,hold
,single
,double
-
按钮(第二代)
- 型号:WXKG11LM
- Zigbee 实体:sensor_switch.aq2, remote.b1acn01
- 状态:on (通过长按触发), off
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
,double
,long_click_press
,hold
-
按钮(第二代,型号 b)
- 型号:WXKG12LM
- Zigbee 实体:sensor_switch.aq3
- 状态:off (始终)
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
,double
,long_click_press
,shake
-
Aqara 无线开关 (单开)
- 型号:WXKG03LM
- Zigbee 实体:86sw1
- 状态:off (始终)
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
-
Aqara 无线开关 (双开)
- 型号:WXKG02LM
- Zigbee 实体:86sw2
- 状态:off (始终)
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
,both
-
Aqara 无线开关 (单开) (第二代)
- 型号:WXKG03LM
- Zigbee 实体:remote.b186acn01
- 状态:off (始终)
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
,double
,long
-
Aqara 无线开关 (双开) (第二代)
- 型号:WXKG02LM
- Zigbee 实体:remote.b286acn01
- 状态:off (始终)
- 事件:
xiaomi_aqara.click
- 事件关键字:
click_type
- 事件值:
single
,double
,long
,both
,double_both
,long_both
-
立方体
- 型号:MFKZQ01LM
- Zigbee 实体:cube
- 状态:off (始终)
- 事件:
xiaomi_aqara.cube_action
- 事件关键字:
action_type
,action_value
(旋转) - 事件值:
flip90
,flip180
,move
,tap_twice
,shake_air
,swing
,alert
,free_fall
,rotate
(度数在 action_value)
-
振动传感器
- 型号:DJT11LM
- Zigbee 实体:vibration
- 状态:off (始终)
- 事件:
xiaomi_aqara.movement
- 事件关键字:
movement_type
- 事件值:
vibrate
,tilt
,free_fall
二进制传感器的自动化示例
运动
- alias: "如果有运动且光线较暗,则开启网关灯"
triggers:
- trigger: state
entity_id: binary_sensor.motion_sensor_158d000xxxxxc2
from: "off"
to: "on"
conditions:
- condition: numeric_state
entity_id: sensor.illumination_34ce00xxxx11
below: 300
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_34ce00xxxx11
data:
brightness: 5
- action: automation.turn_on
target:
entity_id: automation.MOTION_OFF
- alias: "如果没有运动超过5分钟,则关闭网关灯"
triggers:
- trigger: state
entity_id: binary_sensor.motion_sensor_158d000xxxxxc2
from: "on"
to: "off"
for:
minutes: 5
actions:
- action: light.turn_off
target:
entity_id: light.gateway_light_34ce00xxxx11
- action: automation.turn_off
target:
entity_id: automation.Motion_off
门窗二进制传感器
- alias: "如果窗户打开,则关闭散热器"
triggers:
- trigger: state
entity_id: binary_sensor.door_window_sensor_158d000xxxxxc2
from: "off"
to: "on"
actions:
- action: climate.set_operation_mode
target:
entity_id: climate.livingroom
data:
operation_mode: "关闭"
- alias: "如果窗户关闭超过5分钟,则再次打开散热器"
triggers:
- trigger: state
entity_id: binary_sensor.door_window_sensor_158d000xxxxxc2
from: "on"
to: "off"
for:
minutes: 5
actions:
- action: climate.set_operation_mode
target:
entity_id: climate.livingroom
data:
operation_mode: "智能计划"
- alias: "离家时如果门被打开则通知"
triggers:
- trigger: state
entity_id: binary_sensor.door_window_sensor_15xxxxxxc9xx6b
from: "off"
to: "on"
conditions:
- condition: state
entity_id: group.family
state: "not_home"
actions:
- action: notify.notify_person
data:
message: "门已被打开"
烟雾
- alias: "火警时发送通知"
triggers:
- trigger: state
entity_id: binary_sensor.smoke_sensor_158d0001574899
from: "off"
to: "on"
actions:
- action: notify.html5
data:
title: "火警!"
message: "检测到火灾/烟雾!"
- action: xiaomi_aqara.play_ringtone
data:
gw_mac: xxxxxxxxxxxx
ringtone_id: 2
ringtone_vol: 100
燃气
- alias: "燃气警报时发送通知"
triggers:
- trigger: state
entity_id: binary_sensor.natgas_sensor_158dxxxxxxxxxx
from: "off"
to: "on"
actions:
- action: notify.html5
data:
title: "燃气警报!"
message: "检测到密度为 {{ state_attr('binary_sensor.natgas_sensor_158dxxxxxxxxxx', 'density') }} 的燃气。"
小米无线按钮
小米无线按钮有3个版本:
- 对于圆形按钮,可用的事件为
single
,double
,hold
,long_click_press
和long_click_release
。 - Aqara 品牌按钮是方形的。型号 WXKG11LM 仅支持
single
,double
,long_click_press
和hold
事件。WXKG12LM 支持single
,double
,long_click_press
和shake
事件。
对 Aqara 版本而言,生成双击所需的两个点击之间的延迟必须大于圆形按钮。点击过快会生成单击事件。
- alias: "单击切换餐厅灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: single
actions:
- action: switch.toggle
target:
entity_id: switch.wall_switch_left_158d000xxxxx01
- alias: "双击切换沙发灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: double
actions:
- action: switch.toggle
target:
entity_id: switch.wall_switch_right_158d000xxxxx01
- alias: "长按让狗吠"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: long_click_press
actions:
- action: xiaomi_aqara.play_ringtone
data:
gw_mac: xxxxxxxxxxxx
ringtone_id: 8
ringtone_vol: 8
小米立方体
可用事件为 flip90
, flip180
, move
, tap_twice
, shake_air
, swing
, alert
, free_fall
和 rotate
。该集成将最后一个动作存储为属性 last_action
。
- alias: "立方体事件 flip90"
triggers:
- trigger: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_15xxxxxxxxxxxx
action_type: flip90
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_28xxxxxxxxxx
data:
color_name: "springgreen"
- alias: "立方体事件 flip180"
triggers:
- trigger: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_15xxxxxxxxxxxx
action_type: flip180
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_28xxxxxxxxxx
data:
color_name: "darkviolet"
- alias: "立方体事件 move"
triggers:
- trigger: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_15xxxxxxxxxxxx
action_type: move
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_28xxxxxxxxxx
data:
color_name: "gold"
- alias: "立方体事件 tap_twice"
triggers:
- trigger: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_15xxxxxxxxxxxx
action_type: tap_twice
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_28xxxxxxxxxx
data:
color_name: "deepskyblue"
- alias: "立方体事件 shake_air"
triggers:
- trigger: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_15xxxxxxxxxxxx
action_type: shake_air
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_28xxxxxxxxxx
data:
color_name: "blue"
Aqara 无线开关
Aqara 无线开关有单键和双键两个版本。每个键的行为类似于无线按钮,仅限于单击事件 single
。双键版本添加一个名为 binary_sensor.wall_switch_both_158xxxxxxxxx12
的第三个设备,如果同时按下两个键,则报告一个名为 both
的单击事件。
- alias: "降低网关灯的亮度"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.wall_switch_left_158xxxxxxxxx12
click_type: single
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_34xxxxxxxx13
data:
brightness: >-
{% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') %}
{% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') - 60 >= 10 %}
{{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') - 60}}
{% else %}
{{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness')}}
{% endif %}
{% else %}
10
{% endif %}
- alias: "增加网关灯的亮度"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.wall_switch_right_158xxxxxxxxx12
click_type: single
actions:
- action: light.turn_on
target:
entity_id: light.gateway_light_34xxxxxxxx13
data:
brightness: >-
{% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') %}
{% if state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') + 60 <= 255 %}
{{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness') + 60}}
{% else %}
{{state_attr('light.gateway_light_34xxxxxxxx13', 'brightness')}}
{% endif %}
{% else %}
10
{% endif %}
- alias: "关闭网关灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.wall_switch_both_158xxxxxxxxx12
click_type: both
actions:
- action: light.turn_off
target:
entity_id: light.gateway_light_34xxxxxxxx13
振动传感器
该自动化根据振动/倾斜切换客厅灯。
- alias: "振动时打开客厅灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.movement
event_data:
entity_id: binary_sensor.vibration_xxxx000000
movement_type: vibrate
actions:
- action: light.toggle
target:
entity_id: light.living_room_lamp
- alias: "倾斜时打开客厅灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.movement
event_data:
entity_id: binary_sensor.vibration_xxxx000000
movement_type: tilt
actions:
- action: light.toggle
target:
entity_id: light.living_room_lamp
传感器
传感器实体允许您从您的 小米
支持以下传感器类型:
- 电池电量 (百分比)
- 床活动 / 振动 (以微米为单位)
- 坐标
- 湿度 (百分比)
- 光照 (以勒克斯为单位)
- 耗电量 (以千瓦时为单位)
- 电力负载 (以瓦特为单位)
- 压力 (以 hPa 为单位)
- 温度 (取决于 UI 设置,摄氏度或华氏度)
- 倾斜角度
开关
开关实体允许您从您的 小米 aqara
操作
网关提供以下操作:
操作 xiaomi_aqara.play_ringtone
播放特定的铃声。网关固件的版本必须至少为 1.4.1_145
。请查看以下示例。
数据属性 | 可选 | 描述 |
---|---|---|
gw_mac |
否 | 小米 Aqara 网关的 MAC 地址 |
ringtone_id |
否 | 允许的铃声 ID之一 |
ringtone_vol |
是 | 音量百分比 |
允许的 ringtone_id
值包括:
- 警报
- 0 - 警车 1
- 1 - 警车 2
- 2 - 事故
- 3 - 倒计时
- 4 - 鬼
- 5 - 狙击步枪
- 6 - 战斗
- 7 - 空袭
- 8 - 狗吠
- 门铃
- 10 - 门铃
- 11 - 敲门
- 12 - 娱乐
- 13 - 闹钟
- 闹钟
- 20 - MiMix
- 21 - 热情洋溢
- 22 - 吉他经典
- 23 - 冰雪世界钢琴
- 24 - 休闲时光
- 25 - 童年
- 26 - 晨曲流
- 27 - 音乐盒
- 28 - 橙色
- 29 - 思考者
- 自定义铃声 (通过米家应用上传) 从 10001 开始
操作 xiaomi_aqara.stop_ringtone
立即停止正在播放的铃声。
数据属性 | 可选 | 描述 |
---|---|---|
gw_mac |
否 | 小米 Aqara 网关的 MAC 地址 |
操作 xiaomi_aqara.add_device
在 30 秒内启用小米 Aqara 网关的加入权限。之后可以通过按下配对按钮一次添加新设备。
数据属性 | 可选 | 描述 |
---|---|---|
gw_mac |
否 | 小米 Aqara 网关的 MAC 地址 |
操作 xiaomi_aqara.remove_device
移除特定设备。如果要将设备与其他网关配对,则需要进行此移除。
数据属性 | 可选 | 描述 |
---|---|---|
gw_mac |
否 | 小米 Aqara 网关的 MAC 地址 |
device_id |
否 | 要移除的设备的硬件地址 |
示例
长按智能按钮第一代
此示例使按钮被按下时播放狗吠声,并在按钮被单击时停止声音。仅适用于第一代圆形按钮。
注意:声音将在播放结束后自动停止。
- alias: "长按让狗吠"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: long_click_press
actions:
- action: xiaomi_aqara.play_ringtone
data:
gw_mac: xxxxxxxxxxxx
ringtone_id: 8
ringtone_vol: 8
- alias: "单击立即停止吠叫"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: single
actions:
- action: xiaomi_aqara.stop_ringtone
data:
gw_mac: xxxxxxxxxxxx
双击智能按钮
此示例在按钮双击时切换客厅灯。
- alias: "双击切换客厅灯"
triggers:
- trigger: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000xxxxxc2
click_type: double
actions:
- action: light.toggle
target:
entity_id: light.living_room_lamp
故障排除
初始设置问题
如果在应用程序中初始化网关时遇到麻烦,请尝试另一部智能手机。例如,在 OnePlus 3 上未能成功,但在 Nexus 5 上成功。
连接问题
2017-08-20 16:51:19 ERROR (SyncWorker_0) [homeassistant.components.xiaomi] 未发现网关
2017-08-20 16:51:20 ERROR (MainThread) [homeassistant.setup] 设置失败:组件初始化失败。
这意味着 Home Assistant 没有收到来自小米网关的任何响应。可能是本地网络问题或防火墙问题。
- 确保您 启用了 LAN 访问
。 - 关闭运行 Home Assistant 的系统上的防火墙。
- 确保您的路由器支持多播,因为这是小米网关的要求。
- 尝试禁用然后启用 LAN 访问。
- 硬重置网关:长按网关的按钮 30 秒,然后从头开始重新开始。
- 如果您在 Docker 中运行 Home Assistant,请确保使用
--net=host
。 - 如果您在尝试控制网关灯时收到了
{"error":"Invalid key"}
的错误日志- 您应该使用 Android 手机重新生成密钥,或者使用像 bluestacks
的模拟器。在某些情况下,使用 iOS 应用生成密钥可能出现问题。 - 您需要确保您的网络支持多播。如果您在虚拟机中运行 Home Assistant (如 Proxmox),请尝试在主机上运行
echo 0 >/sys/class/net/vmbr0/bridge/multicast_snooping
并重启服务或重启主机。
- 您应该使用 Android 手机重新生成密钥,或者使用像 bluestacks
- 如果所需库 “PyXiaomiGateway” 无法安装,您需要手动安装一些缺少的系统依赖项
python3-dev
、libssl-dev
、libffi-dev
(例如,$ sudo apt-get install python3-dev libssl-dev libffi-dev
)。
如果您的网关 MAC 地址以 04:CF:8C
或 7C:49:EB
开头,网关上的所需端口 9898
可能是关闭的,因此此方法不适用。在线有解决方法,但这需要焊接和电力工作。