Integrating Xiaomi Mi Scale

Hello thanks for your words. I Will try to solve your issue when i have the time. You must have custom card mod installed.

1 Like

Hi,
I have 4 questions:

  1. I do not get any figures in the bars on the right, no 16,4 or 90,5 and so on.
  2. I do not get the background jpg working. What might be missing ?
  3. How can I change the white text colour in the bars into black text for readability ?
  4. How do I get the symbols white and rid of the blue ones ?

Hope you have an idea cause currently I see nothing except coloured bars.
thx
image

As of version 0.0.6 the attribute names changed, I updated the card to support it. About the background image, I wasn’t successful with it either.

type: custom:bar-card
entity_row: true
align: split
positions:
  title: 'off'
  minmax: 'off'
  value: inside
  indicator: outside
  icon: outside
style: |-
  bar-card-value, bar-card-minvalue, bar-card-maxvalue {
    color: #cccccc;
    font-weight: bold;
    text-shadow: 1px 1px #0005;
  }
  bar-card-title {
    color: var(--secondary-text-color)
    font-weight: bold;
  }
  ha-card:before  {
    content: " ";
    background: url('/local/images/miscale.jpg');
    background-size: cover;
    opacity: 0.7;
    position: absolute;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 0;
  }
entities:
  - entity: bodymiscale.hudsonbrendon
    attribute: bmi
    min: '0'
    max: '45'
    target: '22'
    severity:
      - from: '0'
        to: '18.5'
        color: blue
      - from: '18.5'
        to: '25'
        color: green
      - from: '25'
        color: yellow
        to: '28'
      - from: '28'
        to: '32'
        color: orange
      - from: '32'
        to: '45'
        color: red
    name: BMI
    positions:
      minmax: 'off'
      indicator: outside
    height: 50%
    width: 120%
    icon: mdi:human-handsup
  - entity: bodymiscale.hudsonbrendon
    attribute: body_fat
    min: '0'
    max: '45'
    target: '22'
    severity:
      - from: '0'
        to: '12'
        color: aqua
      - from: '12'
        to: '18'
        color: blue
      - from: '18'
        color: green
        to: '23'
      - from: '23'
        to: '28'
        color: darkkhaki
      - from: '28'
        to: '45'
        color: orange
    name: Gordura
    height: 50%
    width: 120%
  - entity: bodymiscale.hudsonbrendon
    attribute: water
    min: '0'
    max: '100'
    target: '63'
    severity:
      - from: '0'
        to: '55'
        color: orange
      - from: '55'
        to: '65'
        color: green
      - from: '65'
        color: lime
        to: '100'
    name: Água
    width: ' 120%'
    height: ' 50%'
    icon: mdi:water-alert
  - entity: bodymiscale.hudsonbrendon
    attribute: basal_metabolism
    min: '0'
    max: '3800'
    target: '2000'
    severity:
      - from: '0'
        to: '1851'
        color: orange
      - from: '1851'
        to: '3800'
        color: green
    name: Meta Basal
    width: ' 120%'
    height: 50%
    icon: mdi:run
  - entity: bodymiscale.hudsonbrendon
    attribute: visceral_fat
    min: '0'
    max: '30'
    target: '9'
    severity:
      - from: '0'
        to: '10'
        color: green
      - from: '10'
        to: '15'
        color: orange
      - from: '15'
        color: red
        to: '30'
      - from: '23'
        to: '28'
        color: darkkhaki
      - from: '28'
        to: '45'
        color: orange
    name: Gordura Visceral
    width: ' 120%'
    height: 50%
    icon: mdi:hamburger
  - entity: bodymiscale.hudsonbrendon
    attribute: muscle_mass
    min: '0'
    max: '80'
    target: '55'
    severity:
      - from: '-2'
        color: orange
        to: '49.4'
      - color: green
        from: '49.4'
        to: '59.5'
      - color: lime
        to: '80'
        from: '59.5'
    name: Músculo
    width: ' 120%'
    height: 50%
    icon: mdi:weight-lifter
  - entity: bodymiscale.hudsonbrendon
    attribute: protein
    min: '0'
    max: '40'
    target: '20'
    severity:
      - from: '0'
        to: '16'
        color: orange
      - from: '16'
        to: '20'
        color: green
      - from: '20'
        color: lime
        to: '40'
    name: Proteína
    width: ' 120%'
    height: 50%
    icon: mdi:food-steak
  - entity: bodymiscale.hudsonbrendon
    attribute: bone_mass
    min: '0'
    max: '10'
    target: '3'
    severity:
      - from: '0'
        to: '2'
        color: orange
      - from: '2'
        color: green
        to: '4.20'
      - color: lime
        to: '10'
        from: '4.20'
    name: Massa óssea
    height: 50%
    width: ' 120%'
    icon: mdi:bone
  - entity: bodymiscale.hudsonbrendon
    attribute: weight
    name: Peso
    min: '40'
    max: '110'
    target: '77'
    severity:
      - from: '40'
        color: aqua
        to: '57.3'
      - from: '57.3'
        to: '77.4'
        color: green
      - from: '77.4'
        to: '86.7'
        color: darkkhaki
      - from: '86.7'
        to: '99.1'
        color: orange
      - from: '99.1'
        to: '110'
        color: red
    width: ' 120%'
    height: 50%
    icon: mdi:weight-kilogram
