There’s a neat looking Xiaomi sensor with a display which is capable of showing temperature and humidity data.

It can trasmit this information over Bluetooth Low Energy (BLE), and if we want to get that in command line from a Raspberry Pi, this is what we need to do.

Hardware
Xiaomi Mijia Hygrothermo v2 sensor

Raspberry Pi model which has inbuilt Bluetooth module:
Raspberry Pi 3B / Raspberry Pi Zero W / Raspberry Pi 3B+

Software

It will use ratcashdev’s mitemp library, which in turn depends on ChristianKuehnel’s btlewrap library, for me it was kinda tricky where to put the btlewrap inside mitemp, but it works the way I’ll show below. I also recommend to use bluepy instead of gatttool as a BLE backend.

pi@pi3pimatic:~ $ git clone https://github.com/ratcashdev/mitemp.git
Cloning into 'mitemp'...
remote: Counting objects: 66, done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 66 (delta 23), reused 59 (delta 16), pack-reused 0
Unpacking objects: 100% (66/66), done.
Checking connectivity... done.

pi@pi3pimatic:~ $ cd mitemp/

pi@pi3pimatic:~/mitemp $ git clone https://github.com/ChristianKuehnel/btlewrap.git btlewrap-git
Cloning into 'btlewrap-git'...
remote: Counting objects: 106, done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 106 (delta 48), reused 65 (delta 21), pack-reused 0
Receiving objects: 100% (106/106), 25.66 KiB | 0 bytes/s, done.
Resolving deltas: 100% (48/48), done.
Checking connectivity... done.

pi@pi3pimatic:~/mitemp $ mv btlewrap-git/btlewrap/ .

pi@pi3pimatic:~/mitemp $ ls
CONTRIBUTING.md  README.md  btlewrap-git  demo.py    pylintrc               requirements.txt       setup.py  tox.ini
LICENSE          btlewrap   build.sh      mitemp_bt  requirements-test.txt  run_integration_tests  test

pi@pi3pimatic:~/mitemp $ rm -rf btlewrap-git/

pi@pi3pimatic:~/mitemp $ demo.py poll 4C:65:A8:D4:A3:86
Getting data from Mi Temperature and Humidity Sensor
FW: 00.00.66
Name: MJ_HT_V1
Battery: 100
Temperature: 23.7
Humidity: 52.0