[Release] Xiaomi device drivers

community_driver

#1

I am maintaining a collection Xiaomi device drivers for Hubitat in a GitHub repository, at veeceeoh/xiaomi-hubitat.

These device drivers are based on the bspranger/Xioami repository of device handlers for SmartThings, but with significant modifications for specific use only with Hubitat.

Rather than start a new thread for each separate Xiaomi device driver as I finish them, I will post announcements on this thread, and add them to the list below in this initial thread post.

Currently supported Xiaomi devices:

  • “original” & Aqara Temperature/Humidity sensors (code here)
  • “original” Motion Sensor (code here)
  • Aqara Motion Sensor (code here)
  • “original” & Aqara Door/Window contact sensors (code here)
  • Aqara Leak sensor (code here)
  • “original” Button (beta code here)
  • Aqara Button - models WXKG11LM & WXKG12LM (code here)
  • Aqara Smart Wall Switch - 2 button wireless model WXKG02LM (code here)
  • Mi “Magic” Cube Controller (beta code here)
  • MiJia Honeywell Smoke Detector (code here)

Notes on all Xiaomi device drivers:

  • All references to a mobile app user interface that were in the original SmartThings device handlers have been removed, since there is no UI in Hubitat (at this time)
  • Xiaomi devices send reports based on changes, and a status report (including battery voltage data) every 50-60 minutes. These settings and the report time intervals are hardware-based and cannot be adjusted.
  • The battery level / voltage is not reported at pairing. The sensors are programmed to supply battery voltage data in their first status report, 50-60 minutes after pairing.
  • Pairing Xiaomi devices can be difficult as they were not designed to use with a Hubitat hub.

Basic pairing instructions (except for Leak sensor, Smart Wall Switch, & Smoke Detector):

  1. Holding the sensor’s reset button until the LED blinks will start pairing mode.
  2. After a brief pause, the LED will flash again.
  3. 3 quick flashes indicates success, while one long flash means pairing has not started yet.
  4. In either case, keep the sensor “awake” by short-pressing the reset button repeatedly, until the sensor is recognized by Hubitat, ready to be named.

Dropped Connection Issue:
As of Hub Update 698, real progress has been made in that after applying the update, Xiaomi sensors have remained connected for most users. However, there have still be reports by some users of sensors dropping their connection less than 60 minutes after pairing, and for others within 24 hours. Just be forewarned: Since they were specifically designed to work with a Xiaomi Gateway hub, there’s no guarantee that Xiaomi devices will stay connected for 100% of Hubitat users.

To reconnect a “lost” sensor without deleting and re-pairing it:

  1. Put Hubitat in “Discover Devices” mode.
  2. For the Temperature/Humidity sensors, Short-press the sensor’s reset button once.
    For any other sensors, LONG-press the reset button and release when the LED flashes (same as for pairing).
  3. Wait for the LED to flash again.
  4. 3 quick flashes indicates reconnection.
  5. If only one long flash, short-press the button and go to step 3.
  6. The device will resume reporting as normal.

Please if you have feedback about any of my Xiaomi device drivers, post on this thread.

If you have any general feedback on pairing Xiaomi devices and whether they are staying connected to your Hubitat hub, please join the discussion on this forum thread.


Best and Cheapest way to get 14 contact sensors?
Xiaomi devices - are they pairing / staying connected for you?
Xiaomi devices with out the gateway?
Xiaomi devices - are they pairing / staying connected for you?
Xiaomi devices - are they pairing / staying connected for you?
Xiaomi devices - are they pairing / staying connected for you?
Looking for a reliable multisensor
Sylvania plugs $14.99, color bulb $19.99 clearance Canadiantire.ca
Compatible Devices Wiki
Aqara WXKG03lm Single Wireless button
Humidity Sensor for Basement
Sylvania plugs $14.99, color bulb $19.99 clearance Canadiantire.ca
Best and Cheapest way to get 14 contact sensors?
Xiaomi devices - are they pairing / staying connected for you?
Zigbee motion detector recommendations?
Discovering devices
#2

[RELEASE] v0.5 of unified Xiaomi Temperature/Humidity sensor Device Driver
Works with both the Xiaomi “original” and Aqara models

For convenience please copy the T/H sensor device driver code from this direct link.

