Integrating Xiaomi Mi Scale

I’ve recently purchased a Xiaomi Body Scale online and would like to include weight tracking in HASS. Although the product is still on it’s way from China I’m thinking about the best way to integrate it. So, I’d like to ask if someone owns this device and has successfully managed to get it working with HASS?
The scale sends it’s data via bluetooth and there is also a library available to handle the data. A command line sensor probably seems to be the best solution to gather the data of the scale. What do you think?

2 Likes

Some python code here: https://github.com/chaeplin/Xiaomi_scale_scan/blob/master/Xiaomi_scale_scan.py
So should be possible

I didn’t found any library that can read internal memory (not only current weight of person, standing on mi scale) =(((

My scale arrived yesterday and in case anyone is interested here is my solution:

I’ve used the above mentioned library node-xiaomi-scale. I have written a script (fetchscaledata.js) running as cronjob. Output of scale data is written to a textfile (scanData.txt). First line contents weight, second line contains calculated bmi. The script waits for the scale to be stabilized and the load to be removed. Afterwards it prints the last measured data. Simply run sudo node ./fetchdata.js > scaleData.txt:

// fetchscaledata.js
let MiScale = require('../index.js');
let miscale = new MiScale();

miscale.startScanning();

miscale.on('data', function (scale) {
    var weight = scale['weight']
    var height = 1.84 // Height in meters [m]
    var bmi = (weight / Math.pow(height, 2)).toFixed(2)
    var statusStabilized = scale['isStabilized']
    var statusLoadRemoved = scale['loadRemoved']

    if (statusStabilized || statusLoadRemoved) {
        console.log(weight + "\n" + bmi)
        process.exit()
    }
});

Afterwards setup two command line sensors for weight and bmi. Scan intervall is set to every 6 hours:

- platform: command_line
  name: Gewicht
  unit_of_measurement: "kg"
  scan_interval: 21600 
  command: head -1 PATHTOFILE/scaleData.txt | tail -1

- platform: command_line  
  name: BMI  
  command: head -2 PATHTOFILE/scaleData.txt | tail -1  
  scan_interval: 21600

As stated before it’s not possible to read data history from the scale. Have fun.

6 Likes

I have found working code “example” with history on java:

1 Like

Does anybody can test my port, written in golang to read scale data? My scale are far away from me =(

I am very interested in this one, could you gently tell me how do you add bluetooth le to the raspberry pi? And how do you integrated it with this one? Is it possible to generate some sort of graphics?

Thanks

Here is BLE installation manual: http://www.elinux.org/RPi_Bluetooth_LE , I am still not integrated it - because I will test it only on Friday (I will come back home) and I will write mqtt integration later, but you can test it right now - it must write all history data to console (if protocol is correct and I didn’t make any mistakes in software).
I will not generate any graphics because in my system it will work with home assistant.

I have made a sensor that gives the latest measured weight as a sensor in HA:
https://github.com/Danielhiversen/home-assistant_config/blob/master/custom_components/sensor/xiaomi_scale.py

It works fine if I run hass as root, but not able to make it work with a normal user.
I have tried to run sudo setcap cap_net_raw,cap_net_admin+eip /home/dahoiv/home-assistant/venv/bin/python3 , but that does not help

Any suggestions for how I can fix that?

so if weight is above a certain value you electrify the fridge door? :smile:

4 Likes

Very good idea. Now i have only police alarm when I open fridge at night =)))

2 Likes

Did you sorted out? Does it work accuratelly? Good job by the way even if it only works by running hass as root is actually a big achievement and maybe a go for me to buy this scale :slight_smile:

I have only used it on my test instance of HA, and there it works fine if you run HA as root.

There is a way to just doing it like the Mi Plant? Because I still didn’t understand how it work (the script of Mi Scale).

I do not think I understand what you suggest here.

I mean: why you need root to search a bluetooth device? It’s possibile use the same script used for Mi Flora to get data from the Mi Scale?

Is there any news here? I’am also looking for a component to integrate the Mi scale.

I just bought one and will test the provided code on this topic then I will revert back

Hi,

has anybody gotten further into this? I would really like to collect the data and show it in my home assistant dashboard.

Best,

Alex

Apparently not :confused: