Integrating Xiaomi Mi Scale

Hey everyone! I’m trying to read data from the Xiaomi body scale V2 in a React Native app. When I console log the device’s service data, I get strings that look like this: BiTlBwYUDAcNAADKAw==.

How can I convert this to weight data?

The BLE data is normally in bytes, it seems like your data is converted to a string somehow.

For the conversion, have a look at how I did this in BLE Monitor

1 Like

Thank for the quick response. Can i still work with the string or would I have to find a way to get the bytes? How would I convert the string to the (measunit, controlByte, impedance, weight)?

Could I use unpack("<BB7xHH", xvalue) where xvalue is my string? Thanks so much!

Also: I’m using this library: Bluetooth Scanning · dotintent/react-native-ble-plx Wiki · GitHub

Normally, you will get a bytestring like this

043e2402010001ef148244dedf1802010603021b1810 161b18 02a6b20701011201128c01a852 be

The scale V2 is identified with 161b18 (16 means Service Data, UUID = 0x181B)

xvalue is the remaining part (except the last byte, which is the RSSI), so 02a6b20701011201128c01a852. So, when you use this code:
(measunit, controlByte, impedance, weight) = unpack("<BB7xHH", xvalue),
it will extract the 4 parameters (in hex)

  • measunit (B) = 02
  • controlByte (B) = a6
  • skip 7 bytes (7x) = b2070101120112 (I thought this was some kind of timestamp, which we don’t use)
  • impedance (H) = 018c (notice that I reverse the two bytes) = 396 in decimals
  • weight (H) = 52a8 = 21160 in decimals. As measunit is in kg, devide by 200 = 105.8 kg.

I am not sure it this react-native-ble-plx is able to use passive scanning to listen ot BLE messages and/or why it is showing you a string in stead of bytes, never used that package. I see it is able to connect to devices, but that isn’t needed. The scale sends out data without “asking” for it, so you should use passive scanning. .

How do you keep track of the weight sensor? Here it’s seems lost automatically after 10 days by the default recorder?

you need to store that info somewhere else. I use influxDB/Grafana to store my data long term
There’s a very good tutorial on how to install it here:

1 Like

Hi, I’ve had a read thought a bunch of this thread and still have no idea where to start. I got my scales last night and am wondering how to go about integrating it into HA. I have an MQTT broker setup but that’s as far as I’ve got. Can someone point me in the right direction? Also need to have multiple users weigh themselves when they are close to the same weight…

There are multiple ways, one way is using BLE monitor or ESPhome to get the data from the scale. BLE monitor can be used if your scale is within the Bluetooth range of your HA machine, ESPhome if your scale is further away ESP device needed.

Next thing you need is a component that does the splitting up into different persons and calculates all the other data like BMI, based on some input like your length, e.g. bodymiscale

What’s your setup ?
The easiest would be the add-on if you have Home Assistant Operating System.
If you’re on a docker container, then it’s a breeze to set up the container version

I’m obviously biased since I wrote both of them :wink:

@lolouk44 @Ernst

Thank you both.

I’m not running HA using supervisor so I’m using docker as I have docker running home assistant.

I don’t have a Bluetooth monitor, but I do have ESPHome running on an ESP32 that I use for some WiFi temperature sensors. So can I use that as a way to have it communicate? I’m a MQTT broker setup to as I realise I need that, hopefully I can integrate it to node red and home assistant?

Thanks in advance!

hello ho i can cnahge icon color?

hello what is in configuration file, the line for lecord attrivbuite?

Yes, ESPhome will work fine with the V1 and V2 version, see Xiaomi Miscale Sensors — ESPHome and Xiaomi Miscale2 combined into Xiaomi Miscale — ESPHome.

About BLE monitor, you don’t need “a BLE monitor” for that, it is an custom integration that uses the Bluetooth of the Home Assistant machine itself.

Look here, I have made good progress on the card

Guys,

