[RELEASE] Xiaomi Aqara Mijia Sensors and Switches Driver

I've put together a combined driver that I use for a list of these devices:

  • Xiaomi Aqara Contact Sensor : MCCGQ11LM [*]
  • Xiaomi Aqara Motion Sensor : RTCGQ11LM [*]
  • Xiaomi Aqara Temperature Sensor : WSDCGQ11LM
  • Xiaomi Aqara Vibration Sensor : DJT11LM [*]
  • Xiaomi Aqara Water Leak Sensor : SJCGQ11LM [*]
  • Xiaomi Aqara Wireless Double Remote Switch : WXKG02LM [*]
  • Xiaomi Aqara Wireless Mini Switch : WXKG11LM
  • Xiaomi Aqara Wireless Mini Switch with Gyroscope : WXKG12LM [*]
  • Xiaomi Aqara Wireless Single Remote Switch : WXKG03LM [*]
  • Xiaomi Mijia Door and Window Sensor : MCCGQ01LM
  • Xiaomi Mijia Human Body Sensor : RTCGQ01LM
  • Xiaomi Mijia Light Sensor : GZCGQ01LM
  • Xiaomi Mijia Wireless Switch : WXKG01LM [*]

[*] These devices have an internal temperature sensor, though with only rough accuracy

The driver may well work for other device hardware versions.

I know there are other drivers available but I put this together because I wanted to reduce the plethora of drivers for these devices and to simplify the code since the functionality of these devices are generally hard-coded in the firmware without the possibility of further configuration.

I've been running this driver for a couple of months now without any major issues. YMMV :slight_smile:

You can either install the driver from the github repository below or use HPM and look for "Xiaomi Aqara Mijia Sensors and Switches" or "Jonathan Michaelson".

Note: Some of the devices are not supported in depth. For example, the vibration sensor support is fairly basic and does not break down all of the available functionality of the device.

29 Likes

Very nicely done. Just did some testing with motion, works great!

Only thing I added was a way to clear the states. When changing from 'other' drivers, there can be leftover junk stored in the states.

Would love to see this in Hubitat Package Manager.

To clear the states, I simply added in the metadata:

command "WipeDevice"

Then added to the bottom of the driver:

def WipeDevice() {
    if (debugLogging) log.warn "Wiping Device"
    state.clear()
    unschedule()
}

Makes the device page nice and clean. :wink:

9 Likes

Cool! Very nice work! I did some testing with all my sensor's and i can confirm that: Xiaomi motion sensors, Aqara motion sensors, aqara temperature and humidity sensors, xiaomi contact sensors and aqara contact sensors works like a charm. Xiaomi smart button (Mi wireless switch, model: WXKG01LM) doesn't work...
Debug and info messages in log:
2021-01-12 15:58:21.927 [info] Bottone Xiaomi Salotto contact changed to closed

2021-01-12 15:58:21.925 [debug] cluster:0006, attrId:0000

2021-01-12 15:58:21.922 [debug] Incoming data from device : read attr - raw: 53500100060800001000, dni: 5350, endpoint: 01, cluster: 0006, size: 08, attrId: 0000, encoding: 10, command: 0A, value: 00

2021-01-12 15:58:20.520 [info] Bottone Xiaomi Salotto contact changed to open

2021-01-12 15:58:20.518 [debug] cluster:0006, attrId:0000

2021-01-12 15:58:20.504 [debug] Incoming data from device : read attr - raw: 53500100060800001001, dni: 5350, endpoint: 01, cluster: 0006, size: 08, attrId: 0000, encoding: 10, command: 0A, value: 01

1 Like

To keep it simple, I've added the state and schedule cleaning functionality to the configure button.

I will look at integrating with HPM.

4 Likes

I don't have a WXKG01LM and it looks like it has its own quirks, so I'll see if I can get hold of one.

1 Like

Let me know if i can help you

