Connecting Xiaomi’s temperature sensor to the gateway BLE: complete

Xiaomi’s temperature sensors have become an integral part of smart homes due to their accuracy, compactness and affordable price, but many users have difficulty connecting them to the gateway via Bluetooth Low Energy (BLE). Unlike traditional Zigbee connectivity, BLE requires a special approach: here it is important not only the correct settings, but also the compatibility of devices, the firmware version and even the distance between gadgets.

In this article, we'll look at the whole process, from checking the compatibility of the sensor and the gateway to configuring automation in the Mi Home or Home Assistant, and focus on the typical errors that make the sensor undetectable, from outdated software to conflicts with other Bluetooth devices, and if you've tried to connect, but you see a message in the application saying "Device not found" or "Can't be added," here you'll find solutions.

Important: the instruction is relevant for the Mijia Bluetooth Temperature and Humidity Sensor series (models) LYWSD03MMC, LYWSD02, MHO-C301 and similar), as well as for gateways Xiaomi Gateway 3, Aqara Hub M2 and other supportive BLE. If your gateway only works on Zigbee, connect via BLE It will be impossible – an additional hub will be required.

1. Verification of the compatibility of the sensor and the gateway

Before you start connecting, make sure your sensor and gateway support BLE-Not all Xiaomi models work on this protocol: for example, old sensors. WSDCGQ01LM They only use Zigbee and will not be suitable for this instruction.

Here is a list of compatible devices:

  • πŸ”Ή Temperature sensors: LYWSD03MMC (most popular), LYWSD02, MHO-C301, MHO-C401 (with display), ClearGrass CGDN1 (clone from AliExpress).
  • πŸ”Ή Gateways with support BLE: Xiaomi Gateway 3, Aqara Hub M2, Aqara Camera Hub G2H/G3, Mi Smart Multimode Gateway.
  • πŸ”Ή Alternative hubs: Home Assistant with Bluetooth adapter (e.g., Home Assistant, CC2652), Zigbee2MQTT s BLE-plug-in.

If your gateway doesn't support BLE, But you have an Android smartphone or a Raspberry Pi, and you can use it as a middle ground, and for example, the Home Assistant app lets you read data from the sensor through your phone and send it to your smart home system.

πŸ“Š What gateway do you use for a smart home?
Xiaomi Gateway 3
Aqara Hub M2
Home Assistant
Another brand
Not yet.

2. Preparation of devices for connection

Before you start setting up, follow the following steps:

Update the lock firmware to the latest version

Make sure the sensor is charged (if battery-operated)

Disable other Bluetooth devices within a 5-meter radius

Reboot the gateway and smartphone

-->

Pay particular attention to the gateway firmware. Outdated versions often don't support new sensors. For example, for Xiaomi Gateway. 3 minimum version required β€” 1.5.6_0036. You can check it in the Mi Home app:

  1. Open Mi Home β†’ select your gateway.
  2. Go to Settings β†’ About the device β†’ The firmware version.
  3. If the version is outdated, update it through the Firmware Update menu.

Also check the battery power of the sensor. If the level is below 20%, the connection may be interrupted (LYWSD03MMC) Use high-quality power cells (e.g. Duracell or Energizer (MHO-C401) charge to 100%.

πŸ’‘

If the sensor doesn't turn on, try removing the battery for 10 seconds, then inserting it back in, which will reset its settings and often helps with connection problems.

3. Step-by-step instructions for connecting through BLE

Now, to the process itself, we're going to look at two options: through the official Mi Home app and through the Home Assistant (for advanced users).

Method 1: Connecting through Mi Home

This method is suitable for most users. Follow the instructions:

  1. Open the Mi Home app and make sure you are in the same region as your account (e.g., Russia or Mainland China).
  2. Press. + β†’ Add the device β†’ Temperature and humidity sensor.
  3. Select your sensor model (e.g. Mijia Bluetooth Temperature and Humidity Sensor).
  4. Click Next and wait until the app starts searching for devices.
  5. When the sensor appears in the list, click on it. If they request confirmation, hold the button on the sensor (if any) for 5 seconds.
  6. Once connected successfully, the sensor will appear in the main menu, and now it can be attached to the gateway.

To tie the sensor to the gateway:

  1. In the main Mi Home menu, click on the gateway.
  2. Go to Settings. β†’ Connected devices β†’ Add the device.
  3. Select your sensor from the list. If it's not there, update the list or reboot the gateway.

Method 2: Connecting with Home Assistant

If you use Home Assistant, it's a little bit more complicated, but it's a little more flexible.

  • πŸ“± Bluetooth adapter on the gateway (e.g. built-in in the Raspberry Pi 4 or external) CSR 4.0).
  • πŸ”§ Installed Bluetooth in Home Assistant Configuration.
  • πŸ“¦ Xiaomi integration BLE (set up HACS).

