Xiaomi Mi Plants Monitor Flower

I’ve never had this problem. Check with the iPhone/Android app what is displayed there.

Mhh. It’s not working for me. When I try to read the data I get:
[email protected]:~ $ gatttool --device=C4:7C:8D:60:BC:F6 --char-read -a 0x35 Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Any ideas? Did they change the handle?

[quote=“mxtra, post:22, topic:3388, full:true”]
Mhh. It’s not working for me. When I try to read the data I get: [email protected]:~ $ gatttool --device=C4:7C:8D:60:BC:F6 --char-read -a 0x35Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[/quote]
I have exactly the same problem, I think this happend after the Xiaomi-app updated the sensor firmware from 2.62 and 2.64 to 2.66 :frowning:

The Xiaomi-app still works an gets all sensor values!

I didn’t found any other handle, that might correspondent the needed values, but I didn’t checked all possible handlers.

So any idea how to get this running again?

BTW: During my investigations I found out where to get sensor firmware version and battery level:

Handle 0x38 gives me on three different sensors:
64 13 32 2e 36 2e 36
57 13 32 2e 36 2e 36
4f 13 32 2e 36 2e 36

If I look in the app, I can see, that the first byte is the battery-level, I get 100%, 87% and 79%.

I think this handle also returns the firmware version in the last 5 bytes as plain ASCII: “2.6.6”. In an other example it has “32 2e 36 2e 32” what would be “2.6.2” the initial firmware version!

Kind regards,

thgha

During the last days I logged every 10 min some other handles and wrote the results into a logfile. I have done this for three different sensors.

First all the “easy” ones, they do not change at all and are the same on all three sensors, while 0x03 is the name “Flower care” in ASCII:

0x02: Characteristic value/descriptor: 02 03 00 00 2a 
0x03: Characteristic value/descriptor: 46 6c 6f 77 65 72 20 63 61 72 65 
0x04: Characteristic value/descriptor: 02 05 00 01 2a 
0x05: Characteristic value/descriptor: 00 00 
0x06: Characteristic value/descriptor: 0a 07 00 02 2a 
0x07: Characteristic value/descriptor: 00 
0x08: Characteristic value/descriptor: 02 09 00 04 2a 
0x09: Characteristic value/descriptor: 0a 00 14 00 00 00 f4 01 
0x0e: Characteristic value/descriptor: 01 00 ff ff
0x15: Characteristic value/descriptor: 98 00 
0x1d: Characteristic value/descriptor: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 
0x2f: Characteristic value/descriptor: 00 
0x31: Characteristic value/descriptor: fb 34 9b 5f 80 00 00 80 00 10 00 00 04 12 00 00
0x32: Characteristic value/descriptor: 0a 33 00 fb 34 9b 5f 80 00 00 80 00 10 00 00 00 1a 00 00
0x33: Characteristic value/descriptor: 00 00
0x34: Characteristic value/descriptor: 1a 35 00 fb 34 9b 5f 80 00 00 80 00 10 00 00 01 1a 00 00
0x37: Characteristic value/descriptor: 02 38 00 fb 34 9b 5f 80 00 00 80 00 10 00 00 02 1a 00 00
0x3c: Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x3e: Characteristic value/descriptor: 00 00 00

Then there are two handles that stay the same, but are different on every sensor, I didn’t checked it, but probably s.th. like MAC, serial etc:

0x17: Characteristic value/descriptor: 18 f6 45 03 a2 13 97 bb a1 2c
      Characteristic value/descriptor: d6 85 2f 13 06 19 c6 c1 cb 3a
      Characteristic value/descriptor: 06 5d 64 8f b7 7b 85 79 42 d7 
0x1f: Characteristic value/descriptor: 29 d9 77 2e 97 49 a3 8a 9f 25 56 13
      Characteristic value/descriptor: e7 aa 1d 3e 33 43 f2 f0 f5 33 ff 49
      Characteristic value/descriptor: 37 72 56 a2 82 21 b1 48 7c de 09 68 

Then we have our values, 0x35 is empty in my case, 0x38 has battery-level and firmware version:

