Xiaomi BLE Temp & Humidity Sensor

I purchased a Xiaomi BLE Temperature & Humidity sensor from AliExpress (the small square one with the LCD display) and I am struggling to connect it with Home Assistant.

I installed Hass.io on a Raspberry Pi 3 B+ and also connected the sensor to the Mi Home app on my phone. I used the mitemp_bt installation to connect the sensor to HA (here).

# Xiaomi temperature & humidity sensor
  - platform: mitemp_bt
    mac: 'A4:C1:38:CA:xx:xx'
    name: Home Temp Sensor
    force_update: true
      - temperature
      - humidity
      - battery

When I run the bluetoothctl command in Home Assistant and perform a scan, I see that the sensor sometimes pops up but immediately disappears again. It seems like it can’t stay connected? See screenshot below (I’ve removed non-relevant information from the picture).

Any ideas?

I have 4 of them. Connected to HA through an esp-32 flashed with openmqttgateway. There is also a custom mitemp_bt available in HACS for them.

Did you follow any specific guide for this? I’m fairly new to HA.

Maybe this helps.

in the details below the video you can skip to the place you want. but this guy knows his stuff it seems. :slight_smile: Nice video to watch anyway

1 Like

You could also try the custom component via hacs. This works in a different way (passive). This could help if you have connection errors. Also check the faq of this component for help with connection issues.

Yeah I just tried that one but I can’t seem to find the bind_key they mention which is needed to decrypt the data. I followed this guide and tried it a couple of times: https://github.com/custom-components/sensor.mitemp_bt/blob/1ba86ecbc02dc362cbb51ec2a47ccc1ed1389888/faq.md#my-sensors-ble-advertisements-are-encrypted-how-can-i-get-the-key.

Maybe this method doesn’t work anymore? And even if I don’t have the bind key, I’m guessing I should still see the device in my Home Assistant, but without data?

Which method did you try? The first is successful for most people (TelinkFlasher method). It sometimes helps to connect the sensor first to the xiaomi app.

Note that the standard mitemp_bt component will not work, as it doesn’t support encrypted devices, like yours. So you have two choises, the custom component or esphome. Both need the bind key.

I tried option 1 with TelinkFlasher but I can’t get it to the “connected” state. Also tried option 2 by first removing the sensor from my Mi Home app and then reconnecting it.

OpenMQTTGateway does not need the bind key, and works flawless with HA. Just take an ESP32, flash with OpenMQTTGateway 0.95 and configure.

I followed the exact steps but when I open the ATC Thermometer web tool to connect to the sensor and get the bind key, it just keeps saying “Searching for devices” in the log. I also don’t get the pop-up that the guy from the video has, where you need to select the device. I’ve tried multiple browsers and also different phones (iOS and Android). I noticed that the bluetooth icon on the sensor doesn’t always show, could this sensor be broken?

Hi vdvaxel,

Currently I have no idea. yet. sorry.
I have orderd 4 of these and a couple of wemo D1 mini’s. SO I hope I can give you the answer in a couple of weeks.
But, maybe others can help you in the mean time.

Ok so I finally got it to work. Turns out the ATC Thermometer web tool to connect to my sensor worked fine if I used it on my laptop, contrary to all the tutorials saying you should open it on your phone. I flashed the custom firmware and got it to connect to my HA. Thanks for all the help everyone!

Good to Read this. Gives me convidence it will work here as well. Thanks

To inform others, I have followed the guide I proposed above in this thread. It takes some time, but it works…

I have a ESP32 D1 Mini. Its a version with wifi + Bluetooth BLE

first time flash to the chip, you need to select ESP32 generic instead of the specific ESP8266 D1 mini (which sounds/looks the first choice). the ESP8266 will not allow you to set esp32_ble_tracker.

This is my config in ESPHome > edit

  name: wemos_d1_mini_1
  platform: ESP32
  board: esp-wrover-kit
  ssid: "xxx"
  password: "xxx"
  manual_ip:   # This is optional
    static_ip: xxx.xxx.xxx.xxx   # This is optional
    gateway: xxx.xxx.xxx.xxx   # This is optional
    subnet:   # This is optional
# Enable logging
# Enable Home Assistant API
  reboot_timeout: 60min
  password: "xxx"
  password: "xxx"
  port: 80
# Enable Bluetooth scanning for this ESP32
  - platform: uptime
    name: "wemos_d1_mini_1_Uptime Sensor"
  - platform: wifi_signal
    name: "wemos_d1_mini_1 WiFi Signal"
    update_interval: 60s
  - platform: xiaomi_lywsdcgq
    mac_address: A4:C1:38:3E:xx:xx
      name: "Sensor_1 Temperature"
      name: "Sensor_1 Humidity"
      name: "Sensor_1 Battery Level"
  - platform: xiaomi_lywsdcgq
    mac_address: A4:C1:38:66:xx:xx
      name: "Sensor_2 Temperature"
      name: "Sensor_2 Humidity"
      name: "Sensor_2 Battery Level"
  - platform: xiaomi_lywsdcgq
    mac_address: A4:C1:38:84:xx:xx
      name: "Sensor_3 Temperature"
      name: "Sensor_3 Humidity"
      name: "Sensor_3 Battery Level"
  - platform: xiaomi_lywsdcgq
    mac_address: A4:C1:38:79:xx:xx
      name: "Sensor_4 Temperature"
      name: "Sensor_4 Humidity"
      name: "Sensor_4 Battery Level"

  - platform: homeassistant
  - platform: restart
    name: wemos_d1_mini_1-restart
    id: restart_switch

After flashing the Xiaomi with new .bin file, it does not report the temperature on the web-page on your phone anymore. It does work, just dont forget to disconnect your phone (bluetooth) from the Xiaomi thermometer so the ESP can pick it up after 1 or 2 minutes. You can tell in the log of ESPhome if it connects right away.