Page 2 of 17

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

Posted: Friday 18 November 2016 10:22
by LouiS22
Stuntteam wrote:Yes..
When it's ready, that will be my prompt switch to RFLink ;)

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

Posted: Friday 18 November 2016 12:52
by jadon
I received my Xiaomi Mi Flora yesterday! I've only had a few minutes to play with it. Connecting with my phone was easy, as you'd expect with a bluetooth LE device. However, I downloaded the Xiaomi Home app and noticed the Flora dashboard is Chinese only :( So I couldn't tell what's what... Anyway, I'll have a look at reading data with that github script this weekend and see if it makes any sense :)

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

Posted: Friday 18 November 2016 12:56
by LouiS22
jadon wrote:I received my Xiaomi Mi Flora yesterday! I've only had a few minutes to play with it. Connecting with my phone was easy, as you'd expect with a bluetooth LE device. However, I downloaded the Xiaomi Home app and noticed the Flora dashboard is Chinese only :( So I couldn't tell what's what... Anyway, I'll have a look at reading data with that github script this weekend and see if it makes any sense :)
Could you please explore the device's range? For example, if you put the sensor into a corner will you phone's able to get the reading from another room, or another floor, etc?

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

Posted: Friday 18 November 2016 19:13
by Itschi
I got mine today. Transmission of the data over a free air distance of 10m worked fine. iOS App is in English and Chinese. Have to wait for the arrival of a HM-11 BLE module to continue with reading the sensors data by an own application...

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

Posted: Saturday 19 November 2016 11:46
by jadon
The range is quite good! I live in an old house (so no concrete walls). I have my Mi Flora in the living room and my raspberry pi 3 in the hallway. I could even connect from my laptop on the 2nd floor.

Anyway, using "sudo hcitool lescan" it lists my device:

Code: Select all

pi@domoticz:~/miflora$ sudo hcitool lescan
LE Scan ...
C4:7C:8D:--:--:-- Flower care
Next, I cloned the repository from https://github.com/open-homeautomation/miflora

I changed the MAC address in demo.py and started the script. After 30 seconds or so, I got the following data:

Code: Select all

pi@domoticz:~/miflora$ python3 demo.py
Getting data from Mi Flora
FW: 2.6.6
Name: Flower care
Temperature: 19.4
Moisture: 9
Light: 201
Conductivity: 0
Battery: 100
So what's next? :)

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

Posted: Saturday 19 November 2016 21:25
by pvm
You can store them in virtual sensors

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

Posted: Sunday 20 November 2016 16:54
by jadon
okay, so I create a dummy hardware device and called it "Flower care"

Image

Then I added three virtual sensors: Temp, Lux and Moisture

Image

I copied the demo.py script to domoticz.py and added some code (Python is not my native programming language, so suggetions are welcome)

Code: Select all

import urllib.request
import base64
from miflora.miflora_poller import MiFloraPoller, \
    MI_CONDUCTIVITY, MI_MOISTURE, MI_LIGHT, MI_TEMPERATURE, MI_BATTERY

# Settings for the domoticz server
domoticzserver   = "localhost:8080"
domoticzusername = "admin"
domoticzpassword = "----"

# Sensor IDs
idx_temp  = "88"
idx_lux   = "89"
idx_moist = "90"

############

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()

poller = MiFloraPoller("C4:7C:8D:61:F7:2A")
#print("Getting data from Mi Flora")
#print("FW: {}".format(poller.firmware_version()))
#print("Name: {}".format(poller.name()))
#print("Temperature: {}".format(poller.parameter_value("temperature")))
#print("Moisture: {}".format(poller.parameter_value(MI_MOISTURE)))
#print("Light: {}".format(poller.parameter_value(MI_LIGHT)))
#print("Conductivity: {}".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 + "&nvalue=" + val_moist + "&battery=" + val_bat)
Using a cronjob I run this script every hour and my sensors get updated :)
I don't know how long the battery is going to last. It looks like it drains 1% every time I do a read out....

Note: I'm using python3

Image

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

Posted: Sunday 20 November 2016 19:02
by deennoo
Great script, can do the job on my side waiting for a better BLE integration on RFLink.

Why don't you use a virtual leaf sensor ? Icon is more revelante.

As this is for a plant care, maybe run script twice a day (at mid day and before sunset) can be more usefull and battery friendly.

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

Posted: Tuesday 29 November 2016 23:14
by pvm
Thnx! Script working great

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

Posted: Tuesday 06 December 2016 12:29
by deennoo
Yeap thx for the script ! works as perfect !

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

Posted: Tuesday 06 December 2016 15:31
by trixwood
i added with a custom sensor...

Code: Select all

idx_cond  = "141"

# Update conductivity
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)

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

Posted: Tuesday 06 December 2016 16:48
by deennoo
trixwood wrote:i added with a custom sensor...

Code: Select all

idx_cond  = "141"

# Update conductivity
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)
Hey hey same here...

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

Posted: Wednesday 07 December 2016 15:49
by pvm
What type of device do you use?

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

Posted: Wednesday 07 December 2016 15:55
by deennoo
Custom sensor

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

Posted: Wednesday 07 December 2016 16:00
by pvm
I understand :) I use custom sensor leaf wetness

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

Posted: Saturday 10 December 2016 9:27
by Deluka
Would it be possible to use more then 1 Mi Flora

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

Posted: Saturday 10 December 2016 10:42
by trixwood
yes! as many as you like.

Does anybody has some info on how long the battery will last?

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

Posted: Saturday 10 December 2016 16:01
by LouiS22
trixwood wrote:yes! as many as you like.

Does anybody has some info on how long the battery will last?
The users manual promises a year, but IMHO it really depends on your using habits: i.e. if you poll the data every minute, it will suck the battery really fast.

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

Posted: Saturday 10 December 2016 16:57
by pvm
After a week of 1 daily request and first day 15 times it is still 100 full

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

Posted: Saturday 10 December 2016 23:54
by lepetitnicolas
Thanks for this script ! It's work perfect.

Now, i need to create a custom sensor (i don't see it.... V3.4834) and a cronjob