Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

Is the stream enabled in your config?

I have also been having the same issue. Mine was working fine up until a few days ago, and now its unreliable. I restarted yesterday and its been fine for 24 hours now, I hope it stays that way. I have seen this error in the log many times before but over the last few days it’s not really worked at all

I have the same problem. It works for about an hour, and then an error.

When HA was downgraded to 95.4 the sensor is working again. I returned to 96.5 and the sensor is dead again.

What do you mean by stream ?

It seems to confirm what I suspect, an issue with the latest release of Hassio…

@brent0np, @genik : Are you both on Hass.io on a Rpi ? Has the issue appeared after a recent upgrade ?

I believed the problem is stream caused, but it doesn’t.

ok, thanks. I am not using this component in my config.

Yes I am using a pi. Yes it would appear it’s an issue after a recent upgrade.

Good evening
Yes, I have a hassio in docker on rasberry 3B. Now version 96.5 and I don’t remember which version started having problems. What a surprising bluetooth works and I can see by the command bluetoothctl Xiaomi Mijia. Why does hassio stop receiving data? Unclear.

I was able to implement component for parsing of Bluetooth Low Energy packets payload that contains temperature/humidity/battery data and that are emitted each second by the sensor. That allows to auto-detect new sensors (both first and second versions) and passively receive data each second without battery impact at all.

There are 3 reasons why I didn’t commit my changes into home assistant repository yet (but I’m working on it):

  1. It requires 1 more command to run on Raspberry Pi itself that allows hcidump command to run without root access:
sudo setcap 'cap_net_raw+ep' `readlink -f \`which hcidump\``
  1. Configuration support is not yet ready, whole configuration looks like this now:
sensor:
  - platform: mitemp_bt
  1. I did everything inside one file that goes against coding standards of Home Assistant. I’m working on it and expect to create merge request in the next months.

In case you’d like to test it on your system, here is the link to my custom_component mitemp_bt. The folder to unpack is /home/homeassistant/.homeassistant/custom_components/ Also you need to run the command I wrote above to allow rootless access to bluetooth device for hcidump tool. I will be glad for constructive feedback.

9 Likes

It is working for me.
And a big plus, there is no any warning because of detection or polling error like with previous version.

It didn’t work initially (I suspect my BLE dongle is a bit ordinary) but second reload is working well getting temperature data every second now!

Thank you for your work, Ivan! I was pleasantly surprised by the news that this sensor sends readings every second, and does not require polling. Such operation of the sensor provides a large window for filtering its readings, but unlike the original mitemp_bt with a five-minute poll, the delay here will be acceptable even with a median of 30 or more (beautiful fast smooth graphics without affecting power consumption). We look forward to the release of your code!

On my RPI 3B+ with Raspbian Buster and HA 0.97.0 (virtualenv) your code works fine. The log has cleared of mitemp_bt timeouts.
The only thing, in addition to your instructions, I had to do:

sudo apt install bluez-hcidump

Hello,

Thanks for your code.
It seems that it requires BLE support on the dongle, right?
When I setcatp, I had this error

Set scan parameters failed: Input/output error

Thanks

Here is my attempt to implement filtering (and reduce HA DB growth rate :slight_smile:
The sensor status is updated with the average of all readings, received between updates (hardcoded 60 secs). In sensor state details you can see actual number of averaged readings ("median: ").
This is my first experience with Python and HA dev, please do not laugh much )

Yes, BLE support required.

can you write detailed, how to use your sensor? where to place file and config for it?
thanks!

My Bluetooth dongle is 4.0 and supports BLE I think. I was able to connection to Xiaomi Temp bluetooth before with this dongle.
I’m on Debian 10

Any one has an idea how to avoid the database to increase?