So here is a more reliable method:
0: setup your bluetooth dongle, make sure you see BLE devices with "sudo hcitool lescan". Python3, PIP installations are neccessary.
Install bluepy:
https://github.com/IanHarvey/bluepy
Code: Select all
$ sudo apt-get install git build-essential libglib2.0-dev
$ git clone https://github.com/IanHarvey/bluepy.git
$ cd bluepy
$ python3 setup.py build
$ sudo python3 setup.py install
Code: Select all
$ sudo apt-get install python3-pip libglib2.0-dev
$ sudo pip3 install bluepy
Let's move on.
On Ubuntu 16.04 bluez comes with gatttool, which works fine with this script. I red somewhere that gatttool is missing from newer installations, if that's the case, just use bluepy as the backend.
At this moment bluepy is my preferred backend, it seem to be reliable.
1:
Download latest Miflora library release from Github
https://github.com/open-homeautomation/miflora/releases
Code: Select all
madrian@ubuntu:~/scripts$ wget https://github.com/open-homeautomation/miflora/archive/v0.4.zip
madrian@ubuntu:~/scripts$ unzip v0.4.zip
madrian@ubuntu:~/scripts$ cd miflora-0.4/
You can verify working of both backend with:
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ sudo ./demo.py --backend gatttool scan
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ sudo ./demo.py --backend bluepy scan
Scanning for 10 seconds...
Found 3 devices:
C4:7C:8D:62:xx:xx
C4:7C:8D:63:xx:xx
C4:7C:8D:61:xx:xx
Let's try to get some data:
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ sudo ./demo.py --backend gatttool poll C4:7C:8D:61:xx:xx
Getting data from Mi Flora
FW: 3.1.8
Name: Flower care
Temperature: 34.3
Moisture: 38
Light: 68503
Conductivity: 326
Battery: 99
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ sudo ./demo.py --backend bluepy poll C4:7C:8D:61:AA:A8
Getting data from Mi Flora
FW: 3.1.8
Name: Flower care
Temperature: 34.1
Moisture: 38
Light: 72156
Conductivity: 328
Battery: 99
We have a working setup, let's write some script to connect with Domoticz.
Create dummy devices for each sensors. I have these per sensor:
Put these scripts in the folder above miflora-0.4.
domo.sh:
Code: Select all
#!/bin/bash
cd "$(dirname "$0")"
while read -r prefix val; do
case "$prefix" in
FW:) fw=$val ;;
Name:) name=$val ;;
Temperature:) temp=$val ;;
Moisture:) mt=$val ;;
Light:) lt=$val ;;
Conductivity:) ct=$val ;;
Battery:) bt=$val ;;
esac
done < <(sudo ./demo.py --backend bluepy poll $1)
#moisture
curl "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$2&nvalue=0&svalue=$mt&battery=$bt"
#temperature
curl "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$3&nvalue=0&svalue=$temp&battery=$bt"
#light
curl "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$4&svalue=$lt&battery=$bt"
#conductivity
curl "http://localhost:8080/json.htm?type=command¶m=udevice&idx=$5&nvalue=0&svalue=$ct&battery=$bt"
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ ./domo.sh C4:7C:8D:63:7A:11 103 104 105 106
{
"status" : "OK",
"title" : "Update Device"
}
{
"status" : "OK",
"title" : "Update Device"
}
{
"status" : "OK",
"title" : "Update Device"
}
{
"status" : "OK",
"title" : "Update Device"
}
Everything is working fine. I have multiple sensors so I wrote another script:
Code: Select all
madrian@ubuntu:~/scripts/miflora-0.4$ cat run_domo.sh
#!/bin/bash
cd "$(dirname "$0")"
#fc1
/home/madrian/scripts/miflora-0.4/domo.sh C4:7C:8D:63:xx:xx 103 104 105 106
#fc2
/home/madrian/scripts/miflora-0.4/domo.sh C4:7C:8D:62:xx:xx 107 108 109 110
#fc3
/home/madria/scripts/miflora-0.4/domo.sh C4:7C:8D:61:xx:xx 111 112 113 114
Finally make a new crontab to call this script every x minutes.
Code: Select all
*/30 * * * * /home/madrian/scripts/miflora-0.4/run_domo.sh >/dev/null 2>&1