Home Assistant Community

Xiaomi Mijia bluetooth temperature & humidity sensor compatibility

#1

I’m interested in adding temperature and humidity sensors throughout my house. On some places it would be nice to physically see the temperature and humidity on a display without the need for a phone.

When looking for alternatives that are nice enough to be seen I came across the Xiaomi Mijia bluetooth temperature and humidity sensor with bluetooth. A nice walkthrough can be seen here:

My question is whether it is possible to use these with Home-Assistant, I know the regular temperature and humidity sensors of Xiaomi / Aqara are and I will be using some of those (too bad you need a gateway for those).

Has anyone been fiddling with the code that was written for Domoticz to get it working in HA?

Code for Domoticz: https://github.com/pFenners/mijia-sensor-domoticz

4 Likes

#2

Good question, I am also interested in this sensor.
I have a few of the small Xiaomi Aqara temp and humidity sensors and they work well, but as Emacee said, the Bluetooth sensor also displays the values in place and that’s better in many cases.

0 Likes

#3

Indeed i’d love to see this device supported too. I have 2 of them (one arrived with a broken screen so i was sent a replacement). Being able to use these in home assistant would be amazing!

0 Likes

#4

I have hacked some basic shell scripts to get the Bluetooth sensor data and feed it into mqtt … which is working very well …

1 Like

#5

Hi @mig, what do you use to read the BT data? would you share your scripts? What about connecting it to the Xiaomi gateway?

0 Likes

#6

@mig Can you please share your config/script and any requirements? thanks buddy !

0 Likes

#7

I used hcitool lescan to find out the correct bt mac adress. My sensors show up as MJ_HT_V1

I run it in a crontab to get updated data every ten minutes.

#!/bin/bash

bt="4C:xx:xx:xx:xx:xx"
sensor="sensor1"

RET=1
until [ ${RET} -eq 0 ]; do
    data=$(/usr/bin/timeout 20 /usr/bin/gatttool -b $bt --char-write-req --handle=0x10 -n 0100 --listen | grep "Notification handle" -m 2)
    RET=$?
    sleep 5
done

RET=1
until [ ${RET} -eq 0 ]; do
    battery=$(/usr/bin/gatttool -b $bt --char-read --handle=0x18 | cut -c 34-35)
    RET=$?
    sleep 5
done

temp=$(echo $data | tail -1 | cut -c 42-54 | xxd -r -p)
humid=$(echo $data | tail -1 | cut -c 64-74 | xxd -r -p)
batt=$(echo "ibase=16; $battery"  | bc)

if [[ "$temp" =~ ^[0-9]+(\.[0-9]+)?$ ]]
then
/usr/bin/mosquitto_pub -h <ip> -V mqttv311 -u <user> -P <password> -t "homeassistant/xiaomi/$sensor/temp" -m "$temp"
fi

if [[ "$humid" =~ ^[0-9]+(\.[0-9]+)?$ ]]
then
/usr/bin/mosquitto_pub -h <ip> -V mqttv311 -u <user> -P <password> -t "homeassistant/xiaomi/$sensor/humidity" -m "$humid"
fi

if [[ "$batt" =~ ^[0-9]+(\.[0-9]+)?$ ]]
then
/usr/bin/mosquitto_pub -h <ip> -V mqttv311 -u <user> -P <password> -t "homeassistant/xiaomi/$sensor/battery" -m "$batt"
fi


9 Likes

#8

thanks buddy!!

by the way a new xiaomi temperature sensor is out here it is :

https://www.aliexpress.com/item/Original-xiaomi-mijia-Mi-miaomiaoce-Thermometer-Temperature-Humidity-Sensor-with-LCD-Screen-Digital-E-ink-electronic/32848309911.html?spm=2114.search0104.3.16.6bfc3cdfV3OjDm&ws_ab_test=searchweb0_0,searchweb201602_1_10152_10151_10065_10344_10130_10068_10324_10342_10547_10325_10343_10546_10340_10548_10341_10190_10084_10083_10618_10307_10303_10313_10059_10184_10534_100031_10103_10627_10626_10624_10623_10622_10621_10620,searchweb201603_38,ppcSwitch_5&algo_expid=3f78f5c1-76f3-4892-9279-a161ccdda650-2&algo_pvid=3f78f5c1-76f3-4892-9279-a161ccdda650&transAbTest=ae803_5&priceBeautifyAB=0

I dont know if it can be linked to HA as it doesnt state how it operates and connects to the Xiaomi app…

0 Likes

#9

I can see that this version does not have any option of wireless connectivity. Am I correct?

0 Likes

#10

I am of the same opinion as you cannot see any wireless connectivity

0 Likes

#11

Hi, Home Assistant has already the sensor miflora based on the same protocol. It should be straightforward to look difference between https://github.com/pFenners/mijia-sensor-domoticz/blob/master/README.md and https://github.com/Tristan79/miflora and migrate it from Domoticz to Home Assistant…

0 Likes

#12

Hi mig,

How I can run this code ?

0 Likes

#13

hi,
check out my implementation https://github.com/dolezsa/Xiaomi_Hygrothermo
suggestions are welcome.

4 Likes

#14

Hi, I also created my implementation, that looks similar to MiFlora one, with the same parameters. This sensor is going to be used a lot, so somebody should create a Python library like https://github.com/open-homeautomation/miflora and use it in both HomeAssistant and Domoticz…There we will create a “standard”…Maybe this “open-homeautomation” guy should host it…I will write to him…

1 Like

#15

Hi flavio20002, is there any chance to share your implementation of MiFlora for the HygroThermo sensor? Can’t get it to work…

0 Likes

#16

Sure! It’s working perfectly with 2 sensors and with Raspberry Pi 3. Look at some graphs on Grafana.

4 Likes

#17

Hi there!

Anyone knows its possible to access data using a Bluetooth gateway (like the Xiaomi bed lamp) instead of connecting directly to the sensor through Bluetooth?

Cheers!

0 Likes

#18

I am running on a QNAP Docker, what other alternatives are there to integrate this?

0 Likes

#19

@dolezsa would it still need a gateway ?
I would really like to use a couple of these, but I understand it needs a bluetooth gateway of some sort.

I don’t feel like buy the xiaomi lamp, is there anything else that can do it, or do I not need it at all (the bluetooth gateway that is)

Thanks for the help !

Regards
S

0 Likes

#20

hi @STVE, all you need is any bluetooth le capable device (in my case, bt usb dongle).

0 Likes