Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

OK, guys. Here is a beta with added support for other Xiaomi BLE broadcasting sensors:

  • LYWSD02 (rectangular body, E-Ink) Thanks
  • CGG1 (round body, E-Ink)
  • HHCCJCY01 (MiFlora, it was not tested at all, reports only temperature so far.
    If you MiFlora owner, then you can help…)

Thanks @JJussi and Sergey Sazonov for hcidumps.

If you installed the component via HACS, then you can take part in testing, if on the component’s page in HACS enable “Show beta” (a “three dots menu” in the upper right corner of the page).

It would be really nice to have something, like miflora-mqtt-daemon, that you can install on a another, distant Pi as an example, which would send the data through MQTT. That way, you can have those sensors at some distant places.

ESPhome implements support for passive monitoring of Xiaomi sensors. But I have not tried.

As a LYWSD02 sensor owner I can confirm that it works! Excellent work! Kudos!

1 Like

LYWSD02 works for me as well, big thanks!

If the device sends it, any chance Battery level could be added too?

Unfortunately, it is seems like LYWSD02 sensor does not broadcasts information about the battery. I have BT dumps from two different people with several sensors of this type, and none of them have battery information… In any case, if the sensor suddenly informs about the battery, then you will see this, since the Xiaomi service data format is generally the same for all such sensors, and processed regardless of sensor type :man_shrugging:

1 Like

Ah, I didn’t check before but not even Xiaomi’ s app has battery info.
Was too exited about getting the sensors data in to HA :slight_smile:
Thanks again !

1 Like

I’m trying to connect MJ_HT_V1 and LYWSD02 for more than two hours with no success :confused: It does not work through neither built-in integration (no data), nor via this custom component (no entities created). Any help would be highly appreciated!

I have RPi 4 + ssd + docker + hassio setup and don’t use any other bluetooth integrations. I have just started playing with HA so I don’t have much components/integrations either.

[email protected]:~ $ apt show bluetooth -a
[email protected]:~ $ apt show bluetooth -a
Package: bluetooth
Version: 5.50-1+rpt1
Priority: optional
Section: admin
Source: bluez
Maintainer: Debian Bluetooth Maintainers <[email protected]>
Installed-Size: 70.7 kB
Depends: bluez
Suggests: bluez-cups, bluez-obexd
Homepage: http://www.bluez.org
Download-Size: 43.0 kB
APT-Sources: http://archive.raspberrypi.org/debian buster/main armhf Packages
Description: Bluetooth support (metapackage)
 This package provides all of the different plugins supported
 by the Bluez bluetooth stack.

Package: bluetooth
Version: 5.50-1
Priority: optional
Section: admin
Source: bluez
Maintainer: Debian Bluetooth Maintainers <[email protected]>
Installed-Size: 70.7 kB
Depends: bluez
Suggests: bluez-cups, bluez-obexd
Homepage: http://www.bluez.org
Tag: role::dummy
Download-Size: 42.9 kB
APT-Sources: http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
Description: Bluetooth support (metapackage)
 This package provides all of the different plugins supported
 by the Bluez bluetooth stack.
[email protected]:~ $ apt show bluez -a
[email protected]:~ $ apt show bluez -a

Package: bluez

Version: 5.50-1+rpt1

Priority: optional

Section: admin

Maintainer: Debian Bluetooth Maintainers <[email protected]>

Installed-Size: 3,680 kB

Depends: libasound2 (>= 1.0.17), libc6 (>= 2.28), libdbus-1-3 (>= 1.9.14), libdw1 (>= 0.127), libglib2.0-0 (>= 2.31.8), libreadline7 (>= 6.0), libudev1 (>= 196), kmod, udev, lsb-base, dbus

Suggests: pulseaudio-module-bluetooth

Conflicts: bluez-audio (<= 3.36-3), bluez-utils (<= 3.36-3)

Breaks: udev (<< 170-1)

Replaces: bluez-audio (<= 3.36-3), bluez-input, bluez-network, bluez-serial, bluez-utils (<= 3.36-3), udev (<< 170-1)

Homepage: http://www.bluez.org

Download-Size: 764 kB

APT-Manual-Installed: no

APT-Sources: http://archive.raspberrypi.org/debian buster/main armhf Packages

Description: Bluetooth tools and daemons

This package contains tools and system daemons for using Bluetooth devices.

.

BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source

project distributed under GNU General Public License (GPL).

Package: bluez

Version: 5.50-1+b12

Priority: optional

Section: admin

Source: bluez (5.50-1)

Maintainer: Debian Bluetooth Maintainers <[email protected]>

Installed-Size: 3,681 kB

Depends: libasound2 (>= 1.0.17), libc6 (>= 2.28), libdbus-1-3 (>= 1.9.14), libdw1 (>= 0.127), libglib2.0-0 (>= 2.31.8), libreadline7 (>= 6.0), libudev1 (>= 196), kmod, udev, lsb-base, dbus