Struggling already quite a bit with this. I’ve got the mi body composition scale 2. I added the addon, configured everything, but i only see an error in the log.

My config looks as follow:

HCI_DEV: hci0
BLUEPY_PASSIVE_SCAN: false
MISCALE_MAC: 50:FB:19:0B:B8:A9
MQTT_PREFIX: miscale
MQTT_HOST: 127.0.0.1
MQTT_USERNAME: "UserName"
MQTT_PASSWORD: "PassWord"
MQTT_PORT: 1883
TIME_INTERVAL: 30
MQTT_DISCOVERY: true
MQTT_DISCOVERY_PREFIX: homeassistant
USERS:
  - NAME: Twan
    SEX: male
    GT: 80
    LT: 100
    HEIGHT: 185
    DOB: '1995-06-26'

This is the error ive got:

2021-09-16 19:52:51 - Starting Xiaomi mi Scale…
2021-09-16 19:52:51 - Loading Config From Add-On Options…
2021-09-16 19:52:51 - Config Loaded…
2021-09-16 19:52:51 - Discovery Completed…
2021-09-16 19:52:56 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:53:31 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:54:06 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:54:41 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:55:16 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:55:16 - 5+ Bluetooth connection errors. Resetting Bluetooth…
Can’t init device hci0: Connection timed out (110)
2021-09-16 19:56:22 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:56:57 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:57:32 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:58:07 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:58:42 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 19:58:42 - 5+ Bluetooth connection errors. Resetting Bluetooth…
Can’t init device hci0: Connection timed out (110)
2021-09-16 19:59:48 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 20:00:23 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 20:00:58 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 20:01:33 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 20:02:08 - Bluetooth connection error: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)
2021-09-16 20:02:08 - 5+ Bluetooth connection errors. Resetting Bluetooth…
Can’t init device hci0: Connection timed out (110)

Im running home assistant Operating System on a pi 4 with built-in bluetooth

I get some data over mqtt on topic: homeassistant/sensor/miscale/UserName/config, so that part seems to be working. There is only no bluetooth communication to the scale.

Do i need to enable something in HA, or stand on the scale on a certain moment?

Make sure the Bluetooth is turned on using raspi-config
Try to set BLUEPY_PASSIVE_SCAN to true
For some reason bluepy appears to have an issue with the built in Bluetooth on raspberry pies
Of that still doesn’t work try a Bluetooth dongle

Lolouk,

Thanks for your reply. Didnt got it working with the built-in bluetooth, so bought a usb dongle and changed to hci1 in the config. Now its working perfect, great job!

1 Like

Hello,
Can someone tell me what is the difference between this 3 github for the scale ?
How to choose the one to install ?

  1. https://github.com/SoulEater45/xiaomi_mi_scale_ha_add_on
  2. https://github.com/dckiller51/bodymiscale
  3. https://github.com/lolouk44/xiaomi_mi_scale

Thank you for your time

Answering in different order (3, 1, 2)

  • The 3rd is an script that is collecting the BLE messages of the scale and calculates additional info like BMI, based on your length. This info is send to MQTT (which can be added in HA as an MQTT sensor)
  • The 1st is an add on for HA, based in the above script (no. 3). Easier to install compared to 3.
  • This 2nd is an integration that is only calculating additional properties, like BMI. The weight has to be collected with another integration, like BLE monitor or ESPHome

So, If you only use it for HA, choose the 1st option if you don’t have other BLE sensors. If you already have BLE sensors, choose the 2nd option in combination with BLE Monitor or ESP Home.

3 Likes

Is there a way to have all sensors added automatically? Simile to how this works for GitHub - briis/hass-weatherflow2mqtt: WeatherFlow to MQTT for Home Assistant. Use UDP to get local weather data in to Home Assistant using MQTT Discovery
In this case all sensors are automatically added in HA (under the MQTT integration a new device is visible and under it entities for each sensor). This clears up the config file quite a bit as the names, icons and everything else are already available.

1 Like