[RELEASE] Xiaomi Drivers with Health Status and Zigbee2MQTT

And now it has shown up in the states list.

Looks like I copied the right lines.

1 Like

Embarrassed - so sharing! I've a Xiaomi Aqara humidity sensor. Worked great for a long time, then I had issues with it and never learned why. Moving the devices' location seems to have helped.
When I moved it - I set it on its side. On the bottom are little 'slats' which I assumed were for air flow.
Since I wasn't mounting it with tape, I laid it on its side at the top of the shower. This worked for a long while and things settled. Last night, my bathroom light went on and woke me. it happened repeatedly all night - I closed the bathroom door and said 'f*k it'.
This AM I determined it was firing due to Smarter Humidity Fan - and the value of humidity was 70% and barely fluctuating.
I'd only changed the battery 2 weeks ago, so that wasn't it. Then I considered - what if it has gotten moisture inside? I turned it and set it with the slats on the bottom, and scotch taped it to the wall. I never once reset, or played with battery - and within 30 mins humidity dropped 20% and is still dropping says Grafana. So, I learned to not turn humidity sensor on their side - seems they can get water in them!


So, after ordering another sensor which was lost in transit, then being offered a replacement, then having 3 new sensors arrive 1 month later, I now have a few spares lol.

The battery was flat out of the box but I replaced it and proceeded to go through the exact same headache pairing it that I had with the first one. I tried close, far, holding the button for different amounts of time, my 10 month old even tried throwing it on the ground like everything else.

Each time it would pair but showed 0 lux values. Eventually I narrowed it down.
My smartthings hub. It was auto adding the sensor (according to the zigbee logging) but not properly pairing to it. So the sensor was trying to send it's lux data to ST with no device entry but pairing to my Hubitat hub with no data.
It also might be that I waited until the blue light on the sensor flashed 3 times THEN let go of the button when pairing it.
It also could just be sheer coincidence. It paired perfectly on the second attempt after unplugging the ST hub and all I did was hold the sensor button longer.

Hopefully this helps someone. Funnily enough, this is still not the hardest zigbee device I've had to pair. 3 words, Xiaomi Water Sensor

1 Like

@birdslikewires first I like to say many thanks for the drivers, I have tried many different that no longer are supported and I always got my Xiaomi sensors to drop of after a few weeks to months so now Im testing yours and so far so good. At first I missed some settings like replaced battery date, custom battery level but I think you have chosen the best battery percentage levels I have seen so far and I like that you can see the battery voltage also so now I don't feel like I miss anything.

The driver Im using is the Temp and Humidity sensor for WSDCGQ11LM but Im using it for my older WSDCGQ01LM without any problem. I have just made another version of it with modded fingerprint part and some other places just to match WSDCGQ01LM.

One thing I noticed was that you use 2 decimals for temp and humidity and I personally like one decimal, I think it looks better in my dashboards at least and I don't need 2 decimal accuracy :slight_smile: .
So I went in to se if I could change this to one decimal in your driver and found the code below.
What I noticed is that the setScale and rounding does not do anything since it's done before variable temperature is divided by 100 so there are no decimals and also from my understanding the sensors only report temp/humidity with 2 decimals so no need to round if showing 2 decimals.
To get one decimal working I changed it as seen below.

Your original code
		BigDecimal temperature = hexStrToSignedInt(temperatureFlippedHex)
		temperature = temperature.setScale(2, BigDecimal.ROUND_HALF_UP) / 100

On my sensors this was enough for temp and humidity with 2 decimals
		BigDecimal temperature = hexStrToSignedInt(temperatureFlippedHex) / 100

My change to get one decimal working
		BigDecimal temperature = hexStrToSignedInt(temperatureFlippedHex) / 100
		temperature = temperature.setScale(1, BigDecimal.ROUND_HALF_UP) 
1 Like

So for anyone interested I added the option to choose how many decimals you want to have from 0 to 2. Since I only have temp and humidity I didn't do it for pressure but should work the same I presume :upside_down_face:.

Changes I did were these, Im not a developer so it probably can be done in a better way but works for me.

  1. Add two inputs under preferences
  2. Set the two preferences to default values when running configure so they are not null
  3. Use preferences values when rounding and trimming the decimals and added null check just to be safe
    (Update after feedback from BirdLikeWires: added a check to only set default values if they are not already set)
