Xiaomi BLE temperature & humidity sensor

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
freibeuter
Posts: 6
Joined: Saturday 27 January 2018 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Xiaomi BLE temperature & humidity sensor

Post by freibeuter »

Hi guys!

Just started using Domoticz and trying to make my home a bit smarter 8-)
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
Attachments
sensors temperature section
sensors temperature section
sensors.png (52.07 KiB) Viewed 12127 times
freibeuter
Posts: 6
Joined: Saturday 27 January 2018 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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
Slokoavac
Posts: 14
Joined: Monday 20 November 2017 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Balkans
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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!
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Chakkie
Posts: 33
Joined: Wednesday 23 December 2015 11:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post by Chakkie »

freibeuter wrote: Sunday 28 January 2018 10:20 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
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
Hesmink
Posts: 168
Joined: Monday 22 June 2015 10:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: The Netherlands
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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!
freibeuter
Posts: 6
Joined: Saturday 27 January 2018 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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.
glory50
Posts: 38
Joined: Thursday 07 June 2018 22:23
Target OS: Linux
Domoticz version: 2022.1
Location: Sud de France
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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!
riob
Posts: 8
Joined: Thursday 06 February 2014 21:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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
wkossen
Posts: 62
Joined: Friday 06 November 2020 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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.
stepanyanmirkhavoyan
Posts: 1
Joined: Tuesday 09 March 2021 8:53
Target OS: OS X
Domoticz version:
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post by stepanyanmirkhavoyan »

its 2018 post still looks good enough
Dave21w
Posts: 361
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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"
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Dave21w
Posts: 361
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post by Dave21w »

Only just got back to looking at this, I still have this error:-
requests error.jpg
requests error.jpg (53.51 KiB) Viewed 1939 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 ?
Dave21w
Posts: 361
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post by Dave21w »

Still can't get this to work despite installing what believe are all rerquirements

Anybody else have any success ?
User avatar
waltervl
Posts: 5149
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Xiaomi BLE temperature & humidity sensor

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests