[RELEASE] Xiaomi/Aqara Temperature & Humidity Sensor — maintained fork of the oh-lalabs driver

Hey, all. I've used Markus Liljergren's Xiaomi/Aqara temperature and humidity driver from the oh-lalabs project for years. That repo has been archived since 2020, so I forked it to keep it maintained. Reading through the source turned up a handful of bugs, some of them old ones, and this fork fixes them.

It supports:

  • Xiaomi WSDCGQ01LM (lumi.sensor_ht) — temperature and humidity
  • Aqara WSDCGQ11LM (lumi.weather) — temperature, humidity and pressure
  • Aqara T1 (lumi.sensor_ht.agl02) — temperature, humidity and pressure
  • Keen Home RS-THP-MP-1.0 — temperature, humidity and pressure

Installing

Hubitat Package Manager: search for Xiaomi/Aqara Temperature & Humidity Sensor.

Manually: go to Drivers Code → New Driver → Import and paste:

https://raw.githubusercontent.com/brossow/hubitat-drivers/main/xiaomi-aqara/th-sensor/zigbee-xiaomi-aqara-temperature-humidity.groovy

Then open each sensor, set Type to Zigbee - Xiaomi/Aqara Temperature & Humidity Sensor (namespace brossow), and click Save Device, then Save Preferences.

Coming from the oh-lalabs driver? The namespace is different, so you have to change the Type on each device page as above. Your history is kept.

Device health instead of presence

The original driver reported "has this sensor checked in during the last 3 hours?" as presence, which made every thermometer a presence sensor. That's why they showed up in presence pickers like Mode Manager's. This fork reports the same check as healthStatus (online / offline), the attribute Hubitat uses for whether a device is reachable.

If you had a "sensor went not present" rule as a dead-battery alert, point it at healthStatus changing to offline instead.

What's fixed compared to the original

  • Pressure options showed on sensors without a barometer. A logic error marked every model as having pressure. Only the models that measure pressure get those options now.
  • Pressure stopped updating if you displayed it in atm. The change needed before a new reading was sent was a fixed 0.1 in whatever unit you chose. In kPa that's 1 hPa, but in atm it's about 100 hPa, so pressure froze after the first reading. It needed about 3.4 hPa in inHg. It's now 1 hPa in every unit. If you use mbar you'll see fewer pressure events than before (the threshold went from 0.1 to 1 mbar). kPa, the default, is unchanged.
  • Temperature and humidity thresholds were slightly off. A change exactly equal to the threshold was skipped, even though the setting says "at least". It's reported now.
  • Bad readings vanished silently. Humidity outside 0–100% (common as the battery dies) is now dropped with a "change the batteries" warning in the log, the same way temperature already was. An offset can no longer push a reading past 0 or 100%.
  • Early WSDCGQ01LM sensors kept an unrecognised model name until their first hourly check-in. They're recognised straight away now.
  • The Keen Home sensor's fingerprint had the wrong manufacturer.
  • The temperature sanity check ignored its own limits and used hardcoded ones.

A few additions:

  • batteryVoltage, alongside battery %, so you can calibrate the min/max voltage settings against real numbers
  • battery % kept between 0 and 100 (a deeply drained battery used to go negative)
  • Temperature/Humidity Reporting Threshold settings, if a sensor is too chatty
  • pressure readings outside 500–1100 hPa rejected as corrupt

I also removed about 1,100 lines of code the driver never used. The full changelog is in the README.

Thanks

The original was solid for years, and nearly everything above is cleanup of good bones. Thanks to Markus for writing it. Like the original, the fork is GPL-3.0.

Let me know if you run into anything.

:flushed_face:

Wow! Years ago, I used Keith’s (@veeceeoh) drivers for Aqara sensors - they ran about 200 lines of code. Amazing to learn there are drivers with >1000 lines of bloat.

Good on you for cutting the bloat out!

Just reporting a bug, that's what the log says. :slight_smile:

I just upgraded to the latest beta and just did a reboot.

All my sensors are chiming in. :frowning:

I did just have an A?C power outage so maybe it's because lots of ZB sensors haven't checked in yet?

That is really great, thats 1100 more space that can be used elsewhere. I wonder if the other oh-lalab drivers can be improved. I have been using these drivers on a C7 and never really have problems. I really like the old Xiaomi/Mijia contacts. They are very small and the batteries last forever. WSDCGQ01LM, lumi.sensor_magnet.

Yes...they are so frugal w/their battery use, really great.

Thanks, @dnickel, good catch. Most of those warnings are expected after an outage, but "Stopping Recovery feature due to Platform bug!" was a real bug I introduced in 2.0.0. When a sensor came back after missing check-ins, a typo made the recovery code throw an error, and the driver then turned Recovery Mode off on that device.

While testing the fix I found a second 2.0.0 bug: sensors upgraded from 1.x through HPM log a checkPresence() error every 3 hours, and their health check doesn't run, until you click Save Preferences.

2.0.2 is out in HPM now and fixes both. After updating, check Recovery Mode on any sensor that logged the "Platform bug" message (dev:2325 for you), set it back to Normal, and click Save Preferences. The checkPresence problem clears up by itself.