title: Hudson Brendon
columns: '2'
animation:
  state: 'on'
  speed: '15'
decimal: '1'

image

2 Likes

Meanwhile I found out that the underlaying MiScale script is not working cause the data for the “aurelien sensor” are not there.

Regarding background image I also had checked different ways like ‘local/image/miscale.jpg’ without the url cause that was working images.

The blue colour of the icon is part of the basic configuration in the primary / accent colour selection.

With the update of bodymiscale the attributtes name changed, @hudsonbrendon post the new names. About question 3 and 4 y can,t either change it, i discover that mine icons appear white because of the theme i,m using, so i guess that changing theme settings will do that.

About the background image, it is strange that it don,t show up for so many of you, let me say all i have about it :
That is the image i have :

miscale

and i put it in this folder /config/www/image/miscale.jpg

Hi Ricardo,

I have meanwhile fixed the bodymiscale points out: it was the sensor name cause I did not know that ‘sensor.weigh_aurelien’ was referring to the original sensor.ble_weight_mi_scale2’

It must start like this:
[boymiscale.yaml]
wolf:
sensors:
weight: ‘sensor.ble_weight_mi_scale2’

Then I got the data from the scale and saw them in the bodymiscale.wolf sensor but your code still did not show any value caused by the attributes you had used partially with uppercase letters and also ’ ’ and not ‘_’ .

After I had changed your attribute lines it worked. I mean lines like this
attribute: Visceral fat changed to that attribute: ‘visceral_fat’

Then I found another typo or point that should be fixed

  - entity:      'bodymiscale.wolf'
    attribute:   'visceral_fat'
    name:        'BAUCHFETT'
    min:         '0'
    max:         '30'
    target:      '9'
    severity:
      - from:    '0'
        to:      '10'
        color:   'green'
      - from:    '10'
        to:      '15'
        color:   'darkgreen' 
      - from:    '15'
        color:   'orange'
        to:      '30'
      - from:    '23'
        to:      '28'

In the third last lane you had a limt set to 30 but the from value in the next 2 lines 23 and 28 are smaller so this segment will be jumped over or ignored.

the last 5 lines should be changed from 30 to 23

  - from:    '15'
    color:   'orange'
    to:      '23'
  - from:    '23'
    to:      '28'

I have a 181D so I checked al the severity sections for that “smaller” model but of cause not those features mine does not support. I guess it might be worth to check the missing ones, in particular

 - water
 - body_fat
 - muscle_ma
 - bone_mass
 - protein

Then please do the attribute exchange of space with “-” and lowercases only cause it would be nice if you replace your previously posted code above too.
That will avoid others from falling into the pitfall I had fallin in.

Regarding background picture: which installation are you running?

  • DOCKER HA
  • DOCKER HASSIO
  • HASSIO image

I have tried and tried with
background
background-image
image
and from
(/home/pi/HomeAssistant/www/img/miscale.jpg)
over
(/local/img/miscale.jpg)
to all those variants with ‘’ or “”

Nothing has worked out so far, even thought others had used similiar code that had worked.

Ok thanks for your corrections, i just updated my code of the card in my previous code. The attribute issue was an breaking change of the component, it was working before.

For the image , i am running Home assistant in an vm of virtual box , with home assistant core and superviser, you could try change the last value z-index: 0; with z-index: 1; or z-index: -1; to see if it changes something.

Don,t forget you have to have card-mod.

OK,
that was the pitfall for all those who had to struggle with the background image

I guess it would be good if you add that to your first code too.

ATTENTION: after the installation background image did work, but only after saving.

Usually the visual editor or code editor updates the preview instantly but not in this case.
Here it needs to be saved to show the updated result afterwards.
I also noticed recently that a restart is not enough and that it needs a stop and start.

I then tried the z-index: variants where
0 means grafic in background and
1 in foreground
-1 means grafic will be on the mars, cause it does no longer appear.

I also tried the transparent png advice I had found somewhere else.
Did work like jpg.

UPDATE:
New issue caused by the background: a title is no longer visible
One workaround is to use a transparent png cause then the title will be there.

You simply need to install the card-mod and then the background image will appear when you have saved the code.

Changes in the code editor itself will not appear in the preview ! They will only appear when you had saved.

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!