Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

@xx_Nexus_xx @thesailor

This is working for me.

First stop the Home Assistant service. For me its: sudo systemctl stop home-assistant@homeassistant

I took a backup:
sudo cp /srv/homeassistant/lib/python3.5/site-packages/mitemp_bt/mitemp_bt_poller.py /srv/homeassistant/lib/python3.5/site-packages/mitemp_bt/mitemp_bt_poller_original.py

Then edited
sudo nano /srv/homeassistant/lib/python3.5/site-packages/mitemp_bt/mitemp_bt_poller.py

Change _parse_data function (it should be obvious but it’s 1 new line and 2 changed lines):

data = self._cache

temp,humidity  = data.replace("T=", "").replace("H=", "").rstrip(' \t\r\n\0').split(" ")

res = dict()
res[MI_HUMIDITY] = float(humidity)
res[MI_TEMPERATURE] = float(temp)
return res

Save, exit, and restart home assistant: sudo systemctl start home-assistant@homeassistant

Or just wait until a fix gets pushed out. I’ve no idea how to release as a patch properly…

Attached is a pic of my sensor in the fridge - I needed to test somehow :slight_smile:

Enjoy!!
46|356x212

1 Like

WOW! Awesome work @randomdisco! Thanks for putting the time into it!
That was a fast turnaround and a great contribution to @flavio20002 's code (or ratcash ?). Definitely thx to both of you.

I will try to squeeze some time in to test, maybe tonight (Melbourne time).

Cheers.

Well,

I don’t have access to the RPI which is running at a remote site, so trying with Docker on my laptop and the spare sensor.

I don’t know how to tell HA how to load the custom mitemp_bt_poller.py source file, or edit it. I believe the later isn’t possible when using Docker.
I have tried by placing the edited file under “custom_components”.

I will have to wait a few more days before being able test - unless I can be pointed towards how to do the above, with Docker.

I noticed that someone else submitted a potential fix on github.

Cheers.

1 Like

Sorry I can’t help more. I don’t have Docker experience and I can’t create a branch to the original code to push a change / make a pull request. Not sure how to get the fix propagated to the Home Assistant :frowning:

The other fix on GitHub is another way of doing the same thing. Either should work so I don’t care which one gets put in. I only tested mine with single digit temp - I don’t know how to test with single digit humidity and I didn’t leave my sensor in the fridge long enough to test negative temps (I’m in Brisbane so negative unlikely to occur).

Does anyone else know how to propagate one of the fixes to Home Assistant?

1 Like

I tried the custom components from flavio2002. But i can’t get my Temperature Sensor to work.
I only get the following Messages:
2018-07-28 17:21:30 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.mijia_batteria is taking over 10 seconds
connect: Connection refused (111)
connect: Connection refused (111)
2018-07-28 17:21:30 INFO (SyncWorker_11) [custom_components.sensor.mitemp_bt] Polling error [Errno Could not read data from Mi sensor %s] 4C:65:A8:D8:AA:E1
2018-07-28 17:21:41 INFO (SyncWorker_12) [custom_components.sensor.mitemp_bt] Polling error [Errno Could not read data from Mi sensor %s] 4C:65:A8:D8:AA:E1
2018-07-28 17:21:41 INFO (SyncWorker_13) [custom_components.sensor.mitemp_bt] Polling error [Errno Could not read data from Mi sensor %s] 4C:65:A8:D8:AA:E1
2018-07-28 17:22:12 INFO (SyncWorker_15) [custom_components.sensor.mitemp_bt] Polling error [Errno Could not read data from Mi sensor %s] 4C:65:A8:D8:AA:E1
2018-07-28 17:22:12 INFO (SyncWorker_4) [custom_components.sensor.mitemp_bt] Polling error [Errno Could not read data from Mi sensor %s] 4C:65:A8:D8:AA:E1

Can you help me?

Hi sorry to ask here @dolezsa
I want to use this xiaomi BLE temp and humid sensor… However I’m running Hassio in Ubuntu VM under Win 10 pc without any integrated Bluetooth adapter. I’m planning to buy a Bluetooth adapter. However in my local area I can’t seem to find an adapter which is compatible with this xiaomi. The one avalaible is USB Bluetooth dongle compatible with Bluetooth version 4.0 for about $5.

