Xiaomi BLE Temperature and Humidity sensor

I have had this sensor running on Hassio on Pi3+ for about 18 months.
It is certainly not a reliable product, Sometimes it sends data for 2 weeks, others is runs for a day and lose connection.
I have fixed it using the following methods. 1. restarting the bluetooth add on. 2. moving the sensor to directly next to it and pressing the bluetooth button on the back of the sensor. 3. doing a full HA reboot.
I saw on another forum about how is also losing connection to the Mi Home app as well, so I think it is the product. There also doesnā€™t appear to have been a firmware update for a long time.

I also use the square zigbee temperature sensors in other parts of my house, and they are far more reliableā€¦ Only occasionally have then lose connect, and the fix is to remove them from the Mi Home app and add it back in. HA usually detected is immediately.

If anyone is struggling with these sensors and has a spare Pi, or Pi Zero around - there is a reliable alternative to having and keeping them working.

Install Hassbian on the spare Pi, setup the Xiaomi as per normal on that.

Then use the Rest Sensor component on your main (hass.io) Pi to connect to the Mi Temps. Iā€™ve used this combination for over a year and have had no drop-outs.

For example, my main hassio gets the readings from my garage Xiaomi BLE via a Pi A+ running Hassbian like this:

  - platform: rest
    resource: http://192.168.1.xx:8123/api/states/sensor.mitemp_bt_one_garage_temperature
    name: mitemp_one_garage_temp
    value_template: '{{ value_json.state }}'
    unit_of_measurement: "Ā°C"

  - platform: rest
    resource: http://192.168.1.xx:8123/api/states/sensor.mitemp_bt_one_garage_humidity
    name: mitemp_one_garage_humidity
    value_template: '{{ value_json.state }}'
    unit_of_measurement: "%"

  - platform: rest
    resource: http://192.168.1.xx:8123/api/states/sensor.mitemp_bt_one_garage_battery
    name: mitemp_one_garage_battery
    value_template: '{{ value_json.state }}'
    unit_of_measurement: "%"

On hassbian, the Xiaomi sensors are setup as normal:


## Mi Temp BT

  - platform: mitemp_bt
    mac: '4C:65:A8:xx:xx:xx'
    name: mitemp_bt_one_garage

I run two Xiaomi BLE sensors via this Pi, along with 8 MiFlora plant sensors - and all that data is retrieved using Rest sensors on my main Hassio install.

I gave up trying to get Hass.io play nice with bluetooth ages ago, and havenā€™t changed my mind, as this way I can extend Bluetooth detection out to the edge of my Wifi :slight_smile:

1 Like

I had this issue when I used NR as well. As Iā€™m now playing with some ESP32 boards and ESPHome Iā€™ve used them to connect to the sensors and not had any issues since.

Hi, I just want to share my problem: Since I updated hassio to 0.96, my thermometers work only few minutes since restart. Then I get this error message and they stop updating.

WARNING (SyncWorker_19) [custom_components.mitemp_bt.sensor] Polling error [Errno 32] Broken pipe

Prior to this hassio update they worked fine (yes I was having ā€œUpdate of sensor.bt_teplomer_2_humidity is taking over 10 secondsā€ but it repaired itself next time. And I didnā€™t really care if they missed one datapoint)

Honestly those sensors are weird* and I am thinking I will get rid of them. Zigbee versions are more reliable. On the other hand, I liked them (bluetooth ones) because I could poll them on request - meaning update every 30seconds for example. With zigbee it depends on the sensor itself how often it transmits data. And it has some strange algorithm and when there is no rapid change it will not transmit any data for 30minutes easily. Also I am not a big fan of CR2032 cells. I love standard AAA batteries used un bluetooth ones.

*Another strange thing with those thermometers - did anyone noticed this as well? I have the thermometer at ~3Ā°C (fridge) and took it out and it started showing (in HASS) really high temperatures like 28Ā°C etc (there was around 23Ā°C in the room) but on the LCD it showed the correct temperature (14Ā°C etc). WTF? How this happens? It returns to correct temperature slowly and then stays at sync with LCD value.

