Integrating Xiaomi Mi Scale

Hi @Ernst , thanks for that! But it seems that BLE Monitor only takes the weight and impedance but does not do the computation to create all the other sensors or attributes.

Anyway, did anyone created a nice Lovelace frontend (UI) ?
I have ideas where it could be green or red depending of values, inspired by the official app.

You can get additional attributes with this integration.

Thank you! It seems not to manage more than one user.

You can create multi user support with node red.

A template sensor will probably also be possible to do the split up.

The reason I didn’t include this, it because I think it would make more sense if there is an integration that does this calculations like BMI and extra attributes independently of the weight measurements. In that way, it is useful for every scale, not only MI Scales.

@mgim

If node red turns you off, you can create a sensor template

  1. Put a name for your weight sensor = weight_name_user1
  2. Change the name of the sensor according to your choice above = {{ states(“sensor.weight_name_user1”) }}
  3. To determine the user you must enter where your weight is. Between xx kg and xx kg = {% if 69 <= weight <= 72.99 %}

The problem with this solution is that if 2 users have a weight too close together it will not work.

#Balance Connectée
- platform: template
  sensors:
    weight_name_user1:
      friendly_name: "Weight Name"
      value_template: >-
        {% set weight = states('sensor.xiaomi_mi_scale_weight') | float %}
          {% if 69 <= weight <= 72.99 %}
            {{ states("sensor.xiaomi_mi_scale_weight") }}
          {% else %}
            {{ states("sensor.weight_name_user1") }}
          {% endif %}
      unit_of_measurement: 'kg'
      icon_template: mdi:weight-kilogram
- platform: template
  sensors:
    weight_name_user2:
      friendly_name: "Weight Name"
      value_template: >-
        {% set weight = states('sensor.xiaomi_mi_scale_weight') | float %}
          {% if 60 <= weight <= 68.99 %}
            {{ states("sensor.xiaomi_mi_scale_weight") }}
          {% else %}
            {{ states("sensor.weight_name_user2") }}
          {% endif %}
      unit_of_measurement: 'kg'
      icon_template: mdi:weight-kilogram

For impedance:

We keep the same logic, it is the weight that will determine the user

  1. Put a name for your impedance sensor = impedance_name_user1
  2. Change the name of the sensor according to your choice above = {{ states(“sensor.impedance_name_user1”) }}
  3. To determine the user you must enter where your weight is. Between xx kg and xx kg = {% if 69 <= weight <= 72.99 %}
- platform: template
  sensors:
    impedance_name_user1:
      friendly_name: "Impedance Name"
      value_template: >-
        {% set weight = states('sensor.xiaomi_mi_scale_weight') | float %}
          {% if 69 <= weight <= 72.99 %}
            {{ states("sensor.xiaomi_mi_scale_impedance") }}
          {% else %}
            {{ states("sensor.impedance_name_user1") }}
          {% endif %}
      unit_of_measurement: 'ohm'
      icon_template: mdi:omega
- platform: template
  sensors:
    impedance_name_user2:
      friendly_name: "Impedance Name"
      value_template: >-
        {% set weight = states('sensor.xiaomi_mi_scale_weight') | float %}
          {% if 60 <= weight <= 68.99 %}
            {{ states("sensor.xiaomi_mi_scale_impedance") }}
          {% else %}
            {{ states("sensor.impedance_name_user2") }}
          {% endif %}
      unit_of_measurement: 'ohm'
      icon_template: mdi:omega
11 Likes

I need help getting rid if “Timmy”. Timmy was added as a user from an update. I removed him from the options but he is still in my entities. How do i remove this user since that was a default user.

Running the addon from home assistant supervised on hassos on raspberry pi.

@sbobergje you need to post an empty message to the Timmy topic with the retain flag set on.
Alternatively use an app like MQTT Explorer to delete the unwanted topic