I've got one on order plus a couple of others to integrate. They'll take a while to arrive.

1 Like

I got two Aqara Temperature sensors (WSDCGQ11LM) today. One for inside and one for outside. (I know they are not made for outside use). I reset them and installed the "Xiaomi/Aquara Combined Driver" and put one outside. It's about -3.0 C (26.6 F) now. As soon as the sensor passed 0 C (32F) it jumped to 654.96 C.
I took it back in and let it get back to room temperature and then I put both in the freezer to see if they read the same. At 0 C both jumped to about 655 C.
Not saying it's the drivers, I haven't tried any other yet. Just thought I would mention it.

Thanks for this, playing around w/the driver w/Aqara contact sensors.

One interesting thing...one shows battery and voltage, the other does not. Is this just a timing issue? They one that is showing battery and voltage has been paired longer than the other one.

image

image

They're not very reliable on reporting their battery (voltage). You cannot force them to update it through zigbee commands as you can with others. They ought to report it every hour but sometimes, nothing. When that happens, it can sometimes take a few goes at re-pairing them to get them to report regularly.

EDIT: I just unwrapped a brand new open/close sensor. The first pair didn't report the battery either. I then paired it again (no need to remove the device first) and it then started reporting battery voltage (3.06v)

It would help to enable debug output and post the "Incoming data from device" from the log just before the temp report (it will have a cluster id of 0402).

Also make sure to set your temp scale in HE > Location and Modes > Temp Scale > Update.

That voltage is odd, since the battery in the contact sensor is meant to be cr1632 which is 3v :open_mouth:

1 Like

Yes, I had noticed that and forgot to mention it. Maybe I have a super contact sensor! :wink:

1 Like

I've just pushed out a new version that should fix that as it happened to my new sensor too :laughing:. Well, it should fix it for the next time it decides to update the voltage report.

1 Like

Sorry to be a pain but is there any way you could put in the lines of code as suggested by @bptworld in post 2.
Makes it very easy to swap drivers.
Thanks.

1 Like

Both now reporting normally...

image

2021-01-12 13_16_01-Aqara 2 Contact Sensor

He did. :wink:

2 Likes

Blast. Did a quick scan but didn't see it.
Oops. :blush:

3 Likes

Sorry this is very new to me. :blush:
The temp scale is correct.

Before it reached zero degrees:


dev:208
2021-01-12 22:34:00.886 infoOutside Temp and Humidity temperature changed to 0.01°C

dev:2082021-01-12 22:34:00.874 infoOutside Temp and Humidity humidity changed to 16.32

dev:2082021-01-12 22:34:00.867 debugcluster:0405, attrId:0000

dev:2082021-01-12 22:34:00.849 debugIncoming data from device : read attr - raw: 5D670104050A0000216006, dni: 5D67, endpoint: 01, cluster: 0405, size: 0A, attrId: 0000, encoding: 21, command: 0A, value: 6006

dev:2082021-01-12 22:34:00.803 debugcluster:0402, attrId:0000

dev:2082021-01-12 22:34:00.795 debugIncoming data from device : read attr - raw: 5D670104020A0000290100, dni: 5D67, endpoint: 01, cluster: 0402, size: 0A, attrId: 0000, encoding: 29, command: 0A, value: 0100

And after:


dev:208
2021-01-12 22:34:11.223 infoOutside Temp and Humidity temperature changed to 654.46°C

dev:2082021-01-12 22:34:11.218 debugcluster:0402, attrId:0000

dev:2082021-01-12 22:34:11.196 debugIncoming data from device : read attr - raw: 5D670104020A000029A6FF, dni: 5D67, endpoint: 01, cluster: 0402, size: 0A, attrId: 0000, encoding: 29, command: 0A, value: A6FF

Well, if you are sure it's not 645 deg outside... Thanks for the debug data, I know where the problem is. I'll have a fix tomorrow after I put a sensor in my freezer to confirm it!

3 Likes