I have finished work on a single unified Hubitat Device Driver for both the Xiaomi “original” and Aqara T/H (Temperature/Humidity) sensor models. This device driver is based on the SmartThings device handlers in the bspranger/Xiaomi GitHub repository, but has been significantly modified to work with Hubitat.

Features:

  • The Hubitat hub will correctly select this custom device driver for both T/H sensor models when paired
  • Temperature (C/F), humidity, pressure (Aqara model only), and battery values correctly reported
  • The date/time of the most recent report of any kind is stored as lastCheckin (human readable) and lastCheckinDate (java format). This may be useful in determining whether the sensor is still connected, since a status report including battery voltage is sent every 50-60 minutes.
  • Battery replacement date tracking, stored in batteryLastReplaced state
  • Preferences include:
    • offsets for temperature, humidity, pressure (Aqara model only)
    • Aqara model only: Selectable pressure unit (mbar, kPa, inHg, or mmHg)
    • Toggle to reset battery replacement date (when you replace the battery!)
    • Date / 24-hour clock settings for display of lastCheckin
    • Min/Max voltage values used to calculate the battery percentage

Note:

  • This device driver is not final, and some features or preferences may be added / removed

#3

Worked right away. You’re a superstar. Now to wait and see if they still timeout or not.


#4

This is very exciting, I found them to be useless for me in ST, They would work for weeks and then fall off. Pairing was and nightmare process. This driver is great, Pulled 9 temp/humd sensors out of the “I give up drawer” and the paired right away, I found that you need to be patient and not except the device to show up in discovery right away, Most of mine took about 15 - 20 seconds. Will checking on status and reporting back. I was excited to see re-pair process if there is a drop off which might make it more bearable. But with the quick pairing process I am confident this is a great start and leaps and bounds better than it was in ST! There are plenty motion sensors from the same place.


#5

My pairing technique was the same as recommended for smartthings… Set the hubitat in search mode. Hold the button to reset until 3 short flashes. then single press the button every 2-3 seconds until you get 3 short flashes again. Pairing complete.


#6

Glad to hear that! Yes, the pairing process works much much better. Just be warned that although the Hubitat engineers are well aware of the connection drop off issue, it’s not easy to diagnose. It may take a while, and there’s no promises.

I’m already working on the motion sensor device driver, currently testing.


#7

No problem at all. Like I said I was ready to toss them. You may have given them new life!

And crud, I missed the repeated clicking to keep the sensor alive. Hence why they took longer.
Since I am not doing anything with them I will leave and lets see what happens.


#8

No guarantees we will be able to get these working. But the next update will have a change in our zigbee stack that should help.

I’ve been researching these quite extensively and they do seem to have a proven track record of being inconsistent and problematic for other platforms if they work at all.


#9

Wow, you have been busy @veeceeoh! Glad to see that you already published a version!

Here’s an update from my side, consolidating the multiple reports I shared across other threads.

Xiaomi Motion Sensor

  • Pairing took a few tries.
  • None of the sensors have fallen off after 48 hours.
  • Motion reporting works perfect with ST handler. Battery reporting does not work.

Xiaomi Temperature/Humidity Sensor

  • Pairing succeeded in the very first try.
  • Sensors fell off multiple tries, in intervals of 3-6 hours.
  • No reporting worked with ST handler. Reporting works flawlessly with your new handler.

Aqara Contact Sensor

  • Pairing succeeded in the very first try.
  • None of the sensors have fallen off after 24 hours.
  • No reporting worked with ST handler. Does not work using the Generic Zigbee handler either.

P.S: As you had mentioned earlier, I too follow the same method to get fallen off device back online. Simply pressing the pairing button while a device scan is in progress, resuscitates the device.


#10

So my results are: Both my Xiaomi original temperature/moisture sensors reported for almost exactly 30 minutes, then stopped, with the reports getting further apart. My suspicion is that there’s some acknowledgement that the Xiaomi hub sends to the device after receiving the values that it’s not getting, but I have no way to confirm that from here. Hopefully the next update will have a positive effect.


#11

[RELEASE] v0.5 of device drivers for Xiaomi “Original” & Aqara Motion Sensors

Links:
• Xiaomi “Original” Motion Sensor device driver code
• Xiaomi Aqara Motion Sensor device driver code

Unlike with the Temperature/Humidity Sensors, there needs to be separate device drivers for the two motion sensor models, because the Aqara model supports the Illuminance Measurement capability that can be accessed by apps such as Rule Machine, while the “original” model does not have that capability.

