Integrating Xiaomi Mi Scale

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

Does the scale ready only when a weight is first added to it, or intermittently? Trying to figure out if I could place a water tank on the scale and periodically obtain readings of its weight to know if the tank is full or not. The Mi Flora devices give periodic reports on soil / moisture data, wondering if the scale works the same way or if it only reports when someone first steps on it.

Only upon stepping on it…

I believe there’s an option in the mi fit app to have it always on and transmitting the value constantly but that will probably drain your battery pretty fast. Also, if you have a weight on it all the time it could potentially degrade the sensitivity in the long term.

Hello!
Help me please!

I have home assistant on mini-pc with mosquitto broker and ble-dongle.

Summary

I have installed this add-on https://github.com/lolouk44/hassio-addons/blob/83c95c8c09915e198ba7794042038b08a352932c/mi-scale/DOCS.md

Summary

Scales are connected and i can see data via mqtt explorer:

2022-02-08 20:17:57 - Data Published ...
2022-02-08 20:56:00 - Publishing data to topic miscale/Nika/weight: {"weight":93.00,"weight_unit":"kg","bmi":40.25,"basal_metabolism":1563.43,"visceral_fat":12.90,"lean_body_mass":58.48,"body_fat":49.18,"water":36.29,"bone_mass":2.87,"muscle_mass":44.39,"protein":11.45,"body_type":"Thick-set","metabolic_age":80,"impedance":407,"timestamp":"2022-02-08T20:56:00+00:00"}
2022-02-08 20:56:00 - Data Published ...
Summary

Also i made this sensors:


  - platform: mqtt
    name: "Alex Weight"
    state_topic: "miscale/Alex/weight"
    value_template: "{{ value_json['weight'] }}"
    unit_of_measurement: "kg"
    json_attributes_topic: "miscale/Alex/weight"
    icon: mdi:scale-bathroom
    # Below lines only needed if long term statistics are required
    # state_class: "measurement"

  - platform: mqtt
    name: "Alex BMI"
    state_topic: "miscale/Alex/weight"
    value_template: "{{ value_json['bmi'] }}"
    icon: mdi:human-pregnant
    unit_of_measurement: "kg/m2"
    # Below lines only needed if long term statistics are required
    # state_class: "measurement"
    
  - platform: mqtt
    name: "Nika Weight"
    state_topic: "miscale/Nika/weight"
    value_template: "{{ value_json['weight'] }}"
    unit_of_measurement: "kg"
    json_attributes_topic: "miscale/Nika/weight"
    icon: mdi:scale-bathroom
    # Below lines only needed if long term statistics are required
    # state_class: "measurement"

  - platform: mqtt
    name: "Nika BMI"
    state_topic: "miscale/Nika/weight"
    value_template: "{{ value_json['bmi'] }}"
    icon: mdi:human-pregnant
    unit_of_measurement: "kg/m2"
    # Below lines only needed if long term statistics are required
    # state_class: "measurement"

But in home assistant this sensors have states “unknown”

What should i do to collect data from mqtt topic “miscale” to my sensors?

It’s odd. Clearly your broker receives the data. Are you sure your mqtt connection details are correct in HA? Any logs of interest?

I have

value_template: "{{value_json.weight}}"

which works :slight_smile:

I think the square brackets index an array, rather than a JSON Object

I also do not have this.

you can use either. JSON’s structure is built like an array with layers. If you had a layer that had a space in its name you’d have to use the [‘xxx yyy’] method.

you don’t specifically need this. If you have it, your sensor will pull the data from that topic to populate the sensor’s attributes.

1 Like

I’ve tried to make sensor with your recomendations, but still have no in it.
Also I try to change mqtt setting - earlier it was like z2m:

MQTT_HOST: mqtt://core-mosquitto

now it’l like in mqtt explorer:

MQTT_HOST: 192.168.31.160

And i still can see info in mqtt topic via mqtt explorer, but not in sensor

Summary

image

  - platform: mqtt
    name: "Nika Weight"
    state_topic: "miscale/Nika/weight"
    value_template: "{{ value_json.weight }}"
    # value_template: "{{ value_json['weight'] }}"
    unit_of_measurement: "kg"
    # json_attributes_topic: "miscale/Nika/weight"
    icon: mdi:scale-bathroom
    # Below lines only needed if long term statistics are required
    state_class: "measurement"

  - platform: mqtt
    name: "Nika BMI"
    state_topic: "miscale/Nika/weight"
    # value_template: "{{ value_json['bmi'] }}"
    value_template: "{{ value_json.bmi }}"
    icon: mdi:human-pregnant
    unit_of_measurement: "kg/m2"
    # Below lines only needed if long term statistics are required
    state_class: "measurement"
2022-03-04 21:29:12 - Starting Xiaomi mi Scale...
2022-03-04 21:29:12 - Loading Config From Add-On Options...
2022-03-04 21:29:12 - Config Loaded...
2022-03-04 21:29:12 - Discovery Completed...
2022-03-04 21:29:13 - Publishing data to topic miscale/Nika/weight: {"weight":95.60,"weight_unit":"kg","bmi":41.38,"basal_metabolism":1589.55,"visceral_fat":13.37,"lean_body_mass":59.45,"body_fat":49.59,"water":36.00,"bone_mass":2.92,"muscle_mass":45.28,"protein":11.36,"body_type":"Thick-set","metabolic_age":80,"impedance":386,"timestamp":"2022-03-04T21:29:12+00:00"}
2022-03-04 21:29:13 - Data Published ...
2022-03-04 21:30:58 - Publishing data to topic miscale/Nika/weight: {"weight":95.60,"weight_unit":"kg","bmi":41.38,"basal_metabolism":1589.55,"visceral_fat":13.37,"lean_body_mass":59.41,"body_fat":49.63,"water":35.97,"bone_mass":2.92,"muscle_mass":45.24,"protein":11.35,"body_type":"Thick-set","metabolic_age":80,"impedance":392,"timestamp":"2022-03-04T21:30:58+00:00"}
2022-03-04 21:30:58 - Data Published ...
Summary

And in the same time i used HACS addon https://github.com/dckiller51/bodymiscale
Sensors (with different names):

  - platform: template
    sensors:
      weight_nika:
        friendly_name: "Вес Ника"
        value_template: >-
          {% set weight = states('sensor.ble_weight_mi_scale') | float(0) %}
            {% if 70.0 <= weight < 100.0 %}
              {{ states("sensor.ble_weight_mi_scale") }}
            {% else %}
              {{ states("sensor.weight_nika") }}
            {% endif %}
        unit_of_measurement: 'kg'
        icon_template: mdi:weight-kilogram

  - platform: template
    sensors:
      impedance_nika:
        friendly_name: "ИМТ Ника"
        value_template: >-
          {% set weight = states('sensor.ble_weight_mi_scale') | float(0) %}
            {% if 70.0 <= weight < 100.0 %}
              {{ states("sensor.ble_impedance_mi_scale") }}
            {% else %}
              {{ states("sensor.impedance_nika") }}
            {% endif %}
        unit_of_measurement: 'Ohm'
        icon_template: mdi:omega

And they are working!
And I still don’t understand, whats wrong with my mqtt-based sensors =(
MQTT addon configuration is more flexible for multiple users…

2 Likes