Xiaomi LCD thermometer

Can Xiaomi LCD thermometer be used with openhab without gateaways ? Via bluetooth or MQTT or something like that? On raspberry pi 3 (wifi+bt)

I’m talking about round lcd thermometer for 10$ or something like that.

Isn’t it bluetooth?

Yes, i was thinking of using Bluetooth bindings.

Hi @RokSiEu,

I use this kind of thermometer at office. A raspberry is fetching the values via Bluetooth every 30 minutes. The values are transmitted via MQTT to openHAB.

Required packages:

       sudo apt-get install pi-bluetooth raspberrypi-sys-mods python3 python3-pip
       sudo pip3 install paho-mqtt

Tool get values: https://github.com/pFenners/mijia-sensor-domoticz

I will send you my working example via PM.

JB

I will try this once my device arrives.

My device arrived and I successfully connected it to openHAB.

I had to add the new mac address prefix (see: https://github.com/aqualx/miflora-mqtt-daemon/pull/3).

But it looks like the device is off by at least 1 °C and 15% humidity. :frowning_face:
Anybody else have checked if the measurements are correct?

I own four of them and compared the readings with another thermometer. All five temps were within 0.2 °C. The humidity was close too …

For me it was acceptable.

Hello!
I am trying to get the same thermometer to work with openhab. Could it be possible to get the example, for to get it work. Cheers!

Here you go:
mijia-sensor.zip.txt (40.1 KB)
Please rename the file extension to zip to open it (I can’t upload zip files in the forum).

In the mijia-sensor.py file you need to change the mac address of the thermometer and also adjust mqtt stuff.

Have fun.

1 Like

Thanks alot, i will give it a try, as i am buildig the openhab, i wonder, if i can connect them together… As i am still a newby in this matter…

I seem to do something wrong :smiley:

/mijia-sensor.py: line 1: import: command not found
./mijia-sensor.py: line 2: import: command not found
./mijia-sensor.py: line 3: import: command not found
./mijia-sensor.py: line 4: import: command not found
from: can’t read /var/mail/mijia.mijia_poller
./mijia-sensor.py: line 9: syntax error near unexpected token (' ./mijia-sensor.py: line 9: def update(address):’

I did change the mqtt address and also the sensor MAC, but i seem to lack some other things…

Did you installed the following packages?

Yes i did. i cheked

Well, it seems i am hardly trying to get it work with openhab, but it is for domoticz :slight_smile:
Digging…

Well somekind of success… I am getting a result, and errors, but it is a step forward…:
I added lines…

#!/usr/bin/env python3

import ssl
import sys
import re
import json
import os.path
import argparse

connect error: Transport endpoint is not connected (107)
connect error: Transport endpoint is not connected (107)
connect error: Transport endpoint is not connected (107)
connect error: Function not implemented (38)
Mi Sensor: 4C:65:A8:DB:9F:C9
Firmware: 00.00.66
Name: MJ_HT_V1
Temperature: 19.6°C
Humidity: 59.3%
Battery: 0%
Traceback (most recent call last):
File “./mijia-sensor.py”, line 63, in
update(“4C:65:A8:DB:9F:C9”)
File “./mijia-sensor.py”, line 56, in update
mqttc.connect(“192.168.0.121”, 1883)
File “/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py”, line 838, in connect
self.connect_async(host, port, keepalive, bind_address)
AttributeError: ‘str’ object has no attribute ‘connect_async’

PS. I had to disable the bluetooth addon from openhab. I think i have to do it all through mqtt… Any ideas or critics, is more than welcome

For me this way is running very stable as far as the distance between Xiaomi and my raspi is not to far:


(thanks to Ersin Gencturk at this point)

I kicked out the battery request and this " if [[ “$temp” =~ ^[0-9]+(.[0-9]+)?$ ]]" as it gave me an error.
And I added a counter in the " until [ ${RET} -eq 0 ]; do" to stop this request after 200 tries.

I’m fine with this so far…