[OBSOLETE] Xiaomi Sensors and Button (beta)

Outstanding, TVM

The main disadvantage to using the “catchall” method is that in most cases, the device’s ZigBee ID is unknown to the SmartThings hub, and so the hub has no way to identify the device when it needs to be rejoined after dropping off the ZigBee mesh network.

A ZigBee ID is a unique 16-digit hexadecimal identifying string that is very similar to the MAC address used for IEEE 802 networks (i.e., Ethernet, WiFi, & Bluetooth). When a ZigBee device is paired with a hub, the device is supposed to send its ZigBee ID to the hub, and also the hub assigns a 4-digit hexadecimal Device Network ID (DNI) to the device (which functions similar to a IP address on a Ethernet / WiFi network).

If a device drops it’s connection with the hub for some reason, the DNI is unassigned, but if the device subsequently attempts to connect, the hub can use the device’s ZigBee ID to match to the device’s entry in the hubs device list, and assign it a new DNI.

Without any ZigBee ID, the hub has no way to match a disconnected device to its entry in the hubs device list. So both automatic rejoin and manual rejoin will fail. By manual rejoin, I mean when the user puts the hub and device in pairing mode in an attempt to rejoin it. Without the ZigBee ID information, the hub will decide it’s a “new” device, and the user has to set it and any of its automations up from scratch.

You can see whether a device’s ZigBee ID is known to the hub by logging into the SmartThings Groovy IDE and viewing the Device List Page:

As long as your device maintains it’s connection with the hub, not having the ZigBee ID isn’t a problem. So that’s why the “catchall” method works for many users. For others, due to interference or weak signal strength, they have issues that seem to indicate a lack of stability. Really it’s just that the hub can’t rejoin the sensor to the network.

In my testing, I have noticed that in rare cases, a Xiaomi / Aqara device will supply its ZigBee ID to the SmartThings hub after being paired using the “catchall” method. Also, it’s quite common for the ZigBee ID to show up in the Hub Events list (IDE > My Hubs > List Events) at the time when attempting to pair the device. It would be a 16-digit hexadecimal string beginning with 00158D (which indicates the manufacturer). Simply copy that entire 16-digit string, and then paste it into the hub’s device details for that device (IDE > My Devices > click Edit > paste string into “Zigbee Id” text field > click Update).

Actually there is a complete newer and updated set of DTHs for Xiaomi / Aqara devices, with links and discussion here:

All of these updated Xiaomi / Aqara DTHs correctly parse battery voltage data, and many improvements have been made both in functionality and features.

The updated Xiaomi “Original” Button DTH, which can be grabbed from here, uses the same method as a4refillpad’s DTH to emulate a button hold function, but with some changes in the code to improve reliability and accuracy. @MinerJason is 100% correct in saying that it can’t be fully reliable due to delays in SmartThing’s cloud execution of the DTH code, however.

Personally, I own both a SmartThings hub and a Hubitat Elevation hub, which executes all code locally, and having ported over all of the SmartThings DTHs to Hubitat can confirm that local execution makes a massive difference in reliability of the emulated button hold feature.

Honestly, if you are looking for the ability to do “long press” or button hold, I would choose another button besides the original round Xiaomi Button. I’d recommend an Aqara Button, but there are now three different revisions, and the only one guaranteed to provide hardware-based button hold that works on the SmartThings platform (using the updated DTH I mention above) is the Aqara Button model WXKG12LM.

1 Like

I’m not sure how rare it is. I know a lot of people like to fill in both the network id and zigbee id fields when using the catchall method (often with the same 4 digit network id), but I’ve always left the zigbee id blank. I find that if I leave it blank, and leave the device very close to the hub until the first check in (50-60 min for most Xiaomi devices), that the zigbee id will usually populate automatically within the first day or so. Absolutely agree that having the zigbee id helps tremendously in keeping devices connected long term.

Good to know! I like Brian’s xiaomi/aqara dth’s a lot, and currently use many of them. Last I tried that button dth didn’t have the emulated hold. I’ll have to take another look at it, because the improved battery reporting would be great!

I’ve been seriously considering moving towards Hubitat. The idea of local execution is really appealing to me for a variety of reasons.

Thanks. I ended up cutting the power to my only Zigbee repeater to complete the reregistration. Xiaomi Zigbee Door/Window Sensor, Motion Sensor, & Smart Button Device Type [beta]

Next time I will try the 30s battery removal and see if it can reconnect.

1 Like

I’ve read this thread well not al of it as so long. But I can find out I add them to SmartThings and to get it all to work. Can someone point immune into the right direction.

LOL. Sorry, but you’ve got a lot of reading to do!

I originally started with Original & Aqara Xiaomi Zigbee Sensors (contact, temp, motion, button, outlet, leak, etc) when I got my first Xiaomi device. I’m on Hubitat now, but I did pair a Xiaomi leak sensor using the information (somewhere) in it to pair the sensor shortly before I sold my SmartThings hub.

@MinerJason finally managed to get the hold press working on the Xiaomi button but the problem is for it turn a light off it needs me holding the button for at least 7/8 seconds, is there anyway to bring this down to say 2/3 seconds, I have looked in the device handler but not sure what to change in there.

Is it this part per chance, changing the 4 after default value, obviously thats a complete guess :slight_smile:

input (“holdTime”, “number”, title: “Minimum time in seconds for a press to count as “held””,
defaultValue: 4, displayDuringSetup: false)

