Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Others (MiLight, Hue, Toon etc...)
jandoedel99
Posts: 12
Joined: Tuesday 18 April 2017 21:55
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by jandoedel99 » Tuesday 18 April 2017 22:04

On RPI 2 with Wheezy i have a problem in the wiki

Code: Select all

Python-to-bluetooth

Next, Install Python3 and the required Python3 libraries that let Python script talk to Bluetooth. 

sudo aptitude install python3
sudo aptitude install python3-pip
sudo pip3 install pygatt
sudo pip3 install requests

the first 2 lines are going good
the next 2 don´t install
What to do

pvm
Posts: 961
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by pvm » Tuesday 18 April 2017 22:09

Can you share the error message?
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

devros
Posts: 189
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by devros » Tuesday 18 April 2017 22:40

Dunno why, but on my OrangePi myflora works only when i run hcitool lescan before script
so i modifed script that it runs hcitool lescan for few seconds, then all works
(also changed hcitool lescan to run without sudo)
i know that its quite dirty but it works... for me
here is my modifed script

Code: Select all

#!/usr/bin/python3
import urllib.request
import base64
import time
import os
from miflora.miflora_poller import MiFloraPoller, \
    MI_CONDUCTIVITY, MI_MOISTURE, MI_LIGHT, MI_TEMPERATURE, MI_BATTERY

# Settings for the domoticz server

# Forum see: http://domoticz.com/forum/viewtopic.php?f=56&t=13306&hilit=mi+flora&start=20#p105255

domoticzserver   = "XXX"
domoticzusername = "XXX"
domoticzpassword = "XXX"

# So id devices use: sudo hcitool lescan
base64string = base64.encodestring(('%s:%s' % (domoticzusername, domoticzpassword)).encode()).decode().replace('\n', '')

def domoticzrequest (url):
  request = urllib.request.Request(url)
  request.add_header("Authorization", "Basic %s" % base64string)
  response = urllib.request.urlopen(request)
  return response.read()

def update(address,idx_moist,idx_temp,idx_lux,idx_cond):

    poller = MiFloraPoller(address)
    loop = 0
    try:
        temp = poller.parameter_value("temperature")
    except:
        temp = 201

    while loop < 2 and temp > 200:
        print("Patched: Error reading value retry after 5 seconds...\n")
        time.sleep(5)
        poller = MiFloraPoller(address)
        loop += 1
        try:
            temp = poller.parameter_value("temperature")
        except:
            temp = 201

    if temp > 200:
        print("Patched: Error reading value\n")
        return

    global domoticzserver

    print("Mi Flora: " + address)
    print("Firmware: {}".format(poller.firmware_version()))
    print("Name: {}".format(poller.name()))
    print("Temperature: {}°C".format(poller.parameter_value("temperature")))
    print("Moisture: {}%".format(poller.parameter_value(MI_MOISTURE)))
    print("Light: {} lux".format(poller.parameter_value(MI_LIGHT)))
    print("Fertility: {} uS/cm?".format(poller.parameter_value(MI_CONDUCTIVITY)))
    print("Battery: {}%".format(poller.parameter_value(MI_BATTERY)))

    val_bat  = "{}".format(poller.parameter_value(MI_BATTERY))

    # Update temp
    val_temp = "{}".format(poller.parameter_value("temperature"))
    domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_temp + "&nvalue=0&svalue=" + val_temp + "&battery=" + val_bat)

    # Update lux
    val_lux = "{}".format(poller.parameter_value(MI_LIGHT))
    domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_lux + "&svalue=" + val_lux + "&battery=" + val_bat)

    # Update moisture
    val_moist = "{}".format(poller.parameter_value(MI_MOISTURE))
    domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_moist + "&svalue=" + val_moist + "&battery=" + val_bat)

    # Update fertility
    val_cond = "{}".format(poller.parameter_value(MI_CONDUCTIVITY))
    domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_cond + "&svalue=" + val_cond + "&battery=" + val_bat)
    time.sleep(1)

# format address, moist (%), temp (°C), lux, fertility
os.system("timeout 2 hcitool lescan 5")
print ("predping")
update("C4:7C:8D:61:B4:DA","142","133","136","143")



jandoedel99
Posts: 12
Joined: Tuesday 18 April 2017 21:55
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by jandoedel99 » Tuesday 18 April 2017 23:05

jandoedel99 wrote:On RPI 2 with Wheezy i have a problem in the wiki