0x35: Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x38: Characteristic value/descriptor: 52 13 32 2e 36 2e 36

By now, I do not think that they changed the handler for the above values, but may be you have so send a command or what ever, to get them.

Normaly, handle 0x35 should have values like the following:

Characteristic value/descriptor: d0 00 00 01 02 00 00 2f 6b 01 00 00 00 00 00 00
Characteristic value/descriptor: c9 00 00 23 01 00 00 19 42 01 00 00 00 00 00 00
Characteristic value/descriptor: cf 00 00 0d 00 00 00 1c f2 01 00 00 00 00 00 00
Characteristic value/descriptor: cb 00 00 00 00 00 00 1c 3c 02 00 00 00 00 00 00
Characteristic value/descriptor: e7 00 00 00 00 00 00 2a 00 02 00 00 00 00 00 00
Characteristic value/descriptor: ec 00 00 34 00 00 00 02 00 00 00 00 00 00 00 00
Characteristic value/descriptor: cb 00 00 00 00 00 00 1c 3c 02 00 00 00 00 00 00
Characteristic value/descriptor: cb 00 00 00 00 00 00 1c 3c 02 00 00 00 00 00 00
Characteristic value/descriptor: ec 00 00 34 00 00 00 02 00 00 00 00 00 00 00 00
Characteristic value/descriptor: cb 00 00 00 00 00 00 1c 37 02 00 00 00 00 00 00
Characteristic value/descriptor: cb 00 00 00 00 00 00 1c 3c 02 00 00 00 00 00 00