Features:

  • The Hubitat hub will correctly select the custom device driver for the appropriate sensor model when paired
  • The date/time of the most recent detected motion is stored as lastMotion (human readable) and lastMotionDate (java format).
  • The date/time of the most recent report of any kind is stored as lastCheckin (human readable) and lastCheckinDate (java format). This may be useful in determining whether the sensor is still connected, since a status report including battery voltage is sent every 50-60 minutes.
  • Battery replacement date tracking, stored in batteryLastReplaced state
  • Commands / Preferences include:
    • A Reset Battery Replaced Date command to track battery life
    • A Reset To Motion Inactive command for override of detected motion
    • A time delay to set how long the driver waits after motion is detected to reset to motion inactive state (see notes below for more information)
    • Date & 24-hour clock settings for display of lastCheckin
    • Min/Max voltage values used to calculate the battery percentage

Notes:

  • These device drivers are not final, and some features or preferences may be added / removed

  • Both models of Xiaomi Motion Sensors only send a “motion detected” message, and do not send a “motion inactive” message. Because of this, the device driver sets the motion inactive state using a countdown timer in its code.
    There is a user preference setting for this, with a default of 60 seconds. This is because in normal operating mode, the hardware is designed to be “blind” to any motion for 60 seconds after a motion detected message is sent, in order to reduce battery consumption.
    This 60-second reset delay cannot be changed, however, when the sensor is paired, and also when the reset button is short-pressed, the sensor goes into “testing mode”, and will report any detected motion every 3-5 seconds, for a period of about 2 hours. Use the testing mode time period to determine the best placement for the use of the motion detector. Placement is very important, because there is no ability to change the sensitivity level of the sensor.

  • I do not have an Xiaomi “original” Motion Sensor to test with, but when my Aqara Motion sensor’s connection with the Hubitat hub is dropped, I had to LONG-press the reset button while Hubitat is in “Device Discovery” mode in order to reconnect. Although it is effectively re-pairing the sensor, I did not have to remove it from my Hubitat’s device list, and after the LED flashed 3 times to indicate a successful connection, I saw reporting resume as normal.


#12

Perhaps, but from the months of working with these sensors and doing research on other people’s exploits with connecting them to non-Xiaomi hubs, I believe the connection issue relates to the regular “status” report that they send, about every 50 minutes for the Aqara models, and every 60 minutes for the Xiaomi “Original” models.

These “status” reports are what all of the device drivers use to parse the battery voltage data to calculate the battery percentage. So when used with the SmartThings hub, looking at recent battery reports in the events list for an otherwise idle device is the best indicator of whether its still “awake” and connected to the hub. This will also be true with the Hubitat hub, if the dropped connection issue can be worked out.

In all of my testing, over 90% of the instances of dropping the connection was just before the “status” report was to be sent. In fact, when I reconnect the sensors using the reset button short-press method, the very first thing they do is send that “status” report and the battery percentage is updated by the device driver (as seen in the device’s Events List or the Hubitat Hub’s Logs webpage.


#13

[UPDATE] v0.5.1 of device driver for Xiaomi Aqara Motion Sensor

Changes:
• Added a second fingerprint for another revision of the Aqara model, as identified with @bomountjoy’s help. (Thanks!!) This should help the Hubitat to select the correct device driver when pairing either revision of the Aqara model. Please let me know if it works.

Link:
• Xiaomi Aqara Motion Sensor device driver code


#14

@veeceeoh Really great work! You seem to be actively pushing out updates :+1:t3:
I have had not had issues with either of the drivers you have published until now, except that the Temperature sensors do not seem to have reported their battery levels to the Hubitat interface ever since they were paired (image below).
07%20PM
Is this a known issue or would this be something wrong at my end alone?


#15

working now


#16

My bad - I didn’t push the updated code from my computer to GitHub. It is updated now, sorry about that!


#17

Has anyone tried the Aqara leak sensors yet?


#18

Neither. :smile: But now it’s possibly a known issue!

Which model of Temp/Humidity Sensor is this - “original” or Aqara?

Also, your screenshot shows a lastCheckin of yesterday evening, which tells me it has probably dropped the connection.


#19

After I finish the device driver for both types of Door/Window contact Sensors, I’m going to make one for the leak sensor. That one will be pretty quick to make.


#20

You’re a Prince Keith! Thank you.