Add the following lines to the configuration.yaml file:

bluetooth:


devices:




hci0# or other interface, check via hciconfig command





xiaomi_ble:




devices:




- mac: "XX:XX:XX:XX:XX:XX" # MAC- address of your sensor




bindkey: "your_bind_key" #Basic Key (optional)




temperature_precision: 1




humidity_precision: 1

To find MAC-Sensor address, use command:

sudo hcitool lescan

Once the Home Assistant is rebooted, the sensor will appear on the device list, and it can be used in automation and dashboards.

How to get a bindkey for a sensor?
Bindkey is a unique key that is required for some sensor models (e.g., the sensing system, LYWSD03MMC) To get it, you can use the mihome-binary-parser (available on GitHub). 2. Intercept the sensor packets using Wireshark or nRF Connect. 3. Remove the key from the authentication package. Without bindkey, the sensor will transmit encrypted data that Home Assistant cannot decrypt.

4. Typical errors and their solutions

Even if you follow the instructions correctly, the connection may fail, and let's look at some of the most common problems and how to fix them.

Mistake.Possible causeDecision
Sensor not found in searchWeak signal. BLE, interference from other devicesBring the sensor closer to the gateway (maximum) 1-2 Meter), disable other Bluetooth devices
The connection is cut off in a few seconds.Low battery charge or outdated firmwareCharge/replace the battery, update the lock and sensor firmware
The sensor connects but does not transmit data.Mi Home is not in the right region or there is no bindkeyChange region to Mainland China, check Home Assistant settings
Error "The device is already tethered"The sensor was previously connected to another account.Reset the sensor to factory settings (hold the button) 10-15 seconds)

Critical feature of sensors LYWSD03MMC: They only support one active person at a time. BLE-So that means that if the sensor is already connected to the smartphone, the gateway won't be able to connect to it!

πŸ’‘

If the sensor is not detected, try using an alternative app like Aqara Home or Yeelight. BLE-devices than Mi Home.

5. Setup of automations with temperature sensor

Once connected successfully, the sensor can be used to create smart home scenarios, such as:

  • πŸ”₯ Smart heating: turn on the heater if the temperature has dropped below 20Β°C.
  • ❄️ Control of the air conditioner: turn it off when a comfortable temperature is reached.
  • πŸ’§ Moisture alert: Send a notification if the humidity exceeds 70% (mould risk).
  • πŸšͺ Safety: turn on ventilation if the temperature in the room with server equipment exceeds 25Β°C.

Example of automation in Mi Home:

  1. Open the Automation tab β†’ Create β†’ Smart scene.
  2. Select the condition: Temperature [your sensor] < 20Β°C.
  3. Add the action: Turn on [heater].
  4. Save the script and activate it.

In Home Assistant, a similar scenario is created through YAML:

automation:


- alias: β€œLow temperature heating”




trigger:




platform: numeric_state




entity_id: sensor.temperature_lywsd03mmc




below: 20




action:




service: switch.turn_on




target:




entity_id: switch.heater

For more complex scenarios, you can use conditional operators, such as turning on the heat only at certain times of the day or if there are people in the room (according to the motion sensor).

6. Alternative ways of connecting (if) BLE doesn't work)

If your gateway doesn't support BLE or the connection is constantly broken, there are workarounds:

Option 1: Use of the Zigbee bridge

Some sensors (e.g, LYWSD03MMC) You can flash it with an alternative firmware, you can add Zigbee support:

  • πŸ”§ Programmer CC2531 or CC Debugger.
  • πŸ’» Custom Firmware for Firmware LYWSD03MMC (available on GitHub).
  • πŸ”Œ Sales for connecting to sensor contacts.