preferences {
	input name: "infoLogging", type: "bool", title: "Enable logging", defaultValue: true
	input name: "debugLogging", type: "bool", title: "Enable debug logging", defaultValue: false
	input name: "traceLogging", type: "bool", title: "Enable trace logging", defaultValue: false
	input name: "tempDecimals", type: "enum", title: "Temperature decimals", defaultValue: 2, required: true, options: [[0:"0"],[1:"1"],[2:"2 (Default)"]]
	input name: "humidityDecimals", type: "enum", title: "Humidity decimals", defaultValue: 2, required: true, options: [[0:"0"],[1:"1"],[2:"2 (Default)"]]

void configureSpecifics() {
	// Called by main configure() method in BirdsLikeWires.xiaomi

	updateDataValue("encoding", "Xiaomi")
	device.name = "Xiaomi Aqara Temperature and Humidity Sensor WSDCGQ01LM"
	sendEvent(name: "numberOfButtons", value: 1, isStateChange: false)
	if (tempDecimals == null) device.updateSetting("tempDecimals", [value: "2", type: "enum"])
	if (humidityDecimals == null) device.updateSetting("humidityDecimals", [value: "2", type: "enum"])

		BigDecimal temperature = hexStrToSignedInt(temperatureFlippedHex) / 100
    	temperature = temperature.setScale((tempDecimals != null ? tempDecimals : 2).toInteger(), BigDecimal.ROUND_HALF_UP)

		BigDecimal humidity = hexStrToSignedInt(humidityFlippedHex) /100
		humidity = humidity.setScale((humidityDecimals != null ? humidityDecimals : 2).toInteger(), BigDecimal.ROUND_HALF_UP)

This is how it looks in preferences.

Example of zero to two decimals i Dashboard


Implemented your changes and it works fine. Thank you for sharing!


Careful, configure() is run whenever the driver is upgraded. Because your defaults are set in configureSpecific() your prefs will reset to two decimal places.

1 Like

Ahh thanks for the info, I changed so that it only sets temp/humidity preferences to default value if they are null.
It is not really needed but it feels better to have that then letting null pointer check catch it every time temp/humidity is updated if you haven't changed the preferences.

if (tempDecimals == null) device.updateSetting("tempDecimals", [value: "2", type: "enum"])
if (humidityDecimals == null) device.updateSetting("humidityDecimals", [value: "2", type: "enum"])

Just a short update, I noticed few issues in my code above.

  1. If using Fahrenheit then the rounding didn't work
  2. absoluteHumidity was calculated using rounded values.
    I have fixed this and at the same time forked birdslikewires driver for WSDCGQ11LM and made changes to support both Mijia WSDCGQ01LM and Aqara WSDCGQ11LM temp sensor in same driver.
    I only have the older WSDCGQ01LM so only been able to test that one but will borrow WSDCGQ11LM from a friend and test.

So if anyone want to test the decimal functionality it can be found here, but be aware the driver use birdslikewires libraries and goal is to contribute back to original driver.


@Ortovox Is this the default HE dashboard? If so, how do you get these compact tiles? Mine are all square unless I use up even MORE real estate and make them 2x wide. These look like 1/2 tall...

Yes that is default dashboard, I have just manually set width and height under dashboard options to 174 and 90 so it's close to 2:1 ratio.
If you have tiles with icons like switches then it will not fit, I then use something like 120 in height.

This is for it to match width of two tiles in my mobile phone but I think it look good in desktop also

All of these drivers have now been updated to support the healthStatus custom attribute, so will no longer misuse presence as a means of reporting device connectivity.

Use @kkossev's Device Health Status to give yourself a nice system overview.


Does anyone have a driver for aqara contact sensors that can be used with the integration?

Aqara produces 5 different contact (door & window) sensors : MCCGQ01LM MCCGQ11LM MCCGQ12LM MCCGQ13LM and MCCGQ14LM .
Which is yours ?

MCCGQ11LM and looking to use it with the Zigbee2MQTT routing driver

OK - the model will not matter then.

Hi all. I just installed the Xiaomi Aqara Temperature and Humidity Sensor WSDCGQ11LM. I am connected directly to a C7 hub using Zigbee. I note from the first post that the driver "Provides temperature, ... and battery reporting." I am not seeing the battery reporting ... any suggestions to get battery reporting would be appreciated.

I installed using the Hubitat Package Manager and the installed code header shows (comments removed):

  • Xiaomi Aqara Temperature and Humidity Sensor Driver
    @Field String driverVersion = "v1.15 (26th August 2023)"
    #include BirdsLikeWires.library
    #include BirdsLikeWires.xiaomi

My Device status shows no battery reporting:

Give it about 50 minutes to an hour and see if there is a battery report (the regular battery reporting interval). In my experience, if after an hour there isn't a report the sensor will need to be paired again.


Oh man!!! :grin: C'mon now ... You got the right answer faster than I had time to post the following ... "the sensor is reporting battery level now approximately 50 minutes after installation ... which is probably more like 60 minutes after I installed the battery."

As usual with this Hubitat community ... fast and accurate responses ... thanks to bjcowles for the support :clap:



First post updated! :slight_smile:

1 Like