Integrating Xiaomi Mi Scale

Has anyone been able to extract the other metrics from the Mi Scale?

Is it possible to check if there are two people using the Mi Scale? If my wife uses the scale sometimes, I’ve got hilarious down-peaks in the history graph :smiley:

Depends of how close the weights are, but you could compare the measured weight to the previous measurements and choose the closest one.

I have difficulty installing bluepy. I appreciate if you could help me.

Thanks.

What’s your problem in detail?

Did you manage to solve this? I appear to have the same problem :frowning:

Unfortunately not yet. Haven’t tried since my last post but not sure the module has changed at all.

1 Like

Hi @syssi,

I tried to have a look at your code but there are filters that I do not understand.
Any idea or guidance on how to get that data if the scale is discovered as MIBCS instead of MISCALE?
Both @allanak and I have the same issue…
Thanks

What’s the output if you change line 51

from 1d18 to 1b18?

It looks like your scale doesn’t use the same schema as the first version of the device:

>>> data = "1b1802c4e1070b1e13050c00002607"
>>> measurement_unit = data[4:6]
>>> measurement_unit
'02'
>>> measurement = int((data[8:10] + data[6:8]), 16) * 0.01
>>> measurement
577.96
>>> 
>>> # lbs detected
... measurement_unit.startswith(('03', 'b3'))
False
>>> # jin detected
... measurement_unit.startswith(('12', 'b2'))
False
>>> # kg detected
... measurement_unit.startswith(('22', 'a2'))
False
>>> 

Which unit do you use? I tried to shift some octets:

>>> i = 6; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
577.96
>>> i = 8; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
20.17
>>> i = 10; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
28.23
>>> i = 12; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
76.91
>>> i = 14; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
48.94
>>> i = 16; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
12.99
>>> i = 18; int((data[i+2:i+4] + data[i:i+2]), 16) * 0.01
30.7

Do you see your weight somewhere? :wink:

Ah, now I get “Scale is sleeping” regardless of whether I weight myself or not…
So a step forward from before :slight_smile:

Retrieved the long data: 1b1802a4e2070514000c24fdfff83e
I tried all above shifts and I can’t find my weight: 80.6 Kg
I went a bit deeper and found that with i=26, I get twice the weight (jin): 161.2

this was reproduced with a weight of 83.9Kg (1b1802a4e2070514001113fdff8c41)
I had a quick look at the other measurements but can’t retrieve them. Any idea?

OK for now, this is what I changed to make it work:
L53:
Replace
measured = int((data[8:10] + data[6:8]), 16) * 0.01
with
measured = int((data[28:30] + data[26:28]), 16) * 0.01

and I’ve added a new line under L58:
if measunit == "02": unit = 'kg' ; measured = measured / 2

Thanks @syssi :slight_smile:

1 Like

Has the second generation o the scale / your scale a switch next to the battery to change the measurement unit? Could you change the unit and provide the new/changed data? I would like to know the identifier of the other units.

Hi Syssi,

The unit gets changed from the app itself.
Kgs: 1b1802a6e20705150a251df401443e
Lbs: 1b1803a6e20705150a251df4019844
so looks like 02 is kg and 03 is lbs

I’m not able to select jin from the app.

I’ve not managed to map the other values, but will keep trying.
For info, above should reflect this:

  • 79.7Kg
  • 25.7% body fat
  • 56.1 Kg muscle mass
  • 50.9% water

It needs to be saved into custom_component/sensor/ ?

The python snippet publishes the information via MQTT. It isn’t a custom component.

So where to save that file?

I run mine as a separate python script, completely independent of HA. AS per above comment, you can set a crontab to get to run every so often:

Apologies for responding late.

bluepy is installed under /srv/homeassistant/lib/python3.5/site-packages/bluepy

When I try to run the script without sudo, I got the following:

Scanning for devices...
MQTT connection returned result: Connection Accepted.
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/python_scripts/miscalegw.py", line 99, in <module>
    main()
  File "/home/homeassistant/.homeassistant/python_scripts/miscalegw.py", line 96, in main
  devices = scanner.scan(5)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 679, in scan
    self.start(passive=passive)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 617, in start
    self._mgmtCmd("le on")
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 276, in _mgmtCmd
    "Failed to execute mgmt cmd '%s'" % (cmd))
bluepy.btle.BTLEException: Failed to execute mgmt cmd 'le on'

and with sudo:

Scanning for devices...
MQTT connection returned result: Connection Accepted.

Then, I can’t read any data on the sensor.