Xiaomi Aqara Door/Window Sensor not visible


My problem: Xiaomi Aqara Door/Window Sensor is not visible in Home Assistant. It’s also missing in Entity Registry.

I have Aqara Gateway, several Aqara switches, Aqara Humidity/Temp sensor and Aqara Door/Window Sensor. This gateway does not support switching to development mode (i’m not able to use xiaomi_aqara component), but I was able to connect it on as an ‘HomeKit Accessory: Aqara Hub’. All devices except Window Sensor are visible and controllable.
When i’m using Mi Home app everything is OK.

My question: how to make Door/Window Sensor visible?
Thanks in advance.

I have the Xiaomi Gateway as well and had the same problem. Now sometimes some of the switches / door sensors mysteriously disappear.

The only thing that worked for me is reconnect the door/window sensor a couple of times (4) to the gateway and it automatically popped up in HA

Thanks for response.
I’ve tried to remove and add Door/Window sensor several times using Mi Home app, no effect in hass.
Did you restart hass/reload config? Did you restart Gateway?
It seems hass does not reload list of devices. I removed temperature sensor and it’s still shown in hass with unknown state.

At the very first try when i tried installing them i reconnected the door/window sensor and reseted the gateway. And the usual unplug it from the power supply and let it be for 30 seconds before putting it in the power socket.

Afterwards i restarted HA just to be sure and eventually it popped up.

Do you got the Aquara or the Mijia sensor. I’ve read that some of the people experienced some problems with the Aquara type.

I have an Aquara type, and finally I was able to make it working.
The problem was in the homekit_controller component. It ignores every binary sensor that is not ‘motion’.
I found out that Aqara Window/Door sensor is detected as ‘contact’ and created a patch (pasted below)
After this door sensor works as expected.
I’m not sure should I create a pull-request to hass or not, because it works for my configuration and may not work for other sensors.

--- a/homeassistant/components/homekit_controller/binary_sensor.py
+++ b/homeassistant/components/homekit_controller/binary_sensor.py
@@ -20,11 +20,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
     conn = hass.data[KNOWN_DEVICES][hkid]
     def async_add_service(aid, service):
-        if service['stype'] != 'motion':
-            return False
-        info = {'aid': aid, 'iid': service['iid']}
-        async_add_entities([HomeKitMotionSensor(conn, info)], True)
-        return True
+        if service['stype'] == 'contact':
+            info = {'aid': aid, 'iid': service['iid']}
+            async_add_entities([HomeKitWindowSensor(conn, info)], True)
+            return True
+        if service['stype'] == 'motion':
+            info = {'aid': aid, 'iid': service['iid']}
+            async_add_entities([HomeKitMotionSensor(conn, info)], True)
+            return True
+        return False
@@ -58,3 +64,34 @@ class HomeKitMotionSensor(HomeKitEntity, BinarySensorDevice):
     def is_on(self):
         """Has motion been detected."""
         return self._on
+class HomeKitWindowSensor(HomeKitEntity, BinarySensorDevice):
+    """Representation of a Homekit sensor."""
+    def __init__(self, *args):
+        """Initialise the entity."""
+        super().__init__(*args)
+        self._on = False
+    def get_characteristic_types(self):
+        """Define the homekit characteristics the entity is tracking."""
+        # pylint: disable=import-error
+        from homekit.model.characteristics import CharacteristicsTypes
+        return [
+            CharacteristicsTypes.CONTACT_STATE,
+        ]
+    def _update_contact_state(self, value):
+        self._on = value
+    @property
+    def device_class(self):
+        """Define this binary_sensor as a motion sensor."""
+        return 'door'
+    @property
+    def is_on(self):
+        """Has motion been detected."""
+        return self._on
diff --git a/homeassistant/components/homekit_controller/const.py b/homeassistant/components/homekit_controller/const.py
index f112737..de37e6b 100644
--- a/homeassistant/components/homekit_controller/const.py
+++ b/homeassistant/components/homekit_controller/const.py
@@ -19,6 +19,7 @@ HOMEKIT_ACCESSORY_DISPATCH = {
     'window': 'cover',
     'window-covering': 'cover',
     'lock-mechanism': 'lock',
+    'contact': 'binary_sensor',
     'motion': 'binary_sensor',
     'humidity': 'sensor',
     'light': 'sensor',

Wow! Great! Thanks for sharing!

Why this solution is not integrated in Home Assistant?

The Aqara door/window sensors MCCGQ11LM won’t appear in Home Assistant if you don’t modify that two files (components/homekit_controller/binary_sensor.py and components/homekit_controller/const.py) like @steck details.

PD: It will be great if you could place that two files for download in same place, so it will be easier for those who want implement this modification. Edit that files manually is quite tricky

1 Like

Can someone create a pull request for this? This way the devs will notice and hopefully integrate it!

it’s already done here but this PR has been merged.

1 Like

Thanks a lot @steck and @benasse that was a long time i wait for it!!! very good job @steck !

I have put back a motion sensor on a Aqara Hub and there is no info about the battery level for the entity…

On a Mio Gateway V3, the info exist…

Someone know if its a Hassio limitation?


I don’t have Aqara motion sensor, but a temperature sensor.
A low battery status is exposed via homekit, but it’s not taken in account by home assistant. It may be the same for motion senor.

1 Like