Skip to content

Commit 22947ff

Browse files
author
niceboy
committed
Add the support of Aqara Gateways
1 parent cb999b4 commit 22947ff

File tree

20 files changed

+1794
-45
lines changed

20 files changed

+1794
-45
lines changed

README.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Home Assistant custom component for control **Xiaomi Multimode Gateway** (aka Ga
1111
| Xiaomi Multimode Gateway 2 (CN) | DMWG03LM | **yes** |
1212
| Xiaomi Multimode Gateway 2 (EU) | ZNDMWG04LM, BHR6765GL | **yes** |
1313
| Aqara Hub E1 (CN) | ZHWG16LM | **yes** |
14+
| Aqara Gateway M2 PoE (CN) | ZHWG19LM | **yes** See Note |
15+
| Aqara Camera Hub G3 CN | ZNSXJ13LM | **yes** See Note |
16+
| Aqara Gateway M3 (CN) | ZHWG24LM | **yes** See Note |
17+
| Aqara Hub M100 (CN) | ZHWG24LM | **yes** See Note |
18+
| Aqara Gateway M200 (CN) | AG047GLB02 | **yes** See Note |
19+
| Aqara Doorbell G410 (CN) | ZNKSML05 | **yes** See Note |
1420
| Xiaomi Gateway 2 (CN) | DGNWG02LM | **no**, [goto][1] |
1521
| Xiaomi Gateway (EU) | DGNWG05LM | **no**, [goto][2] |
1622

@@ -20,13 +26,15 @@ Home Assistant custom component for control **Xiaomi Multimode Gateway** (aka Ga
2026
[2]: https://openlumi.github.io/
2127
[3]: https://github.com/niceboygithub/AqaraGateway
2228

29+
Note: Only Zigbee supported. Manually add the gateway that enabled telnet and use "aiot" or "aqara" as Token
30+
2331
Thanks to [@Serrj](https://community.home-assistant.io/u/serrj-sv/) for [instruction](https://community.home-assistant.io/t/xiaomi-mijia-smart-multi-mode-gateway-zndmwg03lm-support/159586/61) how to enable Telnet on old firmwares. And thanks to an unknown researcher for [instruction](https://gist.github.com/zvldz/1bd6b21539f84339c218f9427e022709) how to open telnet on new firmwares.
2432

2533
---
2634

2735
* [Supported Firmwares](#supported-firmwares)
2836
* [Supported Devices](#supported-devices)
29-
* [Add new device](#add-new-device)
37+
* [Add new device](#add-new-device)
3038
* [Installation](#installation)
3139
* [Configuration](#configuration)
3240
* [Network configuration](#network-configuration)
@@ -83,7 +91,7 @@ Recommended firmwares:
8391
| Xiaomi Multimode Gateway (CN/EU), Xiaomi Multimode Gateway 2 (CN/EU), Aqara Hub E1 (CN) | worked previously in the Hass, but you updated it to latest firmware | [use button click method](https://github.com/AlexxIT/Blog/issues/13) |
8492
| Xiaomi Multimode Gateway (CN/EU) | firmware 1.5.5 and more, never worked in the Hass | [use UART](https://github.com/AlexxIT/XiaomiGateway3/issues/1057) |
8593
| Xiaomi Multimode Gateway 2 (CN/EU) | firmware 1.0.7 and more, never worked in the Hass | [use UART](https://github.com/AlexxIT/XiaomiGateway3/issues/1166) |
86-
| Aqara Hub E1 (CN) | firmware 4.0.4 and more, never worked in the Hass | no solution |
94+
| Aqara Hub E1 (CN) | firmware 4.0.4 and more, never worked in the Hass | use button click method |
8795

8896
- Read more https://github.com/AlexxIT/Blog/issues/13
8997

@@ -102,7 +110,7 @@ Gateway Zigbee chip can work in three modes:
102110

103111
- Support Xiaomi/Aqara Zigbee devices simultaneously in Mi Home and Hass
104112
- Support some Zigbee devices from other brands only in Hass
105-
113+
106114
**2. Zigbee Home Automation (ZHA)**
107115

108116
- Support for [Zigbee devices of hundreds of brands](https://zigbee.blakadder.com/zha.html) only in Hass ([read more](#zigbee-home-automation-mode))
@@ -150,9 +158,9 @@ You may skip 1st step if you know token for you Gateway. If you have multiple Ga
150158

151159
You need gateway `key` only for Xiaomi Multimode Gateway on fw 1.5.5, [read more](https://github.com/AlexxIT/Blog/issues/13).
152160

153-
**ATTENTION:** If you using two Hass with one gateway - you should use same integration version on both of them!
161+
**ATTENTION:** If you using two Hass with one gateway - you should use same integration version on both of them!
154162

155-
## Network configuration
163+
## Network configuration
156164

157165
All settings are **important** or you may have an unstable operation of the gateway.
158166

@@ -165,7 +173,7 @@ All settings are **important** or you may have an unstable operation of the gate
165173
- Authentication: WPA2 (don't use WPA3)
166174
- MikroTik Router settings:
167175
- Wireless > Security Profiles > Group Key Update: **01:00:00** (1 hour or more)
168-
- Keenetic Router settings:
176+
- Keenetic Router settings:
169177
- Disable "[Airtime Fairness](https://help.keenetic.com/hc/en-us/articles/360009149400)" for 2.4GHz
170178
- Disable "[256-QAM](https://help.keenetic.com/hc/en-us/articles/4402854785170)" for 2.4GHz
171179

@@ -248,7 +256,7 @@ params: # all decoded params in one message
248256
occupancy: false
249257
occupancy_duration: 0
250258
ttl: 50m # time to live (TTL) - available timeout (maximum last_seen value)
251-
uid: 649e31xxxxxx # hass UID - "12 hex mac" for BLE and Mesh, "0x + 16 hex IEEE" for Zigbee
259+
uid: 649e31xxxxxx # hass UID - "12 hex mac" for BLE and Mesh, "0x + 16 hex IEEE" for Zigbee
252260
```
253261
254262
**Device update** - manual call for device params update. Don't work for many Zigbee battery devices. Don't work for all BLE devices. Don't work for offline Mesh devices.
@@ -556,7 +564,7 @@ Read more in [wiki](https://github.com/AlexxIT/XiaomiGateway3/wiki/Handle-BLE-Lo
556564

557565
## Xiaomi Multimode Gateway beeper
558566

559-
You can run beeper/buzzer with service:
567+
You can run beeper/buzzer with service:
560568

561569
- duration in seconds
562570
- volume from 1 to 3
@@ -606,7 +614,7 @@ After rebooting the gateway, all changes will be reset. The component will launc
606614

607615
## Troubleshooting
608616

609-
Put your Gateways and your child bluetooth/zigbee devices far away from **USB 3.0 devices and cables, SSDs, WiFi routers**, etc. USB3 hub can almost completely block the Zigbee signal from your Xiaomi Plug up to 20 centimeters away.
617+
Put your Gateways and your child bluetooth/zigbee devices far away from **USB 3.0 devices and cables, SSDs, WiFi routers**, etc. USB3 hub can almost completely block the Zigbee signal from your Xiaomi Plug up to 20 centimeters away.
610618

611619
[![](https://img.youtube.com/vi/tHqZhNcFEvA/mqdefault.jpg)](https://www.youtube.com/watch?v=tHqZhNcFEvA)
612620

@@ -674,42 +682,42 @@ logger:
674682

675683
## FAQ
676684

677-
**Q. Does this integration support Xiaomi Robot Vacuum, Xiaomi Philips Bulb...?**
685+
**Q. Does this integration support Xiaomi Robot Vacuum, Xiaomi Philips Bulb...?**
678686
A. No. The integration does not support Xiaomi Wi-Fi devices.
679687

680-
**Q. Which Mi Home region is best to use?**
688+
**Q. Which Mi Home region is best to use?**
681689
A. Most devices are supported in the China region. In European regions the new Zigbee devices E1/H1/T1-series and some Mesh devices may not work. Read more about [regional restrictions](#regional-restrictions).
682690

683-
**Q. What do multimode gateway beeps mean?**
691+
**Q. What do multimode gateway beeps mean?**
684692
A. Beeps AFTER adding Zigbee devices:
685693
1. No new devices found, the pair is stopped.
686694
2. New device successfully added.
687695
3. Unsupported device model.
688696

689-
Also, if you are using hacked motion sensor - the gateway will periodically beeps. You can [disable it](https://github.com/AlexxIT/XiaomiGateway3/issues/919).
697+
Also, if you are using hacked motion sensor - the gateway will periodically beeps. You can [disable it](https://github.com/AlexxIT/XiaomiGateway3/issues/919).
690698

691-
**Q. Does the integration work without internet?**
699+
**Q. Does the integration work without internet?**
692700
A. Partially. The component connects to a hub on the local network. Adding new devices from/to Mi Home requires Internet.
693701

694-
**Q. Does the integration support non Xiaomi Zigbee devices?**
702+
**Q. Does the integration support non Xiaomi Zigbee devices?**
695703
A. Yes. There are three ways to connect third party Zigbee devices. All methods have a different set of supported devices. There is no exact supported list. Don't expect absolutely every device on the market to be supported in any of these methods.
696704

697-
**Q. Will the Zigbee devices continue to work in Mi Home?**
705+
**Q. Will the Zigbee devices continue to work in Mi Home?**
698706
A. Yes. If you do not enable ZHA or z2m mode, the devices will continue to work in Mi Home. And you can use automation in both Mi Home and Hass.
699707

700-
**Q. Do I need to receive a token or enable Telnet manually?**
708+
**Q. Do I need to receive a token or enable Telnet manually?**
701709
A. No. The token is obtained automatically using the login / password from the Mi Home account. Telnet turns on automatically using token.
702710

703-
**Q. Should I open or solder the hub?**
711+
**Q. Should I open or solder the hub?**
704712
A. No.
705713

706-
**Q. Should I use ZHA mode?**
714+
**Q. Should I use ZHA mode?**
707715
A. You decide. If all of your Zigbee devices are supported in Mi Home, it is best to use it. If you have two hubs - you can use one of them in Mi Home mode, and the second in ZHA mode. Or you can also use the hub in Mi Home mode with Xiaomi devices and a Zigbee USB Dongle for other Zigbee devices.
708716

709-
**Q. How many Zigbee devices does the hub support?**
717+
**Q. How many Zigbee devices does the hub support?**
710718
A. The hub can connect directly up to 32 battery-powered devices (end devices). And **additionaly** up to 26 powered devices (routers). Other devices on your network can work through routers. The maximum number of devices is unknown. Official Xiaomi documentation writes about 128 devices.
711719

712-
**Q. Why does the two-button switch only have one entity action?**
720+
**Q. Why does the two-button switch only have one entity action?**
713721
A. All button clicks are displayed in the status of that one entity.
714722

715723
## Useful links

custom_components/xiaomi_gateway3/core/converters/const.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,48 @@
6565
# lock: On means open (unlocked), Off means closed (locked)
6666
STATE_UNLOCK = True
6767
STATE_LOCKED = False
68+
69+
LOCK_NOTIFY = {
70+
3235774464: "Frequent door opening failures due to incorrect passwords", # 0xC0DE0000
71+
3235774465: "Frequent door opening failures due to incorrect fingerprints", # 0xC0DE0001
72+
3235774469: "Frequent door opening with abnormal keys", # 0xC0DE0005
73+
3235774470: "Foreign objects in the keyhole", # 0xC0DE0006
74+
3235774471: "Keys not removed", # 0xC0DE0007
75+
3235774472: "Frequent door opening failures with incorrect NFC", # 0xC0DE0008
76+
3235774473: "Door unlocked after timeout", # 0xC0DE0009
77+
3235774474: "Multiple verification failures (advanced protection)", # 0xC0DE000A
78+
3235778564: "Automatic lock body abnormal" # 0xC0DE1004
79+
}
80+
81+
GESTURE_MAP = {
82+
2: "Two",
83+
4: "Four",
84+
5: "Five",
85+
6: "Eight",
86+
10: "OK",
87+
101: "Both Two",
88+
102: "Both Four",
89+
103: "Both Four",
90+
104: "Both Eight",
91+
105: "Both OK"
92+
}
93+
94+
PETS_MAP = {
95+
0: "",
96+
1: "Cat",
97+
2: "Dog",
98+
3: "Cat or Dog"
99+
}
100+
101+
ALARM_INDEX_MAP = {
102+
0: "Police car 1",
103+
1: "Police car 2",
104+
2: "Safety accident",
105+
3: "Missile countdown",
106+
4: "Ghost scream",
107+
5: "Sniper rifle",
108+
6: "Battle",
109+
7: "Air raid alarm",
110+
8: "Dog bark",
111+
10000: "default"
112+
}

custom_components/xiaomi_gateway3/core/converters/lumi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def decode(self, device: "XDevice", payload: dict, value):
115115
elif self.attr == "key_id":
116116
payload["action"] = "lock"
117117
payload[self.attr] = value
118+
elif self.attr == "event":
119+
payload["action"] = "lock"
120+
payload["lock_event"] = self.map.get(value)
118121
elif self.attr == "alarm":
119122
v = self.map.get(value)
120123
if v != "doorbell":

custom_components/xiaomi_gateway3/core/core_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ async def gateway_info(host: str, token: str = None, key: str = None) -> dict |
4141
return None
4242

4343
# try to enable telnet and return miio info
44-
result = await enable_telnet(host, token, key)
44+
if token == "aiot" or token == "aqara":
45+
if not await check_port(host, 23):
46+
return {"error": "wrong_telnet"}
47+
return {"host": host}
48+
else:
49+
result = await enable_telnet(host, token, key)
4550

4651
# waiting for telnet to start
4752
await asyncio.sleep(1)

custom_components/xiaomi_gateway3/core/device.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .converters.base import BaseConv, decode_time, encode_time
1111
from .converters.lumi import LUMI_GLOBALS
1212
from .converters.zigbee import ZConverter
13-
from .devices import DEVICES
13+
from .devices import DEVICES, DEVICES_AIOT_ZIGBEE, DEVICES_AIOT_GATEWAY
1414

1515
if TYPE_CHECKING:
1616
from .gate.base import XGateway
@@ -236,7 +236,7 @@ def assert_extra(self):
236236
if ieee := self.extra.get("ieee"):
237237
assert RE_ZIGBEE_IEEE.match(ieee), ieee
238238
if did := self.extra.get("did"):
239-
if type in (GATEWAY, MESH):
239+
if type in (MESH):
240240
assert did.isdecimal()
241241
elif type == ZIGBEE:
242242
assert did.startswith("lumi.")
@@ -267,7 +267,15 @@ def init_converters(self):
267267
# support custom model from yaml
268268
model = self.extra.get("model") or self.model
269269

270-
for desc in DEVICES:
270+
devices = []
271+
if self.extra.get("cloud", "") == "aiot":
272+
if self.type == ZIGBEE:
273+
devices.extend(DEVICES_AIOT_ZIGBEE)
274+
if self.type == GATEWAY:
275+
devices.extend(DEVICES_AIOT_GATEWAY)
276+
devices.extend(DEVICES)
277+
278+
for desc in devices:
271279
# if this spec for current model
272280
if info := desc.get(model):
273281
self.extra["market_brand"] = info[0]

0 commit comments

Comments
 (0)