How to use Aqara Hub M2 devices in Home Assistant?

There are differentAqara Hub M2 gateways available in the market, these is compatible with the hom assistant
Aqara Hub M2 gateway gen 1
August of 2020

that hunger was finally sated as the M2 officially launched in China
Product model:ZHWG12LM Chinese version

Aqara Hub M2 gateway gen 2

Product model:ZHWG17LM Chinese version

Aqara Hub M2 gateway gen 3

16th December 2022 - M2 (2022) M2 2022 edition(cn)

that hunger was finally sated as the M2 (2022) officially launched in China.

Aqara has announced a updated M2(2022) hub for the Chinese market

Product model: ZHWG19LM (Chinese versionl)

the Aquara M2 is not a Xiaomi product so it shouldn’t work with Xiaomi HA integration.
The M2 is a full Aqara product.

you can add it using the HomeKit Controller integration and it has been very stable, no issues at all.

1 Like

Aqara Hub M2 gateway 1 gen 1

Product Name:  Hub M2 
Model Number:  ZHWG12LM (China model)
Product Model Variant:  ZHWG12LM
internal model :lumi.gateway.iragl5
Brand:  Lumi United Technology Co., Ltd
Category:  Hub
Last Certified Date:  
Firmware version: 3.5.0_0013.0636 2022-12-15, 4.0.0_0021.0636  2023-03-09 4.0.2_0010.0644 2023-06-20

Firmware Version History:

This gateway only supported the Zigbee 3.0 protocol

Aqara Gateway

HomeKit Controller

Hass recognizes automatically as HomeKit Controller.
No need for gateway key or lan access mode.

Xiaomi Gateway (Aqara) integration
not supported

Aqara Hub M2 gateway gen 3

Product Name:  Hub M2 2022
Model Number:  ZHWG19LM (China model)
Product Model Variant:  ZHWG19LM
internal model :lumi.gateway.iragl8
Brand:  Lumi United Technology Co., Ltd
Category:  Hub
Last Certified Date:  2022-03-02

how to add Aqara M2 gateway to home assistant?

way1. you can add the M2 via the HomeKit Controller integration.
I have added it as a homekit controller and it has been very stable, no issues at all.

step need below integration
step 2.add your Aqara M2 in aqara home app


  • Aqara dosn’t officially support HA, and they dont seems to intend so either, i’ve had contact with them in regards to IR-supporti, and it seems like they dont really care which functions that don’t work outside there APP

  • Please note that Aquara M2 is not a Xiaomi product so it shouldn’t work with Xiaomi HA integration.

The Xiaomi Gateway(Aqara) integration is not working for M2
hub Xiaomi Gateway (Aqara) - Home Assistant

source:When I am adding the M2 using a new integration, although I type the IP address and/or the MAC address, HA fails to see the unit and gives me the following error: Invalid hostname or IP address

for ios user