Hello,
I updated from 0.95.4 to 0.96.5 and now my 2 BT xiaomi thermometers are now no longer recognizedā€¦

in the log I get:

Updating mitemp_bt sensor took longer than the scheduled update interval 0:00:30

anyone else experiencing this with the update???
Thanks

Me tooā€¦ after update to 0.96.5 my xiaomi ble works some minutes since restartā€¦ then the same error (polling errorā€¦ broken pipeā€¦ etcā€¦)

This issue finally forced me to look into ESPhome. I just took spare ESP32 a made it esentially into bluetooth to wifi bridge. Now my thermometers are connected to ESP32 and ESP32 transmitts the values over wifi to Home Assistant. It looks more solid than using integrated BT in rPi.
Also I can now move rPi anywhere in my apartment as only the ESP32 has to be in range to receive signal from those thermometers.

1 Like

Please, write a short step by step tutorial on how to do this!

Main info here: https://esphome.io/guides/getting_started_hassio.html

How it works in a nutshell that took me some time to understand - you have addon in home assistant where you manage all your ESPhome devices. You write code for them and this addon compiles firmware for them. There are multiple ways how to upload the firmware to the target device - you either download .bin to your computer and use ESPHome-Flasher or you connect USB directly to your rPi.
Later updates to your code can be uploaded wirelessly to the device directly.

My summary - installed ESPhome addon to home assistant. Opened this addon and added new device. Filled in necessary details about my wifi etc.
Added following code, saved, uploaded

esp32_ble_tracker:

sensor:
  - platform: xiaomi_mijia
    mac_address: 4C:65:A8:D7:9E:1C
    temperature:
      name: "Xiaomi BT 1 Temperature "
    humidity:
      name: "Xiaomi BT 1 humidity"
    battery_level:
      name: "Xiaomi BT 1 Battery"
      
  - platform: xiaomi_mijia
    mac_address: 4C:65:A8:DD:40:27
    temperature:
      name: "Xiaomi BT 2 Temperature "
    humidity:
      name: "Xiaomi BT 2 humidity"
    battery_level:
      name: "Xiaomi BT 2 Battery"
      

Last thing to do was go (in home assistant) to configuration, integrations, add, find ESPhome, fill-in IP address of the ESP32 and save. And now simply those sensors appeared in home assistant

3 Likes

For those who have problems with the stability of the sensor reading, the information I found here may be very useful.

Briefly: Xiaomi BLE Temperature and Humidity sensor does not require a poll, it already sends readings about once a second. That is, even if in conditions of poor communication you successfully receive only 1 reading of 60, then this will give you an update once a minute! The user who published this information (via the provided link) has a solution for this kind integration (albeit for now a test, but working).
1 Like

in the configuration.yaml i need just write the following?

sensor:
  - platform: mitemp_bt

i ran the commands and put the custom component , but i cant see the entities?

Yes thatā€™s all. The new name of the sensor looks like: sensor.mi_t_your device mac address.

1 Like

its updating instantly, works amazing, how about battery life?

Battery life not affected, because this sensor is designed so that it sends data once a second itself, without the need to poll it. The only problem this code can lead to - is the fast increase in database size, especially if you have a lot of these sensorsā€¦ Sorry for bad English.

1 Like

Any one has an idea how to avoid the database to increase? its got large in no time

No you need custom files in your config/custom_componets/mitemp_bt folder from github.
then this will work.

Running ESPHome esp32_ble_tracker w/platform: xiaomi_mijia on ESP32 NodeMCU makes my router loose its 2.4GHz bands and requires a router restart.

Seems like the BLE is interfering with my Wi-Fi. Anyone having this issue / Any way to limit the BLE scan?

That looks like ultra shitty router :smiley: I can understand that is looses connection but requiring restart? That weirdā€¦ Try changing wifi channel to different one.

This is an issue with the mitemp_bt_poller.py, namely the way the outhor parses the string. It assumes two digits without a sign. As soon as you get below 10C it will fail.

Hi!!! I have same issue since march / april! Iā€™ve searched without success. Whatā€™s your router model?