Code: Select all

Python-to-bluetooth

Next, Install Python3 and the required Python3 libraries that let Python script talk to Bluetooth. 

sudo aptitude install python3
sudo aptitude install python3-pip
sudo pip3 install pygatt
sudo pip3 install requests

the first 2 lines are going good
the next 2 don´t install
What to do

Code: Select all

error is
pi@raspberrypi ~ $ sudo pip3 install pygatt
/usr/local/bin/python3.5: error while loading shared libraries: libpython3.5m.so                                    .1.0: cannot open shared object file: No such file or directory

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Saturday 22 April 2017 13:56

Seems that on my Pi2 with the Domoticz image, the command isn't pip3 but pip-3.2

So close now but But I still recieve Error:

pi@domo1 ~/domoticz/scripts/python/miflora $ /usr/bin/python3 /home/pi/domoticz/scripts/python/miflora/domoticz.py
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/python/miflora/domoticz.py", line 4, in <module>
from miflora.miflora_poller import MiFloraPoller, \
File "/home/pi/domoticz/scripts/python/miflora/miflora/miflora_poller.py", line 12, in <module>
from subprocess import PIPE, Popen, TimeoutExpired
ImportError: cannot import name TimeoutExpired

And Sudo pip-3.2 install timeoutexpired won't solve anything :(
pi@domo1 ~/domoticz/scripts/python/miflora $ sudo pip-3.2 install TimeoutExpired
Downloading/unpacking TimeoutExpired
Could not find any downloads that satisfy the requirement TimeoutExpired
No distributions at all found for TimeoutExpired
Storing complete log in /root/.pip/pip.log

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Saturday 22 April 2017 15:21

I downloaded the new and updated miflora_poller.py from https://github.com/open-homeautomation/ ... ant-sensor but still recive the same error
I found my ID using : sudo hcitool lescan)
C4:7C:8D:62:0C:81 Flower care

I edit demo.py with this but when I run it I get the following errors:
pi@domo1 ~ $ sudo /usr/bin/python3 /home/pi/domoticz/scripts/python/miflora/demo.py
pi@domo1 ~/domoticz/scripts/python/miflora/miflora/tests $ /usr/bin/python3 /home/pi/domoticz/scripts/python/miflora/demo.py
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/python/miflora/demo.py", line 1, in <module>
from miflora.miflora_poller import MiFloraPoller, \
File "/home/pi/domoticz/scripts/python/miflora/miflora/miflora_poller.py", line 12, in <module>
from subprocess import PIPE, Popen, TimeoutExpired
ImportError: cannot import name TimeoutExpired


I can connect with gatttool -I and Connect
pi@domo1 ~/domoticz/scripts/python $ gatttool -I
[ ][LE]> connect c4:7c:8d:62:0c:81
Attempting to connect to c4:7c:8d:62:0c:81
Connection successful
Notification handle = 0x0021 value: 00
Notification handle = 0x0021 value: 00
Notification handle = 0x0021 value: 00
[c4:7c:8d:62:0c:81][LE]>
(gatttool:9429): GLib-WARNING **: Invalid file descriptor.
Last edited by micksel on Saturday 22 April 2017 21:00, edited 1 time in total.

madrian
Posts: 240
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by madrian » Saturday 22 April 2017 16:36

Coldman wrote:

Code: Select all

[bluetooth]# scan on
Discovery started
[CHG] Controller 34:C3:D2:E4:13:E3 Discovering: yes
[/quote]

How can I connect to the sensor and watch RSSI with scan on? 

Thank you

madrian
Posts: 240
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by madrian » Sunday 23 April 2017 13:21

I am triying:

Code: Select all

@orangepizero:~/bluetoothctl
[bluetooth]# scan on
Discovery started
...
[CHG] Controller 00:1A:7D:DA:71:13 Discovering: yes
[CHG] Device C4:7C:8D:62:6E:22 RSSI: -59
[CHG] Device C4:7C:8D:62:6E:22 ServiceData Value: 0x02
[CHG] Device C4:7C:8D:62:6E:22 ServiceData Value: 0x98
[CHG] Device C4:7C:8D:62:6E:22 ServiceData Value: 0x00
[CHG] Device C4:7C:8D:62:6E:22 ServiceData Value: 0x41
...
.
...
And I see many Servicedata Value lines....how I can filter out only RSSI?

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Monday 24 April 2017 17:49