Hello. Did anyone have experience weighing something that is not heavy. I had an idea to keep track of the weight of my dog ​​(French Bulldog) weight 8-9kg does not record (

Is there any way this scale/setup would work with a persistent weight applied to the scale? Or would it need to be placed on it each time?

I’ve seen some on sale and am thinking of using the scales to keep track of the weight of some kegs of beer in the fridge, so i can use it to convert to how many beers there are left in each.

No that won’t work. You typically need to step in the scale to activate it. It then reads your weight then goes to sleep after a few seconds.

Hello,
with the use of the bodymiscale component i made something to present it on lovelace UI.

3 Likes

It’s great work! Could you share the code, please?

1 Like

Ok, sure.
Just a note:
I am not an code expert so the code may have some extra card mod style that may not be doing no thing :grin:

i use custom bar card, and i mimic the settings ( severity in the card) in the mi fit app.

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.ricardo
    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.ricardo
    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.ricardo
    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.ricardo
    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.ricardo
    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: darkkhaki
        to: '23'
      - from: '23'
        to: '28'
        color: red
      - from: '28'
        to: '45'
        color: orange
    name: Gordura Visc.
    width: ' 120%'
    height: 50%
    icon: mdi:hamburger
  - entity: bodymiscale.ricardo
    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.ricardo
    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.ricardo
    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.ricardo
    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: Ricardo
columns: '2'
animation:
  state: 'on'
  speed: '15'
decimal: '1'

6 Likes

Thanks for sharing, it’s working so far.

However, there is one problem when you restart the core. This causes the template sensors to lose their state and have to recreate it since they are not persistent. However, this only works for one person, the one who weighed himself last.

An example with the values from your template: First a person weighs himself with 70 kg. This is assigned to user1. Then a person weighs himself with 65 kg, this is assigned to user2. Now the core is restarted. Both sensors are unavailable at first. The last state of sensor.xiaomi_mi_scale_weight is 65, so this is correctly assigned to user2 again. User1 is assigned sensor.weight_name_user1 instead, which is unavailable. This will not be corrected until user1 weighs itself again.

Do you have any idea how to solve this?

1 Like

Hello, at the beginning I was part in this direction then my wife and I we have a weight too close. So I went with this solution. In addition it keeps the data well after a restart.

@finipini

I am also working on a map. I have some difficulty being a novice. But you will also find a manual card which works very well.

1 Like

Yes i saw that card earlier, but wanted something to show how far i was from the ideal value of some attributes. Althow the ideal is to store this value for long time anda make some kind of a chart with it.

with 4 load cell weight sensors, esp32 and esphome I have built a cheap scale which can be used with HA. you can use it for example with your bed so your weight is tracked while you are sleeping (or not).

See also Load Cell Amplifier HX711 Breakout Hookup Guide - learn.sparkfun.com

Hi Ricardo,
first a big thank you cause it worked like shown and I like it.

FOR ALL BEGINNERS: you first will need harcs installed cause this offers an automated installation of the custom type bar-card (or you have to do it following the manual way via github)
Here is a list of terms a lot of you wanna translate from portuguese, luckily google does a good trick and the variables are declared in english, so for an easy localisation search for all the “name” items which are here portuguese.
BMI = BMI = BMI
Gordura = fat = Fett
Aqua = water = Wasser
Basal metabolism = basal metabolism = Grundumsatz
Visceral fat = visceral fat = Bauchfett
Músculo = muscles mass = Muskelmasse
Proteína = protein = Protein
Massa óssea = bone mass = Knochenmasse
Peso = weight = Gewicht

Finally you have to replace ricardo with your name at the last line with yours and then everywhere else with the name of your scale sensor. Easiest way to find out your scale’s sensor name is developer tools and then in the header of the table type ‘scale’ … and check the bodymiscale.* one cause that is the sensor’s name you have to put as replacement for this ‘bodymiscale.ricardo’

Only point I have an issue with is the following line
background: url(‘/local/img/miscale2.jpg’);

Usually “/local” means /$config path/www/ and therefore the scale should work if it finds in my /home-assistant/www/img path a file called miscale2.jpg, cause /config stays always for /$config path/www/
I can open my miscale2.jpg manualy just to see if it is a picture and not corrupted.

Therefore a huge thankyou to Ricardo for his achievement.
As I had said it “works” and that means a lot these days cause usually it takes a lot of time to see an idea and to implement it into your HA installation depending on which installation you have and how good the variables are named or not.

Ricardo, yours worked fine for me, but might be usefull to add a few comment lines for all the beginners like me (1 week into).
Can you please check this background image line
background: url(‘/local/img/miscale2.jpg’);

And beyond the background picture question I have another one: regarding font colour
We would like black font instead of white one but I could not find “white” in your script or font colour.

Ricardo, thanks a lot for sharing.