[OBSOLETE] Xiaomi Sensors and Button (beta)

Can you share the complete code?

I got eight new xiaomi mija door window sensors today. I disconnected all hardwired zigbee utility’s, removed all sensors nearby the hub, powered down for 30 minutes without batteries, and tried to pair.
No luck, it’s impossible, before firmware update I could pair one in 10 seconds, and next one 10 sec, never had any problems pairing.
Now it is not possible to pair anything anymore.

Received 2 new Aqara Motion Sensors yesterday.
Paired easily. Didn’t use the catchall method, they appeared as a ‘Thing’.
Changed the DH to the correct one and they work just fine showing Lux%, motion and battery level.
I’m on the latest software build.
No issues here.

Issue seems to be a bit hit and miss.

the daughters that has worked for a few weeks has been showing as unobtainable all day
well since she left for school

might need to find some replacements if the new batch are as bad

I have some of the Mija sensors (new/boxed) at home so will give one of them a shot (not till the weekend though unfortunately). I had zero issues pairing the Aqara sensors when I tried a few days back.

Is the firmware the same on US and UK models ?

If you are talking about the hub, then yes. The latest hub firmware release is universal to all V2 hubs.

Just happily paired 3 aqara window sensors, all detected successfully.

Also paired a new aqara motion sensor using the catchall - I find it pops up as a thing about 50% of the time after I get the three flashes in a row.

Maybe the aqara version is better with the new firmware, I have always paired xiaomi door window, and xiaomi motion with button-presses/app. I have some aqara motion sensors on the way, then I can see if there is a difference.
You are on the latest firmware ?

as far as I know.

What you’ve done here is great. I wholeheartedly encourage you contribute this to one of the DTH we have here, from @a4refillpad or @ArstenA - alternatively, it would be great if A4 or Brian take this into their code.

Feels like the community really likes Xiaomi products, but it’s one of the least supported from a dev point of view. I wonder why we don’t have a clean, comprehensive library of DTH for all the great Xiaomi products?

Please keep up the good work A4 and Brian - we all appreciate it.


I will try to integrate these changes.

1 Like

Which sensor are these changes for?

1 Like

I posted it to my repo and am playing with it… you can try it. If you devices don’t pair with it I would be interested to see what your catchall line looks like. The fingerprint info I pulled from the catchall and then added it to get mine working. Let me know.

1 Like

They were for the Door/Window Aqara sensors.I’m still monitoring the data for the battery reporting. It looks good but hard to tell. I look at the data that is reported and there is only one field that actually changes on my sensor to signify any sort of battery drain. The field that is used in the other plugins are all 100 and the same across all 6 of my devices so it doesn’t make sense for me.

For now it works perfectly for MY sensors but would be curious if others have different catchall reply’s that could explain why it won’t pair easily. If they do, just have to add another fingerprint line with the details and it should work.

Just wanted to post an FYI… I’ve got the Second Gen Aqara temperature sensor that includes a pressure sensor. I didn’t see device handler that would support pressure sensor in this thread anywhere (maybe it is, I didn’t read the whole thread, but it is here:

I’ve gotten it working just fine.

Also as an FYI, I think the recent update to the hub has made the detection of these devices better. While trying to do the “Catch all” method, the devices just popped right up in the discovery screen of the app. No need to do the “Catch all” at all.


Is it possible to get an update on the Temp/Humidity sensor to be able to adjust the humidity offset? Mine are report 15% higher than actual…


what method of button press did you use to get yours to show up. I have 4 Temp sensors I had to use Catch all to find…

Hey guys,

My Xiaomi Temp & Humidity Sensor stopped reporting the temp for some time (humidity, battery and heartbeat are properly reported), maybe since the last hub firmware update. I found the following error messages in the Live Logger (IDE), each time the sensor is polled:

f3dff9ae-9346-4e28-8ed5-12:46:02 PM: debug Parse returned Guest room Temp & Humidity humidity is 32%
f3dff9ae-9346-4e28-8ed5-12:46:02 PM: debug Evencreated: humidity, 32, %
f3dff9ae-9346-4e28-8ed5- 12:46:02 PM: debug Parsevalue: 32
f3dff9ae-9346-4e28-8ed5- 12:46:02 PM: debug Parsename: humidity
f3dff9ae-9346-4e28-8ed5-12:46:02 PM: debug RAW: humidity: 32.37%
f3dff9ae-9346-4e28-8ed5-12:46:02 PM: error groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.math.BigDecimal#plus.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class java.lang.Character]
[class java.lang.String]
[class java.lang.Number]
[class java.math.MathContext]
f3dff9ae-9346-4e28-8ed5-12:46:02 PM: debug Parsename: temperature
f3dff9ae-9346-4e28-8ed5- 12:46:02 PM: debug RAW: temperature: 21.97

BigDecimal is called only once in A4refillpad.s handler, in parseValue function:

private String parseValue(String description) {

if (description?.startsWith("temperature: ")) {
	def value = ((description - "temperature: ").trim()) as Float 
    if (getTemperatureScale() == "C") {
    	if (tempOffset) {
			return (Math.round(value * 10))/ 10 + tempOffset as Float
        } else {
			return (Math.round(value * 10))/ 10 as Float
	} else {
    	if (tempOffset) {
			return (Math.round(value * 90/5))/10 + 32 + offset as Float
        } else {
			return (Math.round(value * 90/5))/10 + 32 as Float
} else if (description?.startsWith("humidity: ")) {
	def pct = (description - "humidity: " - "%").trim()
	if (pct.isNumber()) {
	return Math.round(new **BigDecimal**(pct)).toString()
} else if (description?.startsWith("catchall: ")) {
	return parseCatchAllMessage(description)
} else {
log.debug "unknown: $description"
sendEvent(name: "unknown", value: description)


Is any of you getting this error? Any idea about how to fix this?

I just got 5 of them, temp and humidity, in and really dont understand on how to pair them. All the instructions are in Chinese