Page 1 of 1
Xiaomi BLE temperature & humidity sensor
Posted: Saturday 27 January 2018 17:09
by freibeuter
Hi guys!
Just started using Domoticz and trying to make my home a bit smarter
That´s why a bought a couple of Xiaomi´s new cheap temperature and humidity sensors that transfer data via BLE (see
http://cleargrass.com/). As a newbie it took me about half a day setting up a python script reading temperature, humidity and battery values from sensor and pass it to Domoticz via JSON URL (if someone else needs it, how can I make it public?). So far so good. I set up a dummy hardware in Domoticz and added my sensors as devices of type "Temp + Humidity". In the devices view I can see data is populated correctly, diagramms are showing history - great!
However when I switch to the temperature section in domoticz, I only see the sensors, but no data directly on those widgets (see attached image).
Am I doing something wrong?
Also I marked them as favorites as you can see when looking at the stars but I can´t see them in the dashboard overview
Thanks for helping!!
BR,
Alex
Re: Xiaomi BLE temperature & humidity sensor
Posted: Sunday 28 January 2018 10:20
by freibeuter
Decided to publish code on GitHub:
https://github.com/fr31b3u73r/miThermoHygro
Feel free to test and give me feedback!
Update: Issue is fixed in newest version of script (missed stripping out non Ascii value from received package) - thanks to @PaulFen for pointing it out here:
viewtopic.php?f=56&t=20925
Re: Xiaomi BLE temperature & humidity sensor
Posted: Wednesday 07 February 2018 15:54
by Slokoavac
Cool man! Tnx for script! I am still waiting for it's price to come down and buy one or 2 of em. Still more affordable to use Xiaomi zigbee thermo/hydro meters (8-9$ each) and easier to use with zigbee GW (tho which is 26$) straight to domoticz oob. But that BLE one looks cool too
can you pair it with mi home app and BLE on Raspi at same time? Does it allows multiple pairings?
cheers!
Re: Xiaomi BLE temperature & humidity sensor
Posted: Sunday 11 March 2018 11:06
by Chakkie
Hi freibeuter
Your script works perfectly but unfortunately I am only able to get the data from the device when the device is in paring mode. So basically I need to press and hold the paring button at the back of the device everytime otherwise I won't get the data readout. Do you know what's the issue here.
My raspberry Pi is still on Wheezy and may be that's the problem
thanks
Re: Xiaomi BLE temperature & humidity sensor
Posted: Sunday 08 July 2018 14:59
by Hesmink
Hi,
Got your script to work.
The range of BT is surprisingly far, so I'm able to use these sensors anywhere.
Sensors now are pretty cheap (< 9€ at Joybuy).
Where does the battery information go within Domoticz?
Also my experience getting it to work:
- Took me a while to discover I needed Python 2. Why not add "#!/usr/bin/env python2" at the top of the script?
- I needed to install requests and bluepy, bluepy would only install after installing libglib2.0-dev.
After that it immediately worked!
I would also suggest to name the script like 'miThermoHygro.py' so we can store it in ~/Domoticz/scripts/python.
Thanks!
Re: Xiaomi BLE temperature & humidity sensor
Posted: Monday 09 July 2018 9:34
by freibeuter
Hesmink wrote: ↑Sunday 08 July 2018 14:59
- Took me a while to discover I needed Python 2. Why not add "#!/usr/bin/env python2" at the top of the script?
Thanks - added the shebang
Hesmink wrote: ↑Sunday 08 July 2018 14:59
I would also suggest to name the script like 'miThermoHygro.py' so we can store it in ~/Domoticz/scripts/python.
Done
Hesmink wrote: ↑Sunday 08 July 2018 14:59
Where does the battery information go within Domoticz?
It's an additional param for the Domoticz API (see
https://www.domoticz.com/wiki/Domoticz_ ... y_level.29) - I am not that familiar with Domoticz yet, but you can see it e.g. in the App by pressing long on the device.
Re: Xiaomi BLE temperature & humidity sensor
Posted: Wednesday 08 July 2020 0:38
by glory50
Hi freubeuter!
I have several temp/hum sensors (old round LCD MJ_HT_V1, new angular LYWSD03MMC, zigbee without display) and a couple of those e-ink GlearGrass devices you have written a script. Those who commented here said that the script worked pretty easily but I have a problem.
My Domoticz runs on an Intel NUC DE3815TYKH with Mint 19. I had to install bluepy, requests, setuptools etc for Python2, no problems with them. But the script doesn't simply run at all. After running it, it hangs and stays like this forever. I tried to step through it with pdb and the line it stops is handle_temp_hum_value(), I don't know is this any worth of info or not, I am not a coder, though.
Can you assist me a little with your script? How could I see what it does on a certain moment, how could I debug it or print on console some results (URL, etc) to see what's wrong?
Thanks in advance!
Re: Xiaomi BLE temperature & humidity sensor
Posted: Tuesday 28 July 2020 22:56
by riob
Hi
I have problem with this script, see copy from log below.
2020-07-28 22:53:00.131 Error: EventSystem: Failed to execute python event script "BLE"
2020-07-28 22:53:00.131 Error: EventSystem: Traceback (most recent call last):
2020-07-28 22:53:00.131 Error: EventSystem: File "<string>", line 4, in <module>
2020-07-28 22:53:00.131 Error: EventSystem: ModuleNotFoundError: No module named 'requests'
any thaughts?
Domoticz running on RPI3
Regards Rickard
Re: Xiaomi BLE temperature & humidity sensor
Posted: Friday 05 February 2021 15:31
by wkossen
glory50 wrote: ↑Wednesday 08 July 2020 0:38
After running it, it hangs and stays like this forever.
I have this exact same problem. script hangs.
Re: Xiaomi BLE temperature & humidity sensor
Posted: Tuesday 09 March 2021 8:59
by stepanyanmirkhavoyan
its 2018 post still looks good enough
Re: Xiaomi BLE temperature & humidity sensor
Posted: Friday 23 July 2021 11:11
by Dave21w
Just tried to install this and getting the same error
2021-07-23 10:08:27.970 Error: EventSystem: Failed to execute python event script "BLE Sensor Reading"
2021-07-23 10:08:27.971 Error: EventSystem: Traceback (most recent call last):
2021-07-23 10:08:27.971 Error: EventSystem: File "<string>", line 4, in <module>
2021-07-23 10:08:27.971 Error: EventSystem: ModuleNotFoundError: No module named 'requests'
Did anyone get this issue resolved, checked to make sure requests is present and it is, the version I have is 2.21.00 is this a newer version and so causing an issue ?
Any help would be appreciated as I know little to nothing about python
TIA
Dave
Re: Xiaomi BLE temperature & humidity sensor
Posted: Friday 23 July 2021 12:05
by waltervl
Dave21w wrote: ↑Friday 23 July 2021 11:11
Just tried to install this and getting the same error
2021-07-23 10:08:27.970 Error: EventSystem: Failed to execute python event script "BLE Sensor Reading"
2021-07-23 10:08:27.971 Error: EventSystem: Traceback (most recent call last):
2021-07-23 10:08:27.971 Error: EventSystem: File "<string>", line 4, in <module>
2021-07-23 10:08:27.971 Error: EventSystem: ModuleNotFoundError: No module named 'requests'
Did anyone get this issue resolved, checked to make sure requests is present and it is, the version I have is 2.21.00 is this a newer version and so causing an issue ?
Any help would be appreciated as I know little to nothing about python
TIA
Dave
In the github it says
To be able to use it your device needs a bluetooth hardware that supports BLE, Python (2) as well as external libraries as defined in imports. Tested on Raspberry Pi 3.
So You need to install (or confirm that it is installed) the Python libraries:
binascii
base64
requests
Normally you install these with:
sudo pip3 "python module name"
Re: Xiaomi BLE temperature & humidity sensor
Posted: Monday 22 November 2021 9:26
by Dave21w
Only just got back to looking at this, I still have this error:-

- requests error.jpg (53.51 KiB) Viewed 2173 times
However when I try to install the "requests" module I am told the requirement is already satisfied for both python2 and 3.
Any ideas guys ?
Re: Xiaomi BLE temperature & humidity sensor
Posted: Thursday 10 February 2022 12:02
by Dave21w
Still can't get this to work despite installing what believe are all rerquirements
Anybody else have any success ?
Re: Xiaomi BLE temperature & humidity sensor
Posted: Thursday 10 February 2022 15:31
by waltervl
libraries have to be installed with the same user as the user running Domoticz else it cannot find it.
So if root is running Domoticz use 'sudo pip3' to install the libraries. else install with normal pip3