Suggests: pulseaudio-module-bluetooth

Conflicts: bluez-audio (<= 3.36-3), bluez-utils (<= 3.36-3)

Breaks: udev (<< 170-1)

Replaces: bluez-audio (<= 3.36-3), bluez-input, bluez-network, bluez-serial, bluez-utils (<= 3.36-3), udev (<< 170-1)

Homepage: http://www.bluez.org

Download-Size: 763 kB

APT-Sources: http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages

Description: Bluetooth tools and daemons

This package contains tools and system daemons for using Bluetooth devices.

.

BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source

project distributed under GNU General Public License (GPL).

Thanks in advance!

How far sensors from HA host? (at the time of installation it is worth placing them closer if they are far)
Please check also, that the hcidump utility is installed (required for the custom component to work).
It should also be remembered that the custom component creates entities only upon receipt of data, that is, it takes at least one period (60 seconds by default) - you should wait a few minutes.
It may be worth doing all the points from the installation instructions (including those that are not required for hassio).
I don’t know what else to help… Enable debugging for the component and see the logs:

logger:
  default: warn
  logs:
    custom_components.mitemp_bt: debug
1 Like

Thanks for such quick response!
It seems that distance indeed was the key because I have everything already set up like you just said. It was not so obvious to me because I my xiaomi sensor was just 3 meters from RPi and it was visible when running hcitool lescan manually.
I placed one next to each other and it was recognised flawlessly.

Thank you so much!

PS It seems that either BT radio is somehow weak in RPi 4 or because of some interferences (ConBee, WiFi, SSD) it has less range than my RPi Zero.

The custom component has a longer range, since it just listens. If it does not provide the desired range, then it is worth look at options with external bluetooth or device with ESPHome as intermediate (I’m just testing ESPHome on ESP32 - pretty reliable solution for far placed sensors).

I’m testing custom component :slight_smile: It stops reading sensor data even if I move it like 1.5-2 meters from the RPi. That is probably caused by interference from other radios.

I am about to play with ESP8266 or Arduino + HM-10 BT module and set up OpenMQTTGateway. I may also go with bt-mqtt-gateway on RPi 1 or RPi Zero that I own. It looks promising and I will definitely need much more range than a few meters :wink:

I have also external BT USB dongle from my older RPi, but I’m afraid that it may negatively affect ConBee. That’s why I will probably try to go other solutions that will hopefully work stably as standalone units – “set it and forget it”.

2 Likes

How to set the /tmp to RAM as adviced in the repository running HASSIO after installing the custom_component?

Were you able to get LYWSD03MMC data dumps from someone and getting it to work yet?

Thanks.

Unfortunately, no. There are dumps, but everything is complicated there… The format is different from what we saw before. Here is a discussion on this.

I confirm this behaviour after moving from rp3 to rp4. Previously sensors were working from tens of meters and now they need to be almost next to raspi :confused:

Does anyone have any experience with the ‘new Xiaomi Mijia Temperate and Humidity Sensor with LCD Screen’
http://s.aliexpress.com/yuInaQne

Described as a new version, I hoped it would work as the same as the previous, over bluetooth, but appears not.

I wouldn’t know where to start with testing the new version’s compatibility, can anyone advise or better still help?

Thanks in advance.

With the current firmware version it doesn’t use the same principle of sensor data broadcasting (service data) compared to its brothers.

And by the way not so easy to integrate as its brothers.

I have 6 new square Xiaomi LCD sensors. Using hcitool lescan I found their MACs and names (LYWSD03MMC), and by using gatttool interactive mode, after connecting to the sensors I start getting every few seconds this kind of info:

[email protected]:~$ sudo hcitool -i hci1 lescan
[sudo] password for bogdan:
LE Scan ...
A4:C1:38:3C:66:EF (unknown)
A4:C1:38:3C:66:EF LYWSD03MMC
[email protected]:~$ gatttool -i hci1 -I
[                 ][LE]> connect A4:C1:38:3C:66:EF
Attempting to connect to A4:C1:38:3C:66:EF
Connection successful
Notification handle = 0x0036 value: 06 09 1f 15 0c
Notification handle = 0x0036 value: 06 09 1f 15 0c
Notification handle = 0x0036 value: 06 09 1f 15 0c
[A4:C1:38:3C:66:EF][LE]>

I could determine that the first 2 bytes are the temperature in celsius (0x0906 = 2310 >> 23.1C), and the third byte is the humidity (0x1f = 31 >> 31%). I assume that the last 2 bytes contain info about the battery, but I can’t figure out the format. For the temperature and humidity values I confirmed this format on all 6 sensors (hex values correspond to the display values).
Can someone help with integrating this in HASS?

For those interested: here’s a discussion and search for a solution with passive receiving of LYWSD03MMC advertisements.