micksel wrote: from miflora.miflora_poller import MiFloraPoller, \
File "/home/pi/domoticz/scripts/python/miflora/miflora/miflora_poller.py", line 12, in <module>
from subprocess import PIPE, Popen, TimeoutExpired
ImportError: cannot import name TimeoutExpired
I solved this by manually update to python 3.4

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Tuesday 25 April 2017 11:01

I can see in the python script that the battery parameter is also sent when updating the values.

Like: domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_temp + "&nvalue=0&svalue=" + val_temp + "&battery=" + val_bat)

How can I see this value in domotics?

User avatar
LouiS22
Posts: 497
Joined: Friday 27 February 2015 14:21
Target OS: Raspberry Pi
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by LouiS22 » Tuesday 25 April 2017 11:03

micksel wrote:I can see in the python script that the battery parameter is also sent when updating the values.

Like: domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_temp + "&nvalue=0&svalue=" + val_temp + "&battery=" + val_bat)

How can I see this value in domotics?
Right under the Devices tab ;) Check the little green battery icon, and in that row.

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Tuesday 25 April 2017 11:29

LouiS22 wrote:
micksel wrote:I can see in the python script that the battery parameter is also sent when updating the values.

Like: domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_temp + "&nvalue=0&svalue=" + val_temp + "&battery=" + val_bat)

How can I see this value in domotics?
Right under the Devices tab ;) Check the little green battery icon, and in that row.
Feeling like an idiot, thanks.

bertbigb
Posts: 137
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by bertbigb » Thursday 27 April 2017 20:24

Dear All,

I bought a MiFlora Plant pin and followed the wiki.

I run domoticz on a raspberry 3

I discovered my device with the command

Code: Select all

sudo hcitool lescan
it showed C4:7C:8D:63:62:1E Flower care

I used the domoticz.py from the wiki
I updated this value in domoticz.py and when I now run

Code: Select all

pi@raspberrypi_V3:~ $ /usr/bin/python3 /home/pi/dev-domoticz/scripts/python/miflora/domoticz.py
I get the following response:

1: Varen (weet ik niet)
connect: Device or resource busy (16) (many times)

Anyone any idea why this is happening? I tried already for a couple of hours but no other results. Do I need to change something else?
It is a bit a pity that I can't read the values of the flower pin into domoticz :?
Best regards Bert

Synology DS1515+ - DSM 6.1
Raspberry PI2 - B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Friday 28 April 2017 6:52

I got that error message when I still was connected with my Phone. Is that the case for you?

bertbigb
Posts: 137
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by bertbigb » Friday 28 April 2017 7:52

micksel wrote:I got that error message when I still was connected with my Phone. Is that the case for you?
That was exactly the case, now it is working fine. Thanks for your reaction
Best regards Bert

Synology DS1515+ - DSM 6.1
Raspberry PI2 - B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon

User avatar
LouiS22
Posts: 497
Joined: Friday 27 February 2015 14:21
Target OS: Raspberry Pi
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by LouiS22 » Saturday 29 April 2017 14:56

Got a firmware upgrade, new version is 2.9.4. I've upgraded, python script is still working (those who wonder).

ilpier
Posts: 38
Joined: Friday 24 February 2017 13:01
Target OS: Windows
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by ilpier » Monday 08 May 2017 17:31

There is no way for Windows?

micksel
Posts: 93
Joined: Wednesday 28 January 2015 18:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by micksel » Monday 08 May 2017 18:18

ilpier wrote:There is no way for Windows?

python exit for windows but not sure about all the moduls, maybe easier just to emulate a Linux system on win

bertbigb
Posts: 137
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by bertbigb » Monday 08 May 2017 20:58

Hi,

I have a raspberry PI 3 with bluetooth, MQTT and Domoticz installed.
I can read through the lua script all my plant pins. So far so good.
What I would like is to send the values from the plantpins over MQTT to another domoticz system running on Synology.
From the PI, i tested and i can send messages to the other domoticz system on Synology
Can anyone help me to point out how to do or what to change in the script to make this possible?

Thanks for your help.
Best regards Bert

Synology DS1515+ - DSM 6.1
Raspberry PI2 - B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon

pvm
Posts: 961
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Re: Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor

Post by pvm » Monday 08 May 2017 23:57

You can also make a slave Domoticz and have Domoticz sent these values over to the other one
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests