Xiaomi smart scale 2 binding

Did anybody intergrate this guy into thire openhab?
image
I saw some python scrips that might be able to do the trick.

please note there is a mi scale and a mi scale 2. Number 2 offeres much more data e.g. fat level, water level, bone mass calculations ect.

1 Like

Could you link them here?

If there’s already a python script, you may try to utilize Exec Binding.

There’s also some ongoing work on Bluetooth/BLE binding on ESH repository (driven by @chris and @vkolotov) that might potentially open some possibilities in the future.

I found this one on Home assistant forum:

It seems that it is only getting the weight not all the other measurements, e.g.fat bonemass body water level ect.

There is an other tread about it:

I have the version 1 of the scale, so only weight is available.

hi

Is there any progress on this? I’m very interested.

I think the Python scripts mentioned above only work for Mi Scale v1 the v2 is slightly different.

I found java code for it on the openscale source code (https://github.com/oliexdev/openScale), but I don’t know how to port this code to openhab. Anyone with more in depth knowledge on openhab could help on this? If so, I could do the testing.

2 Likes

I successfully integrated MI Scale 2 in Openhab but it tells weight only. Using the formula available on Openscale page I can try to implement calculation of other aspects too.

1 Like

If you need me to test somethings lets me know

sure, i will let you know. I just need some time as currently i am busy in my stupid college exams.

Hi @srijansaxena11 ny update? Anywhere we could go to have a look to your code?

@pfiol sorry i completely forgot about this. well i tried to use the formula in the python script and it gave correct results. so try the script and let me know if it gives correct results to you or not. you need to add your height in cm in the code which i have mentioned in the code.
here is the link: https://github.com/srijansaxena11/miscale

@Moellegaard you can test the script if you want. :slight_smile:

1 Like

I tried and failed :frowning:
I need to install btle; i get the error:
python miscalegwtest.py

Traceback (most recent call last):
  File "miscalegwtest.py", line 7, in <module>
    from bluepy import btle
ImportError: cannot import name btle

Sorry I'm very noob with Python.

I tried with 
`git clone https://github.com/IanHarvey/bluepy.git`
`sudo python setup.py install`
but I get this error:
sudo python setup.py install
running install
running bdist_egg
running egg_info
creating bluepy.egg-info
writing bluepy.egg-info/PKG-INFO
writing top-level names to bluepy.egg-info/top_level.txt
writing dependency_links to bluepy.egg-info/dependency_links.txt
writing entry points to bluepy.egg-info/entry_points.txt
writing manifest file 'bluepy.egg-info/SOURCES.txt'
reading manifest file 'bluepy.egg-info/SOURCES.txt'
writing manifest file 'bluepy.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
Working dir is /home/openhabian/bluepy
execute make -C ./bluepy clean
execute make -C bluepy -j1
Failed to compile bluepy-helper. Exiting install.
Command was 'make -C bluepy -j1' in /home/openhabian/bluepy
Return code was 2
Output was:
make: Entering directory '/home/openhabian/bluepy/bluepy'
tar xzf bluez-src.tgz
touch ./bluez-5.47/lib/bluetooth.c ./bluez-5.47/lib/hci.c ./bluez-5.47/lib/sdp.c ./bluez-5.47/lib/uuid.c ./bluez-5.47/attrib/att.c ./bluez-5.47/attrib/gatt.c ./bluez-5.47/attrib/gattrib.c ./bluez-5.47/attrib/utils.c ./bluez-5.47/btio/btio.c ./bluez-5.47/src/log.c ./bluez-5.47/src/shared/mgmt.c ./bluez-5.47/src/shared/crypto.c ./bluez-5.47/src/shared/att.c ./bluez-5.47/src/shared/queue.c ./bluez-5.47/src/shared/util.c ./bluez-5.47/src/shared/io-glib.c ./bluez-5.47/src/shared/timeout-glib.c
Package glib-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glib-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glib-2.0' found
Package glib-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glib-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glib-2.0' found
cc -L. -g -Wall  -Os -DHAVE_CONFIG_H -I./bluez-5.47/attrib -I./bluez-5.47 -I./bluez-5.47/lib -I./bluez-5.47/src -I./bluez-5.47/gdbus -I./bluez-5.47/btio -I./bluez-5.47/sys  -o bluepy-helper bluepy-helper.c ./bluez-5.47/lib/bluetooth.c ./bluez-5.47/lib/hci.c ./bluez-5.47/lib/sdp.c ./bluez-5.47/lib/uuid.c ./bluez-5.47/attrib/att.c ./bluez-5.47/attrib/gatt.c ./bluez-5.47/attrib/gattrib.c ./bluez-5.47/attrib/utils.c ./bluez-5.47/btio/btio.c ./bluez-5.47/src/log.c ./bluez-5.47/src/shared/mgmt.c ./bluez-5.47/src/shared/crypto.c ./bluez-5.47/src/shared/att.c ./bluez-5.47/src/shared/queue.c ./bluez-5.47/src/shared/util.c ./bluez-5.47/src/shared/io-glib.c ./bluez-5.47/src/shared/timeout-glib.c
bluepy-helper.c:33:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/attrib/att.c:33:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/attrib/gatt.c:32:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/attrib/gattrib.c:34:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/attrib/utils.c:30:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/btio/btio.c:37:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/src/log.c:38:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/src/shared/io-glib.c:30:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
./bluez-5.47/src/shared/timeout-glib.c:22:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
Makefile:30: recipe for target 'bluepy-helper' failed
make: *** [bluepy-helper] Error 1
make: Leaving directory '/home/openhabian/bluepy/bluepy'

Could you please help me out?

I placed it all in my \OPENHABIANPI\openhabian folder

Oh, I manage to fix that, but now I get:

 sudo python miscalegwtest.py
Scanning for devices...
MQTT connection returned result: Connection Accepted.
Traceback (most recent call last):
  File "miscalegwtest.py", line 128, in <module>
    main()
  File "miscalegwtest.py", line 125, in main
    devices = scanner.scan(5)
  File "/usr/local/lib/python2.7/dist-packages/bluepy-1.3.0-py2.7.egg/bluepy/btle.py", line 852, in scan
    self.start(passive=passive)
  File "/usr/local/lib/python2.7/dist-packages/bluepy-1.3.0-py2.7.egg/bluepy/btle.py", line 789, in start
    self._startHelper(iface=self.iface)
  File "/usr/local/lib/python2.7/dist-packages/bluepy-1.3.0-py2.7.egg/bluepy/btle.py", line 284, in _startHelper
    preexec_fn = preexec_function)
  File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I seem that I have both the subprocess.py and the btle.py file…

@Moellegaard Which device are you using? if raspberry pi 0 then it won’t work without an external bluetooth dongle.
Also found this comment on home assistant page:
“I’ve recently tested rpi zero w with xiaomi miscale and it worked fine. From what I’ve found to get working BLE on rpi zero you need kernel at least 4.9. Maybe you are running some older kernel and upgrade would solve this. You could also try running “hcitool lescan” to scan for BLE devices and test if bluetooth low energy is working.”

Hello
hcitool lescan is working and I find different bluetooth devices.
I’m running on a raspberry 3 B
Linux openHABianPi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux

I discovered that something when wrong with my installation of bluepy, but now it works :smiley: thanks alot!

How do you avoid double entries?

what do you mean by double entries? i have made a button in openhab which results in running of this script. so i stand on my weight machine. when it finishes reading my weight i say “ok google turn on sync weight” where “sync weight” is my openhab button. and it updates my current weight which is stored in database.

Okay, can I see your rule? I had root access problems when running from node red.
Thanks for sharing and helping! :smiley:

Sure.

items file:
Switch WeightSync “Sync Weight” [“Switchable”] { channel=“exec:command:weight:run” }

things file:
Thing exec:command:weight [command=“sudo python /etc/openhab2/scripts/miscalegw.py”, interval=0, autorun=false]

1 Like