Integrating Xiaomi Mi Scale

I was just wondering how often to run the script.
@syssi listed above a run on an hourly interval at xx:30. I’m concerned that the scale will be in sleep mode by then.
Yet if I refresh too often, the scale doesn’t go into sleep mode, thus consuming more power/battery
I was wondering if anyone had found a “sweet spot” on how often to “prod” the scale to check for readings to

  1. ensure the latest weighing gets caught
  2. ensure we don’t keep the scale “awake”

So far I’m running at a 5 min interval but would like to hear other people’s experience

I am thinking of creating a switch template which would run the script.
If I call it something like “Scale”, I would be able to command Alexa “turn on scale” after I weight myself, and this will read the data off the scale.

Everything is in future tense because I just got mi scale delivered and haven’t yet tried to use it :slight_smile:

I’ve been playing about with the “sleep” time for the script. It is now called by a cron job every 5 min. It’s enough to catch a reading before the scale goes back to sleep, and not often enough that it’ll keep it awake.

image

Now I’m no android user and have no idea on how to reverse engineer an apk, but if someone had the skills to try and extract the formulae used to calculate the various body measures, it would be great

I managed to download the APK and convert it to JAR, but I have no idea what or where to look to try and get he formula.
Is there anybody who’s familiar with APK / Android programming who could have a look or at least give me some pointers? I can PM the files if required.

I was playing with it as well, didn’t find anything unfortunately.
I believe the formula is somewhere in these ARM compiled files:
lib\armeabi\libBodyfat.so
lib\armeabi\libdataProcess.so
No idea how to decompile them though. I saw some ASM/C++ converters, but they are not free. ASM is simply gibberish to me so that I have no point of looking at even :slight_smile:
We need someone who can dig deeper!

1 Like

Guys, what about OpenScale?

I’ve done a feature request: OpenScale component

It’s been a while since I’ve started this post. Today I’ve taken the time to write a blog post about the way I’ve integrated the MiScale in Homeassistant. The post is in german. Maybe it’s helpful to someone.

https://www.triumvirat.org/2018/07/28/miscale-und-homeassistant/

2 Likes

interesting read. So you don’t do anything with the impedance I guess to calculate the BMI and only take your height into consideration?

Absolutely right. I’ve got the first version of the scale. It doesn’t have the impedance functionality.

The guy from OpenScale is close to make it work for BMI, Muscle, water, etc. It would be nice to integrate that into HA. With the new user features, it makes a lot of sense

Why do you think he’s close to make it work ?

Stupid question Alert:

When I’m trying to run this script (https://hastebin.com/mibikorepo.py) I’m getting the following error. What m’I doing wrong ?

/home/pi# sudo python ./miscale.py
Traceback (most recent call last):
File “./miscale.py”, line 9, in
from bluepy import btle
ImportError: No module named bluepy

Note: I have installed bluepy in the Pi 3B, and trying to execute the script home directory.

what version of python are you running?

Python 3.5.3

Cool. you may need to check which version of bluepy you installed. It may be that it’s the one for python 2.7 or other.
Try and run the script with sudo pythonX.XX /miscale.py where X.XX is the python version matching your install of bluepy and you shouldn’t get that same error message.
Unless you use bluepy somewhere else, you could uninstall it and reinstall it for the correct version of python (e.g. using pip vs pip3 for example)

1 Like

I had installed bluepy for pip3 only
but running the script with mentioning the python version did worked for me

sudo python3.5 ./miscale.py
it is now showing searching for devices …
I’ll go home put my Mi Scale’s mac id in the script and try to fetch the results.

Thanks :slight_smile:

1 Like

Hi lolouk44

I tried with my Mi Scale’s mac and it did worked, Now my question is how can i get the other matrices like Body fat, water, muscle and all is it possible ??

MQTT connection returned result: Connection Accepted.
Device: f6:xx:xx:xx:xx:xx (random), -84 dBm .
Sent data to topic miscale/weight/kg: 80.6 kg

for now I’ve only computer the BMI based off formulas I’ve found online:
BMI = weight / (height * height)
weight is in Kg, height is i m
Check how i’ve done it here:


I was looking to see if someone could find the formula that Xiaomi uses for its scales. I might use a formula from online sites in the future, but for now I’m only tracking weigtht and BMI

1 Like

Are you guys thinking into making this an official component? Would be easier to use. Were you able to make it works? Would love to see my data sent to my Home assistant directly instead of having to bring my mobile with me all the time