Integrating Xiaomi Mi Scale

subscribing means the mqtt node (ha or mqtt.fx) will subscribe to the topic and read/save all messages sent to the topic.

It doesn’t sound like having done this, can you tell me how to do? Maybe it’s what I’m missing?

I tried to get on the scale without success, nothing appears.

My config dcoker-compose.yml

version: ‘3’
services:

mi-scale:
image: lolouk44/xiaomi-mi-scale:latest
container_name: mi-scale
restart: always

network_mode: host
privileged: true

environment:
- MISCALE_MAC="xx:xx:xx:xx:xx:xx" # Mac address of your scale
- MQTT_HOST=192.168.1.2  # MQTT Server (defaults to 127.0.0.1)
- MQTT_PREFIX=miScale
- MQTT_USERNAME=xxxxx       # Username for MQTT server (comment out if not required)
- MQTT_PASSWORD=xxxxx   # Password for MQTT (comment out if not required)
- MQTT_PORT=1883           # Defaults to 1883
- MQTT_TIMEOUT=30      # Defaults to 60

  # Auto-gender selection/config -- This is used to create the calculations such as BMI, Water/Bone Mass etc...
  # Up to 3 users possible as long as weights do not overlap!

- USER1_GT=73            # If the weight is greater than this number, we'll assume that we're weighing User #1
- USER1_SEX=male
- USER1_NAME=roberto     # Name of the user
- USER1_HEIGHT=179       # Height (in cm) of the user
- USER1_DOB="1989-09-20" # DOB (in yyyy-mm-dd format)

- USER2_LT=52            # If the weight is less than this number, we'll assume that we're weighing User #2
- USER2_SEX=female
- USER2_NAME=laura      # Name of the user
- USER2_HEIGHT=160        # Height (in cm) of the user
- USER2_DOB="1991-02-12" # DOB (in yyyy-mm-dd format)

and configuration.yaml

Bascula Xiaomi Mi Body Composition Scale 2

Peso y Masa corporal Roberto

  • platform: mqtt
    name: “Peso Roberto”
    state_topic: “miScale/roberto/weight”
    value_template: “{{ value_json[‘Weight’] }}”
    unit_of_measurement: “kg”
    json_attributes_topic: “miScale/roberto/weight”
    icon: mdi:scale-bathroom

  • platform: mqtt
    name: “Indice de masa corporal Roberto”
    state_topic: “miScale/roberto/weight”
    value_template: “{{ value_json[‘BMI’] }}”
    icon: mdi:human-pregnant

Peso y Masa corporal Laura

  • platform: mqtt
    name: “Peso Laura”
    state_topic: “miScale/laura/weight”
    value_template: “{{ value_json[‘Weight’] }}”
    unit_of_measurement: “kg”
    json_attributes_topic: “miScale/laura/weight”
    icon: mdi:scale-bathroom

  • platform: mqtt
    name: “Indice de masa corporal Laura”
    state_topic: “miScale/laura/weight”
    value_template: “{{ value_json[‘BMI’] }}”
    icon: mdi:human-pregnant

That is all I did.

if you’re sure your mqtt settings are correct, then make sure the mi app is not running on your phone, step on the scale, wait to get a reading displayed on the scale, then step off.
Next wait up to 5 min (until the minute number ends with 5 or 0) and you should get something sent to MQTT. If not it probably means your MQTT settings are not correct. In any case try and get me the log from then

I will look again, but if my configuration is correct, in addition to the same configuration by my explorer I can see everything in my computer without problem …

I have done what he told me, I have climbed the scale and waited, but nothing has changed :frowning:

I’m missing some step?

what do you now get in your container logs?

the same thing I showed

Just a quick note that I’ve updated the containers:
https://hub.docker.com/r/lolouk44/xiaomi-mi-scale

Key changes:

  • Fixed issue with values in docker-compose seen as strings code (removed the ")
  • Fixed multi-arch platform builds
  • The script now runs continuously as opposed to once every 5 min, removed cron jobs
  • Fixed issue with string to int conversion (mqtt port, timeout) that used to break the paho-mqtt code
  • Updated the biometrics library with latest version from (https://github.com/wiecosystem/Bluetooth)
  • Added logging to docker console
  • Bumped paho-mqtt to V1.5.0
  • Bumped python to 3.8
1 Like

@lolouk44 Do you think is possible to retrieve the weight data real time during weighing?

Is pretty much real time already. Just takes a few seconds to retrieve the data and send to ha. Make sure you run the latest version of the container

yes, i have the last version, and it’s really nice :smile:
but i wondering if you have seen if is possible to get weight data during measurement. before it defines the correct weight, like the app

That would be kind of pointless. Remember HA saves all the states so you’ll end up with lots of incorrect data saved "just so it looks like it’s moving while you weigh yourself "

it depends of the use that we can do with this kind of data.
for example for a smart mirror in front of the scale. i think that saves states in HA is not the only way with this data can be used.

Thanks. Even then it would not behave like the Xiaomi app. There would be Too much latency between mqtt getting the messages then ha receiving them. I probably won’t implement this to be honest

Does the custom component work alongside the Mi Fit app, or do i have to choose to either using the app or the home-assistant integration?

I have a question, everything is working but the mqtt topic keeps sending “miScale/David/weight” instead of the name i gave to the user in compose file.
What am i missing?

Can you share your docker compose file as well as your measured weight?

Sorry missed this one
You can’t use both at the same time
Once the app or the component runs it pretty much takes control of the communication And won’t allow another app to connect
I personally no longer use the mi app anymore

version: ‘3’
services:

mi-scale:
image: lolouk44/xiaomi-mi-scale:latest
container_name: mi-scale
restart: always

network_mode: host
privileged: true

environment:
- MISCALE_MAC=****
- MQTT_HOST=****
- MQTT_PREFIX=miScale
- MQTT_USERNAME=****
- MQTT_PASSWORD=****
- MQTT_PORT=1883
- MQTT_TIMEOUT=60

- USER1_GT:75
- USER1_SEX:male
- USER1_NAME:pedro
- USER1_HEIGHT:176
- USER1_DOB:1984-10-01

- USER2_LT:70
- USER2_SEX:female
- USER2_NAME:naomi
- USER2_HEIGHT:165
- USER2_DOB:1990-07-03

This is what compose says,

mi-scale |
mi-scale | -------------------------------------
mi-scale | Starting Xiaomi mi Scale…
mi-scale | MQTT connection: Connection Accepted.
mi-scale |
mi-scale | Sent data to topic miScale/David/weight: {“Weight”:“87.00”,“BMI”:“28.41”,“Basal Metabolism”:“1765.76”,“Visceral Fat”:“18.42”,“TimeStamp”:“2020-03-21-14:13:30”}

got it, replace the columns : with equal signs = in your docker-compose
For some reason my github /docker were showing an old version of docker-compose (just fixed this).