MCPcopy Index your code
hub / github.com/AlexxIT/XiaomiGateway3

github.com/AlexxIT/XiaomiGateway3 @v4.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.4 ↗ · + Follow
790 symbols 2,555 edges 63 files 75 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Xiaomi Gateway 3 for Home Assistant

hacs_badge

Home Assistant custom component for control Xiaomi Multimode Gateway (aka Gateway 3), Xiaomi Multimode Gateway 2, Aqara Hub E1 on default firmwares over LAN.

Gateway Model Supported
Xiaomi Multimode Gateway (CN) ZNDMWG03LM yes
Xiaomi Multimode Gateway (EU) ZNDMWG02LM, YTC4044GL yes
Xiaomi Multimode Gateway 2 (CN) DMWG03LM yes
Xiaomi Multimode Gateway 2 (EU) ZNDMWG04LM, BHR6765GL yes
Aqara Hub E1 (CN) ZHWG16LM yes
Xiaomi Gateway 2 (CN) DGNWG02LM no, goto
Xiaomi Gateway (EU) DGNWG05LM no, goto

Other. Aqara Hub E1 (EU), Aqara G2H (CN), Aqara H1 (CN), Aqara M1S (CN), Aqara M2 (CN), Aqara P3 (CN) | HE1-G01, ZNSXJ12LM, QBCZWG11LM, ZHWG15LM, ZHWG12LM, KTBL12LM - no, goto

Thanks to @Serrj for instruction how to enable Telnet on old firmwares. And thanks to an unknown researcher for instruction how to open telnet on new firmwares.


Supported Firmwares

Gateway Firmwares Required
Xiaomi Multimode Gateway (CN/EU) 1.5.0 - 1.5.4 only Token
Xiaomi Multimode Gateway 2 (CN/EU) 1.0.3 - 1.0.6 only Token
Aqara Hub E1 (CN) 4.0.1 only Token
Xiaomi Multimode Gateway (CN/EU) 1.5.5 - 1.5.6 Token and Key
Xiaomi Multimode Gateway 2 (CN/EU) 1.0.7 Token and Key

PS. Firmwares from 1.4.6 to 1.4.7 for Xiaomi Multimode Gateway may work but UNSUPPORTED. Please don't create issues if something doesn't work on them.

PS. For "only Token" firmwares integration will get Key automatically and save it to integration settings and to /config/.storage/xiaomi_gateway3/keys.json. Please save it safely somewhere else.

Recommended firmwares: - Xiaomi Multimode Gateway (CN/EU) - 1.5.4 - 1.5.6 - Xiaomi Multimode Gateway 2 (CN/EU) - 1.0.6 - 1.0.7 - Aqara Hub E1 (CN) - 4.0.1

HOWTO get token read here

HOWTO get key

Gateway Situation Solution
Xiaomi Multimode Gateway (CN/EU) firmware 1.5.4 and lower setup integration and use only Token
Xiaomi Multimode Gateway 2 (CN/EU) firmware 1.0.6 and lower setup integration and use only Token
Aqara Hub E1 (CN) firmware 4.0.1 and lower setup integration and use only Token
Xiaomi Multimode Gateway (CN/EU) firmware 1.5.5 and more, but shipped from the factory with firmware 1.4.6 and lower use button click method
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
Xiaomi Multimode Gateway (CN/EU) firmware 1.5.5 and more, never worked in the Hass use UART
Xiaomi Multimode Gateway 2 (CN/EU) firmware 1.0.7 and more, never worked in the Hass use UART
Aqara Hub E1 (CN) firmware 4.0.4 and more, never worked in the Hass no solution
  • Read more https://github.com/AlexxIT/Blog/issues/13

For Xiaomi Multimode Gateway you also can:

Please, not ask me why you need it.

Supported Devices

Gateway Zigbee chip can work in three modes:

1. Mi Home (default)

  • Support Xiaomi/Aqara Zigbee devices simultaneously in Mi Home and Hass
  • Support some Zigbee devices from other brands only in Hass

2. Zigbee Home Automation (ZHA)

3. Zigbee2mqtt

Zigbee devices in ZHA or z2m modes doesn't controlled by this integration!

Xiaomi BLE and Mesh devices works simultaneously in Mi Home and Hass. No matter which zigbee mode is used.

Matter devices supported only for Xiaomi Multimode Gateway 2 (EU) with fw 1.0.7_0019 and higher.

Some BLE devices may or may not have battery data depending on the device firmware.

Gateway entity shows connection state to gateway. It has many useful information in attributes.

Zigbee, BLE, Mesh and Matter devices has optional zigbee, ble, mesh, matter that shows last_report time in state and may useful intormation in attributes.

Add new device

You can change the operation of an existing device or add support for any Xiaomi Zigbee, Xiaomi BLE, Xiaomi Mesh or any other brand Zigbee device by writing an external converter.

It is welcomed if you return a working converter to integration. You can create an issue or make a pull request.

Installation

HACS > Integrations > Plus > XiaomiGateway3 > Install

Or manually copy xiaomi_gateway3 folder from latest release to /config/custom_components folder.

Configuration

Settings > Integrations > Add Integration > Xiaomi Gateway3

If the integration is not in the list, you need to clear the browser cache.