Once firmware is in place, the sensor will run through Zigbee and connect to any Xiaomi or Aqara gateway.

If you don't have a gateway with BLE, But there is an Android smartphone, you can use it to transfer data:

  1. Install the Home Assistant app on your phone.
  2. Enable Permanent Bluetooth Scanning in the settings.
  3. Set up Mobile App integration to transfer data from phone to server.

The disadvantage of this method is that the phone must always be near the sensor.

Option 3: Purchase of a specialized hub

If you plan to deploy a large smart home system, consider buying support hubs. BLE:

  • 🏠 Aqara Hub M2 β€” It supports up to 128 devices, including BLE.
  • 🌐 Home Assistant Green – a ready-made solution with Bluetooth and Zigbee.
  • πŸ”Œ Sonoff Zigbee 3.0 USB Dongle Plus is a budget option for Home Assistant.

7. Optimization of the sensor: tips for placement and setting

To ensure that the sensor is stable and transmits accurate data, follow these recommendations:

Set the sensor up at altitude. 1-1.5 floor-foot

Avoid direct sunlight and heat sources (batteries, cookstoves)

Place away from metal surfaces (they shield the signal) BLE)

Check the sensor calibration once in a while. 3-6 months

-->

The frequency of data update depends on the sensor model:

  • πŸ”„ LYWSD03MMC: Updates data every 10 minutes (can be changed by firmware).
  • πŸ”„ MHO-C401: Updates every 2 minutes, but drains the battery faster.
  • πŸ”„ ClearGrass CGDN1: interval is adjusted from 1 to 60 minutes.

If you need more data, you can reduce the refresh interval with Home Assistant or custom firmware. 1-2 Minutes reduce battery life with 1-2 years 3-6 months.

To calibrate the sensor, use a reference thermometer:

  1. Place the sensor next to the reference thermometer in stable conditions (e.g., in a closed box).
  2. Compare the readings through 1-2 hour.
  3. If the difference is greater than 1Β°C, calibrate the sensor through Home Assistant or return it under warranty.

πŸ’‘

To increase the signal range BLE Use a Bluetooth repeater (for example, ESP32 This will help if the sensor is in another room or behind multiple walls.

FAQ: Frequently Asked Questions

πŸ” Why does the sensor connect but not show data?
This is a typical problem when you don't have a bindkey or a bindkey, try: Untie and reconnect the sensor, change the region in Mi Home to Mainland China, and for Home Assistant, make sure the configuration is the correct bindkey. If it doesn’t work, check if the sensor is in conflict with others. BLE-devices (for example, a fitness bracelet or wireless headphones).
⚑ How to increase battery life?
Battery life depends on the model and frequency of updates: LYWSD03MMC: Use Energizer Ultimate Lithium batteries to keep them running 2 years of renewal every year 10 Reduce the frequency of updates to 30-60 If you don't need real-time data, turn off the display (if you have it) in the sensor settings. If the sensor is discharged quickly, check if it's in the bad signal zone -- constant reconnection attempts consume a lot of energy.
πŸ“± Can I connect the sensor to multiple gateways at the same time?
No, Xiaomi sensors. BLE It only supports one active connection, but you can: Use Home Assistant as a central hub and transfer data from there to other systems (e.g. Google Home or Apple HomeKit). MQTT-If you try to connect the sensor to two gateways at the same time, the connection will be unstable, and the data can be duplicated or lost.
πŸ”„ How to reset the sensor to factory settings?
For most models: Remove the battery (if you have one), press and hold the button on the sensor (usually hidden under the lid), insert the battery back without releasing the button. Hold the button still. 10-15 seconds until the indicator flashes 3 Once. MHO-C401 (with display: press the button on 5 Seconds until the screen goes out and lights up again.
πŸ› οΈ Can the sensor be repaired if it stops working?
If the sensor is not turning on or transmitting data, try: Replace the battery (even if it seems charged); check the contacts of the battery for oxidation (clean with alcohol); Update the firmware (for models with support). OTA). If the sensor is physically damaged (for example, after a fall), repair is usually impractical - it is cheaper to buy a new one. MHO-C401, If it's cracked, but the sensor is working.