That is the place in the code to set the default, but the DTH is written such that you can input whatever time you want without altering the code. It just uses 4 seconds as the default if you don’t specify anything else. Just open the device in the app, click the little gear icon in the upper right corner, and you should see where you can change the time setting.

Keep in mind that the cloud processing adds time, so this emulated hold function isn’t always reliable, and the actual time you need to hold it will vary slightly every time. I have mine set to 2 seconds, but it usually takes 2.5-3 seconds to actually trigger as “held”.

1 Like

FFS never realised that setting, ill give that a bash tonight, jesus wept @MinerJason I owe you about 3 million pints of lager for all your help here :slight_smile:


I have installed the Device handler for xiaomi smart plug and managed to pair it as well. Works great but now I bought couple other same xiaomi smart plugs.

Do i have to install new device handlers? Or can ride on the existing one since its the same bunch of codes anyways.

My newly bought xiaomi smart plugs are not working and blinking red. Pls help. Thanks

You only install the custom DTH once. When you pair the switch you can go in to the IDE and edit the new device and point it to the correct driver that you installed on the very first plug.
Sounds like the new ones just aren’t pairing automatically. You may be in the “Catchall” realm to get these guys online.

I have the Buttons but unfortunately they don’t work right. You have to hit it first to turn it on then again to activate unless you had used them recently then they stay on a while and only have to hit it once. Can this be right? Yes it is the Xiaomi standard button.

[UPDATE] “Original” Xiaomi Button DTH v1.3

(For Xiaomi’s round button, model WXKG01LM)

This release adds support for previously hidden functionality that is being “revealed” with firmware version 0.25.20. Because firmware 25.20 (which is being deployed starting March 6 2019) is required, this new DTH should only be used by SmartThings Hub v2 and v3 users.

[UPDATE] Aqara Button DTH v1.4b BETA

(For models WXKG11LM (original / new revisions) and WXKG12LM

This release fixes “broken” functionality for the original revision of Aqara Button model WXKG11LM due to a change in firmware version 0.25.20 (which is being deployed starting March 6 2019). However, this new DTH also adds multi-click functionality for the same Aqara Button model, which was not available in previous firmware versions.

NOTE: These updated DTHs only work with Firmware 25.20 or newer, which is currently only available for SmartThings v2 or v3 Hubs.

Please see this post for details and links to the updated DTH code.

1 Like

[RELEASE] Aqara Wireless Smart Light Switch DTH v0.9b BETA

For 2016 & 2018 revisions of the 2-button WXKG02LM and 1-button WXKG03LM

This new device handler (DTH) was split off from the “old” Aqara Button DTH in order to best support the two revisions of the one and two-button Aqara Wireless Smart Light Switches. The code has been written so that this device handler can be used with any firmware version, but for users with hub running on Firmware 25.20 or newer, all three actions of the older 2016 revision two-button model WXKG02LM are now recognized: left, right, and both button(s) pushed.

Please see this post for full details about this new device handler in addition to the other two updates announced in the above post, along with the link to the DTH code.


I just realized that the battery died in two of my temp/humidity sensors. I didn’t know because they still showed a status of ACTIVE in the IDE. Is there any way to fix that? If they would have gone OFFLINE, my piston would have alerted me.

1 Like

In the over 1.5 years I’ve been using Xiaomi / Aqara devices I’ve never had the batteries die, but I can confirm that their Status can be marked as “OFFLINE”, even with SmartThings’ Device Health feature turned off:

I have read reports of Device Health being unreliable, so I have it turned off.

Really the best way to know whether a Xiaomi / Aqara device has gone offline for any reason is to look at the time of the most recent battery percentage report.

All battery-powered Xiaomi / Aqara ZigBee devices check in with the hub every 50-60 minutes and send a battery voltage report at the same time. So I would suggest setting up a piston with logic that sends an alert if no battery percentage event has been generated by the device in over 2 or 3 hours.

If having trouble setting up a piston with that kind of logic, there is also a very nice customizable SmartApp which can send notifications based on time since the last XXXX event, or battery level, or temperature:

EDIT: It would be really helpful if you could check the events lists for the final battery voltages / percentages just before those sensor’s batteries died, and share those values.

Yeah, the problem is that these devices apparently don’t go OFFLINE in the IDE even if they haven’t communicated in over a month. I assumed that would be a good value to watch for device issues, and it seems it is - except for these. Of course, I can create a new piston to just watch the value of my Xiaomi devices, I was hoping that kind of device specific piston wouldn’t be required.

I’ll take a look at Simple Device Viewer, but man would I prefer to have all my automations in Webcore.

And finally, as far as battery percentages go, they seem to vary pretty wildly. I’m about 90% sure that one of them last checked in with 80% before dying.

1 Like

@veeceeoh I am hoping that you can help me figure out what the problem is with my aqara WXKG11LM buttons.

I was happily using my aqara buttons to open and close my gate and garage door until they stopped working a few days ago. When I pressed the buttons, there is no event button being pushed when I checked the events log. However, I do see the lastcheckin and lastcheckinCore events as shown below. Any idea?

Aqara Button WXKG11LM last checkin is Sun Mar 31 2019 5:19:08 PM
Aqara Button WXKG11LM last checkin co re is 1554027548374

The V2 firmware was recently updated. You will need to update your DTH with this one.

1 Like

@TylerDurden it works! Thank you very much.