1. First install the Aqara iOS App and register the M2 Hub, this should add to HomeKit. Then add all accessories.
2. After that remove the M2 from Apple Home app’s HomeKit. Don’t use the 10 second reset button to do this.
3. Got to HA and install the HomeKit-Controller via [ ]( It will find the M2 and its accessories and add to HA.
4. Your iOS app should still have it loaded



The Aqara hub M2 doesn't support the multicast network protocol implemented in xiaomi_aqara.

Please use the homekit_controller to integrate the device


use a modified firmware:

-Whats your point ? … you just line up various CHN versions, a month ago, and now you state that M2(no version mentioned) doesn’t work in Xiaomi Aqara ( which the docs also seems to indicate )
Lots of people in here have M2, in various Zigbee-capable integrations.
Have you bothered to search this forum ? , for your specific device, or just Aqara M2 for that matter ?


I too have am using the integration option via HomeKit. This has been very stable with the compromise of losing control of the hub via the Aqara app. The result is that I’ve not updated the M2’s firmware in about 9 months.

Does anyone know how to upgrade the firmware on the M2 in this configuration? I would like to add the FP2 and, from what I understand, a firmware update is required.

upgrade aqara home app    v 4.0  , 4.0.9  2023-10-26,4.1.1  2023-11-17,4.1.2 2023-11-24,4.1.4 2023-12-16,4.1.7,2024-1-23
upgrade the firmware in aqara home app
region server:china server (china version)

firmware Version: 0034 2023-07-07

aqara home app latest version information:Aqara Home-小米应用商店

Thank you for the quick reply! Are these commands executed from within HA?

Could anyone confirm whether Aqara Hub M2 exposes its Alarm system to Home Assistant when integrating via HomeKit controller?
I don’t believe a HomeKit hub (M2) would connect to two controllers (Home Assistant and native Apple Home app) simultaneously, or will it? If it does then I suppose my first question is redundant.

I want to buy Aqara A100 smart lock (homekey Is one of the reasons) and if I were to complement it with the M2 hub I’d like to use the hub as an alarm system. But I do need that alarm system in Apple Home for Siri and Apple Watch controls while I also need the sensors in Home Assistant. I use plenty of Aqara/xiaomi motion/door/water sensors for home automation in HA (currently connected via Z2M and sonoff zigbee gateway) so I could move (some of) them to the M2 hub which would allow me to get rid of Eufy security system that doesn’t work overly well with either HA or HomeKit.
If it only pairs with one controller, then I would pair it with HA to get the sensors and (if supported) alarm control panel which would in turn be exposed to Apple Home via HomeKit bridge where I could control it via Siri and Apple Home app. I know I could use HA own alarm control panel without the M2 hub but I’d prefer to have alarm separate to HA for redundancy (Aqara app at least, ideally also Home bypassing HA) as I find HA not quite as reliable as standalone hubs.

M2 Alarm “default” in Homekit-C
entity: alarm_control_panel.aqara_hub_m2_a59a_security_system

So yes on 1.
I think NO on 2.

1 Like

Thanks a lot for prompt response! So my idea should be viable(ish). I just noticed a comment above saying that integration with HA(or HomeKit in general) removes the hub from Aqara app, is that right?
Just wonder how the lock would work in this case (don’t suppose you have one), whether “pass through” to Home app via HA would maintain the same level of functionality as direct pairing from M2 to Home app. I guess worst case i could have m2 paired with Home and use a few standalone motion sensors with m2 for alarm only, not ideal but should work (unlike Eufy).

Well, i still have my devices, thou the hubs-alarm-function in the app, is only available for automations/scenes made in the app, and it’s ofcause then cloud-depended, but when you arm/disarm Alarm etc in HA/Homekit-C, it’s not reflected in the app :frowning: ( i haven’t any scenes/automation in app for the alarm, thou i have some “notification-alarm-automations”, for some temperatures/motion-sensors, set in the phone-app only, but have these devices in automations in ha).
You can still update firmware in the hub via app, it’s still an accessory in the app, and you can add remote-controlls, (IR remote-controlls are not supported in Homekit-C), set/se Hub-settings etc

No, no locks here, but i guess locks maybe works as i.e a switch, if they are on/off it will be reflected in the app, regardless if it’s by HA, manuel/automatic, or the app

PS: i stand corrected … i just “configured” Alarm-Alert in the phone-app(home-alert, away-alert,night-alert), and placed a “card” in “HomeBoard” Now i see the status of the alarm, set in HA, and can also change “mode” and/or disable, in both HA and from phone(and view the Alert-log in phone-app)
( Thou im pretty sure such a “config” in the phone will drain the battery, but it was fun testing :grin: )

Thanks for the details, this helps a lot! :slight_smile:
For me the use of Aqara app would be limited to Alarm alerts. I just want those to work in case if HA hangs or an integration falls off. Though now that I’m reading this, I am starting to realise that I might be trying to do something silly. When Hub is connected to HomeKit, it would actually make sense for the app to suppress alarms as they will duplicate Home app’s alarms. I had it previously with Eufy alarm system, (where the integration with HA was through a cloud integration so the app wouldn’t know it was connected to HomeKit) and whele alerts were redundant just how I wanted it was also quite annoying :slight_smile:

Sounds like I should be able to get it working acceptably so just need to try it out in different ways. I’ll share the results some time later. Hopefully when Matter is supported it will be even easier. Thanks again!

If Locks works as i suspect, you could create an i.e “Away-Alert” (on the phone)
i.e, " if Lock change to Open, Alert " (ofcause the Lock, then also need to be an accessory in the Hub/Phone-app)

When you then enable the Alarm “Away” in HA , the Alarm status in your phone will change to “Away” and the “Away-Alert” in the phone-app will start running

I received the M2 hub today. After spending a few hour and almost going crazy, finally I think I figured it out. I must say Aqara app is a piece of something, but once set up it all looks more or less OK.

So Aqara app on iOS kind of forces you to integrate the hub with Apple Home straight away (natively, not with HA). It just doesn’t have any other options when you’re adding the hub, you have to do that to proceed. If you remove Aqara app’s permissions to see Home in iOS, it will not allow you to proceed until you allow it. I am not sure whether it’d still be possible to integrate m2 with Home Assistant via HomeKit controller actually. May be using iOS device without a connected Home would allow that but seems like the iOS app is totally designed for HomeKit.
I suppose this behaviour may be dependant on app and hub’s firmware version, mine is 4.0.4_something.

Then for some reason the hub was not showing in the Aqara app while it was visible in Apple Home app but you can’t add sensors and other accessories through HomeKit directly. That was a waste of two hours before I got anywhere. I tried adding it on Android platform, android version of Aqara app is just godawfully terrible. I was eventually able to add the hub but only when connected via Ethernet as android app is so messed up you can’t see the dialogs to configure wifi (not that I care, but someone else might). Not sure if that actually made any difference, but after adding the hub one more time via iOS app it finally appeared in both Apple Home and Aqara app (but disappeared on Android, omg this is silly), so I was finally able to add a motion sensor. It could have been some weird sync issue in the app, or may be I just needed to logout and back in but terrible UX anyway.

Then I spent another couple of hours trying to figure out how to actually trigger the alarm. You can turn the alarm on an off from HomeKit but there’s no way to trigger it from HomeKit or to configure how it is triggered as this is a job of he alarm system, not HomeKit.
boheme61 I should have read your post about the “cards” again sooner (thanks for that, it saved me from going crazy). I actually had to add a “Card” in Aqara app to create triggers for each mode, and it indeed sync the status of the alarm between Aqara and HomeKit. Funnily enough it doesn’t look like there’s a way to disarm (set to Off) the alarm from Aqara app, only switch between 4 modes (away/home/hight/24x7). Another little UX glitch.

So what I found:

  • I can’t quite see how to integrate M2 with HA via HomeKit controller anymore. It technically should work, but the Aqara app just forces you to do HomeKit integration with native Home app, eliminating the option of discovering the hub later via Home Assistant’s HK controller. I have not tried discovering it from HA directly without using Aqara app while hub is in pairing mode, but even if it works it won’t be viable as the app is still needed to manage the hub. I noticed that it maintains sensor connections after re-pairing with HK, so perhaps adding the sensors via app and then resetting the network would do the trick but it sounds way too hard.

  • The M2 hub does indeed expose Alarm control to HomeKit. All notifications are managed by HomeKit, so if HomeKit is dead I’m not sure Aqara app alone would provide any notification redundancy (what I wanted). This shouldn’t be too bad though, HK is pretty reliable.

  • The M2 hub supports Matter, and can be integrated with Home Assistant via Matter! I will expose sensors to HA via Matter, and to Home via HomeKit integration. So you can integrate with HA and Home simultaneously after all, this is great! but HomeKit may get duplicating sensors. I have not renewed HK-bridge integration yet, if it does it can cause some inconvenience later.

  • The Matter integration does NOT expose alarm to HA. This unfortunate. Those who want to use M2 hub exclusively with HA might be out of luck, at least for now. I can work around that by syncing a logical switch (or an HA’s own alarm panel) from HomeKit via an automation in HomeKit itself. This won’t eliminate the dependancy on HomeKit but will allow additional automations in HA when alarm triggers.

  • The trigger in Aqara have all modes including 24x7 (the is all configured via “card” ) and you can select which sensors will be used in each mode. E.g. water sensors in 24x7 and motion/door sensors in Home/Away mode etc. There are configurable delays before arming and before triggering so sensors won’t spam you while you’re leaving house (my pain with Eufy). This looks good, pretty much just how it should be. The only thing I noticed was lack of any audible feedback while the alarm is in delay mode before trigger, would be good to have a reminder (the only thing Eufy does better) to turn the alarm off but probably this can be just automated via presence detection or lock.

So the M2 hub should work quite fine as an Alarm system for HomeKit (native Apple app) and simultaneously as a bridge to HA for connected sensors. But if not for the smart lock (haven’t received that yet), I’d not bother with M2 hub and just create alarm automations directly in Home Assistant using its own alarm control panel which can be exposed to HomeKit. The M2 hub might be more reliable (yet to be seen) than my instance of Home Assistance, but additional complexity doesn’t justify it In my opinion.

As i never had an iphone, i only have my experience from android( and most mobile apps sucks, both in UX, and options :slight_smile: )

Have you tried to “toggle”, i.e if the alarm is set to “away” then click on “away”, in the phone-app ?

Again experience from Android, But i don’t think you need your phone-app at all to integrate the M2-hub in HA
Start over, Close your Phone AP, then go to “/integrations” in HA(not from your phone) , plug out your M2-hub, for few seconds, plug it in again, then HA should discover it(or click to get pair-mode on the hub), if Homekit-Integration turns up Click-Ignore !, if Homekit-Controller don’t turn up, click Add-Integration, i can’t see why that shouldn’t work, regardless of what app the hub is configured/setup in.

Thou thanks for the info about “Homekit-Integration”, and Iphone/Apple, Not that i think i will ever use either :slight_smile:


Once you add the hub to Home Kit, simply delete the entry it creates in the Apple Home Kit app and instantly (and I mean instantly) the device will be discovered in Home Assistant via the Homekit controller integration.


I’ve just managed to add my aqara M2 to Home Assistant. However, I current has an Aircon remote control (RF) linked to the M2 on Aqara App. Is it possible for the remote controller to be linked to HA as well?

no. these commands executed from within aqara home app

The really interesting questiion for me is: where to find the code to configure the M2 (SW 4…0.4)

The 8 digit code printied on the bottom of the device neither has the format xxx-xx-xxx required by HA nor did it work when I tried it. I tried adding the hyphens to the code as well as typing the 8 digits without hyphens.

The code obviously works with my device as scanning the code from the aqara app on the ipad did the job of connecting it to the Home app of the ipad.

Anyideas? Anyone? please.

kind regards