Next one is the handler 0x41, I’m quite sure, that this is a counter or s.th. similar, because it constantly increases it’s value (three or four bytes, MSB is on the right:

0x41:
14.10.2016,01:20:51 Characteristic value/descriptor: ab 0b 21 00
...
16.10.2016,22:30:01 Characteristic value/descriptor: 50 d1 24 00
0x41:
14.10.2016,01:20:51 Characteristic value/descriptor: 5c fa 03 00
...
16.10.2016,22:30:01 Characteristic value/descriptor: 31 c2 07 00
0x41:
14.10.2016,01:20:51 Characteristic value/descriptor: 3e f5 03 00
...
16.10.2016,22:30:01 Characteristic value/descriptor: 4c c0 07 00

OK and finally the is handler 0x12, no idea what this one is doing, it keeps it value for some hours, then changes, the value on all three sensors is different, only once for round about 12 hours, all three sensors had the same value: “ff ff ff ff”.

0x12:
14.10.2016,01:20:51 Characteristic value/descriptor: fa 1d 15 fb
...
14.10.2016,12:37:01 Characteristic value/descriptor: fa 1d 15 fb 
14.10.2016,12:47:01 connect error: Transport endpoint is not connected (107)
14.10.2016,12:57:01 Characteristic value/descriptor: 64 cb 3b 94 
...
15.10.2016,14:57:01 Characteristic value/descriptor: 64 cb 3b 94 
15.10.2016,15:07:01 Characteristic value/descriptor: 0f 49 7a f9
...
15.10.2016,22:07:01 Characteristic value/descriptor: 0f 49 7a f9 
15.10.2016,22:17:01 connect error: Transport endpoint is not connected (107)
15.10.2016,22:27:02 connect error: Transport endpoint is not connected (107)
15.10.2016,22:37:01 connect error: Transport endpoint is not connected (107)
15.10.2016,22:47:01 Characteristic value/descriptor: ff ff ff ff
...
16.10.2016,11:37:01 Characteristic value/descriptor: ff ff ff ff 
16.10.2016,11:47:01 Characteristic value/descriptor: 6b ea 4f 76 
16.10.2016,11:57:01 connect error: Transport endpoint is not connected (107)
16.10.2016,12:07:01 connect error: Transport endpoint is not connected (107)
16.10.2016,12:17:01 Characteristic value/descriptor: a2 20 c7 ef
...
16.10.2016,21:30:01 Characteristic value/descriptor: a2 20 c7 ef 
0x12: --------------------------------------
14.10.2016,01:20:51 Characteristic value/descriptor: 91 e5 20 c8
...
14.10.2016,12:47:01 Characteristic value/descriptor: 91 e5 20 c8 
14.10.2016,12:57:01 Characteristic value/descriptor: e5 30 75 59 
...
15.10.2016,14:57:01 Characteristic value/descriptor: e5 30 75 59 
15.10.2016,15:07:01 Characteristic value/descriptor: ab c5 59 60
...
15.10.2016,22:07:01 Characteristic value/descriptor: ab c5 59 60 
15.10.2016,22:17:01 Characteristic value/descriptor: ff ff ff ff
...
connect error: Transport endpoint is not connected (107)
16.10.2016,11:37:01 Characteristic value/descriptor: ff ff ff ff 
16.10.2016,11:47:01 Characteristic value/descriptor: b0 79 22 2a
...
16.10.2016,20:30:01 Characteristic value/descriptor: b0 79 22 2a
0x12: --------------------------------------
14.10.2016,01:20:51 Characteristic value/descriptor: fe a9 a1 08 
...
14.10.2016,12:47:01 Characteristic value/descriptor: fe a9 a1 08 
14.10.2016,12:57:01 Characteristic value/descriptor: 1e 78 b4 4e 
...
15.10.2016,14:57:01 Characteristic value/descriptor: 1e 78 b4 4e 
15.10.2016,15:07:01 Characteristic value/descriptor: fa e7 7f 45 
...
15.10.2016,22:17:01 Characteristic value/descriptor: fa e7 7f 45 
15.10.2016,22:27:02 Characteristic value/descriptor: ff ff ff ff 
...
16.10.2016,11:07:01 Characteristic value/descriptor: ff ff ff ff 
16.10.2016,11:17:01 connect error: Transport endpoint is not connected (107)
16.10.2016,11:27:02 connect error: Transport endpoint is not connected (107)
16.10.2016,11:37:01 connect error: Transport endpoint is not connected (107)
16.10.2016,11:47:01 Characteristic value/descriptor: b9 48 39 bd 
...
16.10.2016,20:30:01 Characteristic value/descriptor: b9 48 39 bd

Hi all,

so some more I checked:

Getting the handle 0x35 with the gatttool still works in my environment if I use a sensor that still is on firmware 2.6.2!

I sniffed the BT-traffic and saved it to a file, to look at it with Wireshark, unfortunately I’m far away of being en expert here.
But what I have seen was, that handle 0x38 still works with a simple “char-read”, while 0x35 works with a “notification”:

37	1.868963	localhost ()	HhccPlan_95:6a ()	ATT	12	Sent Read Request, Handle: 0x0038 (Unknown)
...
39	2.111094	HhccPlan_95:6a ()	localhost ()	ATT	17	Rcvd Read Response, Handle: 0x0038 (Unknown)
-> 63:13:32:2e:36:2e:36
...
43	2.359261	HhccPlan_95:6a ()	localhost ()	ATT	28	Rcvd Handle Value Notification, Handle: 0x0035 (Unknown)
-> 60:95:6a:27:38:b6:10:e0:d5:e5:db:fb:4d:03:b3:da
...
50	2.854152	HhccPlan_95:6a ()	localhost ()	ATT	28	Rcvd Handle Value Notification, Handle: 0x0035 (Unknown)
-> c0:00:00:4a:00:00:00:1c:a8:00:02:3c:00:fb:34:9b

Unfortunately I have no idea, how to initiate this notification :frowning:

Anybody with an idea outside there? Anybody who has some experience with reading a BT-dump?

If needed, I can provide the dumps here, they are less than 4KB in size.

Thanks a lot,

kind regards thgha

Some dude found everything out by himself:
https://wiki.hackerspace.pl/projects:xiaomi-flora

Even posted some python code

1 Like

Hi koen01,

thank you very much for this!

This is exactly what I was looking for!

Kind regards,

thgha

I have a problem with the 2.6.2 sensors om my Pi3.
I try to send the 0xA01F code to 0x0033:
gatttool --device=C4:7C:8D:61:BB:6B --char-write --handle=0x0033 --value=0xA01F
and then
gatttool --device=C4:7C:8D:61:BB:6B --char-read -a 0x0035
Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Still got only zeros.
Anyone better than me on gatttool that could help me with this?

Has anyone managed to use that code? I am also using a rpi3 and when I run that python script the it is missing gattlib. I tried installing gattlib which needed two other libraries, but pip still fails with some error message I cannot figure out.

Gattool is not installed by default. Did you run
sudo cp attrib/gatttool /usr/local/bin/
?

Sorry, it was my bad. I missed the dependencies of gattlib. After installing the dependencies, I could install gattlib using pip.

The code is working just fine with my Mi Flora running on firmware 2.6.6.

seems, that I have the same issue. Any hints which deps you installed to get it running?

PS: I was hoping to get it work also via command line:

# gatttool -b C4:7C:8D:60:12:34 --char-read -a 0x0038; sleep 1; gatttool -b C4:7C:8D:60:12:34 --char-write -a 0x0033 -n 0xA01F; sleep 1; gatttool -b C4:7C:8D:60:12:34 --char-read -a 0x0035;
Characteristic value/descriptor: 5b 13 32 2e 36 2e 36 
Characteristic value/descriptor: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

But as you see, I still get only 0, so probably I have to go the Python-way.

Thanks a lot,

Kind regards,

thgha

I am not sure if it works from the command line. I am not an expert, but in the code python code you connect to the device and send/receive commands. But with the command line, those are separate connections. So it may not work the same way.

Anyway, check this out:
https://bitbucket.org/OscarAcena/pygattlib/src/ebcc53523ae8d3b9047eeba8e6899ea448dffc73/DEPENDS?at=default&fileviewer=file-view-default
I installed all these using sudo apt-get install and after that I could pip install gattlib.

I changed the python code, so it takes the device ID from the first argument and a filename from the second argument. The result is written onto the screen, but it is also saved in a text file in JSON format. I read and parse that in OpenHAB and it picks up the sensor values without any issues.

Can somebody help me to run the python-script.
I get following error message:

sudo /usr/bin/python flower.py C4:7C:8D:61:9C:C8
Traceback (most recent call last):
File “flower.py”, line 6, in
from miflora.miflora_poller import MiFloraPoller,
File “/usr/local/lib/python2.7/dist-packages/miflora/miflora_poller.py”, line 12, in
from subprocess import PIPE, Popen, TimeoutExpired
ImportError: cannot import name TimeoutExpired

The fix for the 2.6.6 firmware has now been integrated into the MiFlora library:

Can somebody test this? If everything is working fine, I will create an update for the Home Assistant module.

1 Like

It’s working for me.

[email protected]:~/miflora $ python3 demo.py 
Getting data from Mi Flora
FW: 2.6.6
Name: Flower care
Temperature: 21.8
Moisture: 56
Light: 73
Conductivity: 2822
Battery: 100
[email protected]:~/miflora $

Use python3 instead.

sudo python3 flower.py C4:7C:8D:61:9C:C8

Regards, S

Hi,

Python code is working well for me.

My main purpose is to integrate with home assistant as per your instruction “https://www.open-homeautomation.com/2016/08/29/monitor-your-plants-with-home-assistant/” so does it mean if I upgrade using “sudo pip install --upgrade miflora”, the home assistant: miflora component would work well again? Or anything else that I need to do?

Thanks for your help & great work.

[email protected]:~/miflora $ python3 demo.py
Getting data from Mi Flora
FW: 2.6.6
Name: Flower care
Temperature: 27.9
Moisture: 75
Light: 40
Conductivity: 1953
Battery: 100
[email protected]:~/miflora $

I will update the MiFlora module in Home Assisant. So it should be included in the next Home Assistant upgrade.
An easy fix for now is to locate the miflora.py file on your system and edit the “REQUIREMENTS” line. Change the version there to 0.1.11 (should be 0.1.9 now).

The new version have been merged. It will be available with the next HA update.