Do you think this kind of dongle will be compatible and able to found the xiaomi sensor? Could you please post a pic or link of your Bluetooth dongle?

hi, you can buy from aliexpress or from something similiar one piece like this:
image
it costs around 3 USD. the requirement is that it supports BT 4.0.

Ah perfect! Yes this is the kind I’m looking at in my local place… Will order it soon while waiting for the xiaomi gateway and sensors to arrive… Thank you very much for the confirmation…

Did this get pushed through to Home Assistant in the end?
Last night it got below 10 degrees for the first time and sure enough I seen the same thing on my graphs.

I’m running HassOS 0.75.3 so wondering if I update will it fix this?

This cheap BLE Dongles have one disadvantage - very low range/radio coverage. One wall and 5-6 meters makes connection unreliable (RSSI -90dBi) with sensor, a lot of read timeouts in HASS logs.
I’m looking for better dongle, with good (maybe external?) antenna.

I have heard good things about this one: https://www.lm-technologies.com/product/bluetooth-v4-0-dual-mode-long-range-usb-adapter-lm1010/
However that was for a different use case, not sure if Hass supports it (I think it should)

It’s boradcom based adapter AFAIK. And the proce looks like $40-50 per piece :confused:

Yep, not cheap, however you were looking for something with an external antenna :slight_smile:

I did not full understand the description how to install the sensor

Will this senor work with a MI Gateway or a Yeelight Bedside Lamp with BTE out of the box or would I need some special devices / receivers?
Will I get the required MAC address using the mi home app?
Can I use several sensors in parallel?

The background: I have some aqara temperature and humidity sensors connected through the mi gateway and they are working fine.
Now I think to place a sensor in each room, but a sensor with a display would be better than without a display.

You need the device that has Home Assistant installed on it to already have BLE functionality - such as a Raspberry Pi 3/NUC with a wireless card - or add an USB BLE dongle (that is Bluetooth 4.x, there are still to be found dongles featuring Bluetooth 2.x/3.x).

Xiaomi Gateway (I don’t know about the Bedside Lamp) doesn’t have the BLE functionality.

Mi Home app is used on the phone to pair with the Mi Jia sensor (Mi Flora sensor for plants monitoring also uses the same protocol) and can control Zigbee, Wifi and BLE devices. AFAIK, MAC is not shown in the Mi Home app but it is relatively easy to find it with any BLE scanning app if not inclined to do the dirty work of BLE scanning by yourself.

There are some other projects that use low energy devices (ESP8266 or ESP32; ESP8266 needs a BLE module such as HM10/AT-09 flashed with HM10 firmware) and act as BLE gateways thus making the values available to HA - ESPHome/OpenMQTT, etc.

1 Like

Thank you for your answer. My Pi 3 is to far from the rooms, so I will better use additional “normal” Zigbee sensors. It is good to got this answer now, before ordering them. And the Zigbee sensors are currently on sale, that’s also fine :slight_smile:

You’re welcome.

I have the Mi Jia sensors in each room, but mainly for the slick look. As the BLE protocol is still buggy, I use an ESP8266 with DHT22 sending data over MQTT (I’ve added also light sensors so it is a pretty impressive device for under 5 USD), but if you already have the ones with Zigbee there’s no need for other devices sending data to HA.

Could have also gone for the e-ink version (no wifi/BLE/Zxx connectivity):
https://www.aliexpress.com/item/Original-xiaomi-mijia-Mi-miaomiaoce-Thermometer-Temperature-Humidity-Sensor-with-LCD-Screen-Digital-E-ink-electronic/32854817316.html

so anyone was able to connect few temp sensors by Xiaomi ?
Can it work directly without gateway?

These Bluetooth ones work without the gateway. I use openmqttgateway on esp32 board to get values from mine

can you please elaborate how to do it ?
what is the effective range for it?
Is it stable?
is someone added wired solution instead of battery?