Why to Integrate Xiaomi Gateway with Home Assistant
Xiaomi Mi Home Gateway (Aqara Gateway, Mi Gateway 3, and others) is a central element of Xiaomiβs smart home ecosystem that manages sensors, switches, and other devices using the Zigbee protocol. However, the standard Mi Home app limits functionality: no time-of-day automation, complex scenarios, or integration with other brands. Here comes Home Assistant, an open smart home platform that allows you to combine all devices into a single system.
Connecting Xiaomiβs gateway to Home Assistant offers several key benefits:
- π Local management without dependence on the Xiaomi cloud (works even when the Internet is disconnected).
- π οΈ Advanced automation with the use of YAML-Scripts, triggers and conditions.
- π Detailed analytics: event logs, energy consumption graphs, sensor response history.
- π Integration with other systems (Google Home, Alexa, Apple HomeKit via Home Assistant).
In this article, we will discuss three ways to connect: through the official Xiaomi Miio plugin, an alternative Zigbee2MQTT (for advanced users), and the Mi Home Auto cloud bridge. You will also learn how to avoid typical errors (for example, Device not found or problems with the Zigbee network) and optimize the system.
Method 1: Connect via the official Xiaomi Miio plugin
The easiest method is to use the built-in integration of Xiaomi Miio into Home Assistant, which supports most Xiaomi/Aqara gateways and allows you to control connected devices (motion sensors, temperature sensors, buttons, etc.) without additional manipulation, but this method has a limitation: you need a cloud account Mi Home and a stable Internet connection for initial authorization.
To connect:
- Open the Home Assistant web interface and go to Settings β Devices & Services β Add Integration.
- Enter the username and password from the Mi Home account (make sure that the account is linked to the mainland region of China - this is critical!).
- Select the gateway from the list of detected devices. If the gateway does not appear, check that it is connected to the same Wi-Fi network as the Home Assistant server.
βοΈ Preparing for connection via Miio
π‘
If you have an Invalid credentials error when you log in, try changing your Mi Home password and using a new one, sometimes by logging out on all devices.
Once successfully connected, the Home Assistant will have entities to manage the gateway and its devices, such as:
- π media_player.xiaomi_gateway β lock-control.
- π‘οΈ sensor.xiaomi_temperature β temperature-sensing.
- πͺ binary_sensor.xiaomi_motion β motion-sensorship.
β οΈ Note: The official Xiaomi Miio integration does not support Zigbee devices from third parties (e.g., from Tuya or other devices). IKEA). If you want complete freedom in the selection of sensors, consider the method of using the Zigbee2MQTT.
Method 2: Connect via Zigbee2MQTT (for advanced)
If you want to completely abandon the Xiaomi cloud and manage devices locally, the best option is to use Zigbee2MQTT. This method requires more effort, but gives you complete control over the Zigbee network, support for devices from other brands and high stability.
- π₯οΈ Home Assistant Server (Available on Raspberry Pi, NAS PC).
- π Zigbee adapter (recommended) CC2531, CC2652 or ConBee II).
- π¦ Installed by Mosquitto Broker (MQTT-server Zigbee2MQTT.
Adjustment steps:
- Connect the Zigbee adapter to the server and check that it is defined by the system (the command ls /dev/tty* should show the device, for example, /dev/ttyACM0).
- Install Zigbee2MQTT via HACS or manually (instructions on the official website).
- Open the configuration file configuration.yaml and add:
zigbee2mqtt:
data_path: /config/zigbee2mqtt
external_converters: []
devices: devices.yaml
advanced:
network_key: GENERATE_NEW_KEY_ON_FIRST_START
mqtt:
base_topic: zigbee2mqtt
server: mqtt://localhost
serial:
port: /dev/ttyACM0 # replace with your port
adapter: zstackNext, you need to reset the Xiaomi gateway to factory settings and connect it to Zigbee2MQTT as a new device:
| A model of a lock | Support for Zigbee2MQTT | Features |
|---|---|---|
| Mi Gateway 3 | β Yes. | Requires firmware with ZNP support (use adapter: zstack) |
| Aqara Gateway E1 | β Yes. | Better compatibility, recommended for new systems |
| Mi Gateway 1/2 | β οΈ Partially. | There may be problems with the new generation of Aqara sensors |
What if the gateway is not connected to Zigbee2MQTT?
Method 3: Cloud Bridge Mi Home Auto (alternative for beginners)
If the first two methods seemed complicated, you can use an intermediate solution β Mi Home Auto. This is a cloud bridge that syncs devices from Mi Home with Home Assistant without the need to configure Zigbee or MQTT.
Instructions for setting:
- π± Install the Mi Home Auto app on your smartphone (available for Android and iOS).
- π Log in to your Mi Home account and select a gateway to sync.
- π₯οΈ In Home Assistant, add Mi Home Auto integration HACS manually.
- π Enter the access token generated in the mobile application.
Once connected, all gateway devices will appear in Home Assistant as prefixed entities. mi_home_auto. For example:
- switch.mi_home_auto_plug_158d0001234567 β plug-in.
- binary_sensor.mi_home_auto_motion_158d0001234568 β motion-sensor.
β οΈ Warning: Mi Home Auto cloud bridge does not support local scenarios. If the Internet goes down, automation will stop working. Zigbee2MQTT.
Typical errors and their solutions
When connecting Xiaomi gateway to Home Assistant, users often face the following problems:
| Mistake. | Reason. | Decision |
|---|---|---|
| Device not found in Xiaomi Miio | Gateway not on the same network as Home Assistant, or blocked by firewall | Check Wi-Fi connection 2.4 GHz, disable VPN, add exception to firewall for port 54321 |
| Failed to connect to MQTT broker | Mosquitto Broker or incorrect configuration.yaml settings are not running | Check the status of the Mosquitto service with the systemctl status mosquitto team |
| Gateway connects, but sensors don't show up | Devices are not tied to the gateway in the Mi Home app | Add sensors to Mi Home, then reboot integration to Home Assistant |
| Zigbee network is down in Zigbee2MQTT | Adapter problems or Zigbee channel conflict with Wi-Fi | Change the Zigbee channel in the settings (11 or 25 are recommended to minimize interference) |
If the devices are unstable after connecting (for example, temperature sensors are updated every 10 minutes instead of 1 minute), check the following points:
- πΆ Zigbee signal level: the gateway should be in the center of the house, not in the corner. Zigbee2MQTT signal-level (LQI).
- β‘ Gateway power: Some models are sensitive to unstable voltage. USB-feed-in.
- π Conflicts with other Zigbee devices: If you have other hubs (like Philips Hue), they can interfere with your network.
π‘
For stable operation of Zigbee-network avoid using channels 15-20 β they intersect with Wi-Fi at 2.4 GHz. Optimal channels: 11, 20, 25.
Optimizing the Gateway in Home Assistant
After a successful connection, several steps are recommended to improve performance and reliability:
- Turn off cloud sync in the Mi Home app if you are using Zigbee2MQTT. This will reduce delays and reduce the load on the gateway.
- Configure backup configuration Zigbee2MQTT. To do this, add to configuration.yaml:
zigbee2mqtt:
backup_path: /config/zigbee2mqtt_backups- Create automation for critical devices, for example, if the smoke detector is triggered, turn on the siren and send a notification to the phone:
automation:
- alias: "Fire alarm"
trigger:
platform: state
entity_id: binary_sensor.smoke_sensor
to: "on"
action:
- service: switch.turn_on
entity_id: switch.siren
- service: notify.mobile_app_iphone
data:
message: "β οΈ Smoke sensor is activated!"So for ease of control, you can group the devices into rooms, for example, all the sensors in the bedroom can be grouped together. group.sensors_bedroom:
group:
sensors_bedroom:
name: Bedroom sensors
entities:
- binary_sensor.bedroom_motion
- sensor.bedroom_temperature
- sensor.bedroom_humidityπ‘
If you have a lot of Zigbee devices, consider buying a Zigbee router (like IKEA Tradfri or Aqara Range Extender) that will increase network range and reduce the load on the gateway.