ESPHome already integrates with many of Xiaomi’s Bluetooth Low Energy (BLE) devices out of the box. What makes this integration interesting and useful in the smart home, is that you can use a cheap Bluetooth-enabled ESP32 (or ESP32-C3) as a gateway between the Bluetooth device and Home Assistant. While the official integration is already extensive, ranging from soil sensors to thermometers with e-paper screens and bathroom scales, there are many more Xiaomi smart devices out there.
The custom components for ESPHome I will be introducing today covers a number of the devices not (yet) officially integrated with ESPHome. The integration of the many Xiaomi Bluetooth devices listed below is made possible by developer dentra on GitHub. This article will cover these devices, which even include a Bluetooth-enabled Rubik’s Cube, and provide details on how to set them up.
Table of Contents
- Why use ESPHome to connect to Xiaomi BLE devices
ESPHome custom components for Xiaomi BLE devices
- Xiaomi Mi Motion-Activated Night Light 2
- Universal Xiaomi Smart Kettle
- Xiaomi Door & Window Sensor 2 and Qingping Motion & Ambient Light Sensor
- Xiaomi Flood Sensor
- Xiaomi Human Body Sensor 2
- Yeelight Remote Control and Yeelight Wireless Switch
- Xiaomi Mijia Bluetooth Smart Rubik’s Cube
- Universal Xiaomi Thermometer/Hygrometer
Why use ESPHome to connect to Xiaomi BLE devices
There are many reasons as to why you would want to use ESPHome, and not a mobile app, to connect to Xiaomi’s BLE devices. First, it allows you to import the sensor readings in to Home Assistant. You can then use these values can in automations. For example, you could use the Xiaomi Mi Smart Home Door/Window Sensor 2 to detect when a window has been opened and let Home Assistant turn off your heating or HVAC. Or you could sound an alarm via a notification, whenever a Xiaomi Flood Sensor detects water underneath your washing machine.
The second most important reason for using ESPHome, for me personally, is that you can skip the app altogether. Nowadays, every manufacturer wants you to install their app, so they can access your precious data. Using an app for such devices has many downsides: For starters, you don’t know what is happening to your data without reading the wordy terms and conditions. You might claim that there’s no harm in someone else knowing the temperature of your living room. But if we take the Xiaomi Home app as an example and browse through the access permissions it wants you to grant it, you might think differently. According to the Google Play listing, it requests permission to the following: Contacts, location, camera, device and app history, device ID and call information, files, phone, storage, microphone, Wi-Fi information, identity, and much more.
Additionally, I want all of my smart devices to report to one central application: Home Assistant. Home Assistant allows your smart home to be completely vendor-independent and ESPHome does an impressive job of not just integrating custom sensors, but Bluetooth sensors, too.
ESPHome custom components for Xiaomi BLE devices
The way these custom components work is rather different from the official ESPHome implementation. Instead of relying on custom firmware or workarounds to gather the bind key needed to connect to Xiaomi’s Bluetooth devices, the custom component interacts directly to the MIoT protocol.
This does mean that you need to register an account with Xiaomi and you will need to pair the device with your phone, to get it registered. Once your phone has paired with the Xiaomi Bluetooth device, you will be able to deinstall the app again. The use of the MIoT protocol is a one-way process. Your ESPHome node will be querying the remote server for information, but it will send nothing in return.
Xiaomi Mi Motion-Activated Night Light 2
The Xiaomi Mi Motion-Activated Night Light 2 is more than just your usual night light. It comes with a base, to which the light magnetically attaches. The direction in which the heavily diffused light shines can be adjusted to your liking. This allows you to mount the Xiaomi Mi Motion-Activated Night Light 2 anywhere, and you can also bounce the light off a wall, for even more diffusion. It comes with a light and infrared sensor, so it can adjust the brightness based on the conditions and will automatically turn on when it detects movement.
Thanks to an internal battery, which can last for up to a full year, you can use this night light to guide you on nighttime bathroom visits. As the LEDs used do not produce any harmful blue light and have a warm temperature (2800K), it should allow you to fall asleep again more easily.
Universal Xiaomi Smart Kettle
This component should cover most Bluetooth smart kettles from either Xiaomi or one of its many sub-brands (Mijia, Viomi, etc.). Currently confirmed to be working is the Viomi Smart Kettle Bluetooth Pro (this is not the linked kettle). If you do have any other smart kettle from the above-mentioned vendors, make sure to inform the developer whether it is compatible or not.
As I do not own such a kettle, I can’t report on the functionality of this component, but it does appear to show the kettle’s status and the water’s temperature.
Xiaomi Door & Window Sensor 2 and Qingping Motion & Ambient Light Sensor
The Xiaomi Door & Window Sensor 2 (buy it on AliExpress) is a basic contact sensor, similar to the Zigbee and Wi-Fi alternatives. It consists of two components: One houses the electronics and a reed switch, the other is simply a magnet. The reed switch opens whenever the magnet moves away from it and thus, it recognizes when a door or window is open.
Using this custom component for ESPHome, you can relay data on the sensor’s status to Home Assistant. What makes the Xiaomi Door & Window Sensor 2 stand out from the crowd is that it also features a light sensor. The reading from that sensor can be used to decide whether a light should be turned on or not whenever you open a door. Other uses include the capability of closing smart shutters when the sun goes down and a window is, to not attract as many mosquitos.
There is a second custom component available for the Qingping Motion & Ambient Light Sensor (buy it on AliExpress) available. Function wise, it is comparable to the Xiaomi Door & Window Sensor 2, it does, however, differentiate itself by having a magnetic base. Using this base, you can easily change the direction in which the Qingping Motion & Ambient Light Sensor is pointing, or even attach the sensor directly to an iron surface.
Xiaomi Flood Sensor
The Xiaomi Flood Sensor (and any other flood sensor for that matter) is as basic as it gets. Whenever something, for example water, bridges the two contacts on the backside, it sends out an alarm. The obvious use case is to have this sensor beneath your washing machine, or anywhere else where water might leak.
However, there are also possibilities to use a flood sensor in the reverse way: One example is to check whether your cat’s, dog’s, or other pet’s water bowl is empty. In this case, you would set the alarm to ring whenever nothing bridges the contacts. If you are interested in this sensor, please consider using my affiliate link to purchase it.
Xiaomi Human Body Sensor 2
The Xiaomi Human Body Sensor 2 (buy on AliExpress) looks and acts similar to the equivalent from Aqara, but in place of a Zigbee radio, there is Bluetooth. This component lets you extract motion activation and light readings from the sensor.
Yeelight Remote Control and Yeelight Wireless Switch
The Yeelight Remote Control (buy it on AliExpress) provides six buttons : On, off, colour temperature, night light, and temperature control. Using the custom component, you can’t just use these six button, but also configure what happens when you long press any of the buttons. This could be used to set a light to its maximum brightness whenever you long-press the + button.
The Yeelight Wireless Switch, also found under the name Yeelight Remote Control 1S, is a single push-button remote. Despite only having one button, there are three functions available: Single click, double click, and long press. This wireless switch has its own custom component.
Xiaomi Mijia Bluetooth Smart Rubik’s Cube
Your eyes are not deceiving you, there is a Smart Rubik’s cube made by Xiaomi (buy it on AliExpress). Why would you want one of these? Its main function appears to be to allow you to time yourself. The custom component will pick up whenever you twist the cube, either clockwise or counterclockwise.
I’m sure there is someone out there who could use this device for some creative automations. Perhaps one could start playing the Mission:Impossible soundtrack whenever the Xiaomi Smart Rubik’s Cube is twisted.
Universal Xiaomi Thermometer/Hygrometer
Besides the devices listed above, there is one more custom component available. ESPHome officially supports some of the above listed Bluetooth devices from Xiaomi, however, using the custom component is likely to be easier.
The Universal Xiaomi Thermometer Hygrometer custom component should cover any Bluetooth sensor from Xiaomi or any of its sub-brands. There are a number of confirmed to be working devices on the GitHub page, and the developer would certainly be grateful if you were able to add more.