Page 12 of 17

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

Posted: Tuesday 18 April 2017 22:04
by jandoedel99
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

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

Posted: Tuesday 18 April 2017 22:09
by pvm
Can you share the error message?

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

Posted: Tuesday 18 April 2017 22:40
by devros
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")



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

Posted: Tuesday 18 April 2017 23:05
by jandoedel99
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

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

Posted: Saturday 22 April 2017 13:56
by micksel
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

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

Posted: Saturday 22 April 2017 15:21
by micksel
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.

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

Posted: Saturday 22 April 2017 16:36
by madrian
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

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

Posted: Sunday 23 April 2017 13:21
by madrian
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?

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

Posted: Monday 24 April 2017 17:49
by micksel
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

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

Posted: Tuesday 25 April 2017 11:01
by micksel
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?

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

Posted: Tuesday 25 April 2017 11:03
by LouiS22
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.

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

Posted: Tuesday 25 April 2017 11:29
by micksel
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.

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

Posted: Thursday 27 April 2017 20:24
by bertbigb
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 :?

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

Posted: Friday 28 April 2017 6:52
by micksel
I got that error message when I still was connected with my Phone. Is that the case for you?

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

Posted: Friday 28 April 2017 7:52
by bertbigb
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

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

Posted: Saturday 29 April 2017 14:56
by LouiS22
Got a firmware upgrade, new version is 2.9.4. I've upgraded, python script is still working (those who wonder).

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

Posted: Monday 08 May 2017 17:31
by ilpier
There is no way for Windows?

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

Posted: Monday 08 May 2017 18:18
by micksel
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

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

Posted: Monday 08 May 2017 20:58
by bertbigb
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.

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

Posted: Monday 08 May 2017 23:57
by pvm
You can also make a slave Domoticz and have Domoticz sent these values over to the other one