You need to add integration two times:

  1. Cloud version. It used ONLY to load tokens and names for your devices from cloud.
  2. Gateway. It adds your gateway and all connected Zigbee, BLE and Mesh devices.

You may skip 1st step if you know token for you Gateway. If you have multiple Gateways - repeat step 2 for each of them.

You need gateway key only for Xiaomi Multimode Gateway on fw 1.5.5, read more.

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

Network configuration

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

  • Shared LAN between Gateway and Hass server. You may use VPN, but both IP-address should be in same network subnet!
  • Open ping (accept ICMP) from Gateway to Router
  • Fixed IP-address for Gateway on your Router
  • Wi-Fi Router settings:
  • Fixed channel from 1 to 11
  • Channel width: 20MHz (don't use 40MHz)
  • Authentication: WPA2 (don't use WPA3)
  • MikroTik Router settings:
  • Wireless > Security Profiles > Group Key Update: 01:00:00 (1 hour or more)
  • Keenetic Router settings:
  • Disable "Airtime Fairness" for 2.4GHz
  • Disable "256-QAM" for 2.4GHz

With the following settings the operation of the gateway may be unstable: different subnets, closed ping to router, Wi-Fi channel 40MHz, WPA3.

Regional Restrictions

Device MiHome EU MiHome CN Vevs EU Vevs CN
Gateway 3 (CN and EU) supported supported supported supported
Zigbee old series supported supported supported supported
Zigbee E1 series (CN and EU) no supported no supported
Zigbee H1 and T1 series (CN and EU) no partially no some models
Bluetooth BLE and Mesh some models supported supported supported

Xiaomi Mijia Smart Multi-Mode Gateway has two models - ZNDMWG03LM (China) and ZNDMWG02LM/YTC4044GL (Euro). Both this models can be added to China or to Euro cloud servers.

PS. This is the ONLY Xiaomi/Aqara gateway that has the same internal model for the China and Euro versions - lumi.gateway.mgl03. So the Hass component and the Xiaomi cloud servers see no difference between the models.

Most older Xiaomi/Aqara Zigbee devices can also be added to China and to Euro cloud servers.

New Zigbee devices from E1 series can be added ONLY to China cloud servers. They supported in official Mi Home application.

New Zigbee devices from H1 and T1 series are not officially supported in Mi Home. But they can be added ONLY to China cloud servers. You can controll them from Hass (check supported list) but not from stock Mi Home application. Some of this model (mostly H1 switches and T1 relays) can be controlled from Mi Home by Vevs.

Some of Bluetooth BLE and Mesh can be added ONLY to China cloud. But with Mi Home by Vevs they can be added to any cloud.

PS. You can't add Zigbee devices E1/H1/T1 to Euro cloud even with Mi Home by Vevs.

If you control your devices from Home Assistant - it makes absolutely no difference which cloud they are added to. Devices are controlled locally and without delay in any case.

PS. Some Aqara devices are not supported at all in Mi Home in any version, e.g. Aqara Door Lock N100 Zigbee version.

Multiple Gateways

Integration support multiple gateways in one MiHome account.

Zigbee devices can be attached (paired) to only one gateway. I recommend to split your Zigbee network into several gateways, so it will be more stable. I recommend not to mix battery and powered devices in the same network.

Bluetooth BLE and Mesh devices can work simultaneously with all gateways. In this technology, there is no binding to the gateway.

If a user has more than one Bluetooth Mesh Gateway on the network - only one will send Bluetooth device data to the cloud. But this integration can continue to collect Bluetooth data from all gateways simultaneously and locally.

Device command select

Device info - displays device information in notification.

```yaml extra: cloud_fw: 2.1.1_0025 # device firmware from cloud integration cloud_name: Dev Presence Sensor 2 # device name from cloud integration did: '1005xxxxxx' # device ID from MiHome mac: 64:9e:31:xx:xx:xx market_brand: Linptech market_model: ES1ZB, linp.sensor_occupy.hb01 market_name: Presence Sensor ES1 rssi_54ef44xxxxxx: -69 # rssi for each gateway rssi_54ef55xxxxxx: -79

Core symbols most depended-on inside this repo

Shape

Method 459
Function 189
Class 142

Languages

Python100%

Modules by API surface

custom_components/xiaomi_gateway3/core/converters/zigbee.py92 symbols
custom_components/xiaomi_gateway3/core/device.py41 symbols
custom_components/xiaomi_gateway3/core/mini_mqtt.py34 symbols
custom_components/xiaomi_gateway3/core/converters/base.py29 symbols
custom_components/xiaomi_gateway3/core/converters/silabs.py28 symbols
custom_components/xiaomi_gateway3/core/xiaomi_cloud.py25 symbols
custom_components/xiaomi_gateway3/core/mini_miio.py25 symbols
custom_components/xiaomi_gateway3/core/converters/lumi.py25 symbols
custom_components/xiaomi_gateway3/core/converters/mibeacon.py24 symbols
custom_components/xiaomi_gateway3/core/gate/base.py22 symbols
tests/test_conv_ble.py21 symbols
custom_components/xiaomi_gateway3/light.py21 symbols

For agents

$ claude mcp add XiaomiGateway3 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page