Integrating Xiaomi Mi Scale

Its working, tnx.
User 3, how does it work, how does it know who the 3rd user is?
With user 1 and 2 you say above or under a certain weigth.

You have an upper limit and a lower limit.
Weight over upper limit goes to user 1
Weight under lower limit goes to user 2
anything else goes to user 3.

1 Like

I’ve noticed that after some time your docker image isn’t up, when i troubleshoot i see that my bluetooth is off, i need to restart the rpi3+ to get it working again but i keeps failing after some time.
I’ve reinstalled raspbian lite but still the same problem. You got any ideas?

mi-scale | Starting Xiaomi mi Scale…
mi-scale | Traceback (most recent call last):
mi-scale | File “/opt/miscale/Xiaomi_Scale.py”, line 180, in
mi-scale | main()
mi-scale | File “/opt/miscale/Xiaomi_Scale.py”, line 173, in main
mi-scale | scanner.scan(5)
mi-scale | File “/usr/local/lib/python3.8/site-packages/bluepy/btle.py”, line 852, in scan
mi-scale | self.start(passive=passive)
mi-scale | File “/usr/local/lib/python3.8/site-packages/bluepy/btle.py”, line 797, in start
mi-scale | self._mgmtCmd(self._cmd()+“end”)
mi-scale | File “/usr/local/lib/python3.8/site-packages/bluepy/btle.py”, line 312, in _mgmtCmd
mi-scale | raise BTLEManagementError(“Failed to execute management command ‘%s’” % (cmd), rsp)
mi-scale | bluepy.btle.BTLEManagementError: Failed to execute management command ‘scanend’ (code: 11, error: Rejected)

Do you have anything else that’s using Bluetooth? I don’t have any issues But I’m not using a RPi

No nothing else, keeps crashing when i step on the scale after a while.

Ok. What happens if you take the container down and restart it. Does it still work? Si you get different error messages?

Same error because it totally crashes the bluetooth.

I’m sorry not sure what to say. Works flawlessly for me. Do you have a usb Bluetooth stick you can try?

No, need to buy one then. which platform are u using it on?

I have bought a usb bluetooth stick, put off internal bluetooth.
It’s up and running for 2 days now, so for some reason it crashes the internal bluetooth.
Btw i love it.

Thanks for the feedback, much appreciated. Now to figure out why it crashes :thinking:
Got a similar report with a user on RPI 4…

@lolouk44 i tried your integration and it works perfectly! thank you for this =) but theres a little thing im wondering about… would it be possible to return values like overweight skinny etc depending on the calculated values? (also good/bad/normal ranges for the other values from the scale?)

edit: im using the container on a rpi3+

thank you very much

Not looked at that yet but will see if it’s possible (meaning if I can be arsed :joy:)

Haha. I just thought there are some options, cause i saw something like this in some of the scripts in the src folder :wink:

My Mi Body Scale #2 has the same Model number, so I had to search for MIBFS to get the MAC-adress. I’ve used this add-on: https://github.com/Tobi0892/xiaomi_mi_scale - and it successfully installs, I’ve added the sensors that also shows up. But they won’t register any value.

I haven’t opened the Mi Fit-app while trying either. I’m using the Mosquitto broker add-on in HASS.IO but I’m not sure of how to make sure the scale and MQTT are talking to each other. I installed MQTT.fx and connected to hass.io using the same credentials that’s in my Dockerfile, but I don’t see anything pop up regarding the Scale.

Sorry for a messy question, just not sure of what to do to make it work. Is there another way that I could install it? I haven’t installed hass.io manually so I’m not sure of how to install it the Docker-way.

Thanks for the great work, really looking forward to see it work for me :smiley:

EDIT:

Here is the log from the add-on:


Here is the log from MQTT:

what code are you using to connect to the scale? Docker container? python script?
The current (latest) version no longer uses crontab

1 Like

I removed it from hassio. And installed Docker on a fresh Raspberry Pi, I followed the instructions and the container is up and running. I did the following commands in order:

mkdir xiaomi-mi-scale
cd xiaomi-mi-scale
sudo nano docker-compose.yml (and pasted everything)
docker-compose up -d

Is there any way to check if the connection is valid or if I’m still missing something? Thanks again :smiley:

EDIT: Just tried to use the scale, seems to work. Am I able to edit the “docker-compose.yml” or do I need to remove this and do everything again? :slight_smile: Would be great to adjust mine or/and my wifes weight-value from time to time, at the moment we’re both almost at the same weight.

EDIT 2: Seems like it just picked up the first time I used it.

EDIT 3: Tried reinstall it, it won’t update my values for any sensors. I’ve restarted hassio and tried to use the scale with and without socks. And for my Raspberry Pi 3 with Docker installed has the status “Restarting (1) 7 seconds ago”, and counting up to 1 min and then restarts again. Is my docker-compose.yml wrong? Here is the pastebin.

your docker-compose file appears correct at first glance.
Can you get the logs from the docker container?

Great! Thanks :smiley: This is my log:

Starting Xiaomi mi Scale...
MQTT connection: Connection Accepted.
Traceback (most recent call last):
  File "/opt/miscale/Xiaomi_Scale.py", line 180, in <module>
    main()
  File "/opt/miscale/Xiaomi_Scale.py", line 173, in main
    scanner.scan(5)
  File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 852, in scan
    self.start(passive=passive)
  File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 797, in start
    self._mgmtCmd(self._cmd()+"end")
  File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
    raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)

is bluetooth enabled on your Pi?
can you try:
sudo hciconfig hci0 down && sudo hciconfig hci0 up
then restart the container?

1 Like