Integrating Xiaomi Mi Scale

I guess something is wrong with my Pi 3s bluetooth:

After a reboot it seems to be running again, but the status for the docker-id still says “restarting (1)”.

Haven’t been able to find a solution for this. I’m going to try to install this on another Pi.

out of interest, some users appear to have success by adding time.sleep(0.1) to the btle.py file (located in /usr/local/lib/python3.8/site-packages/bluepy/btle.py in the container)


No idea if it’ll work, buth worth a try.

Another user used a separate bluetooth dongle and has no issues (reported) since

1 Like

Great, how do I edit the btle.py-file? When I try “sudo nano /usr/local/lib/python3.8/site-packages/bluepy/btle.py” it says it doesn’t exist.

I just want to make sure I’m doing each step correct. Could you confirm?

  1. Installed Docker and Docker Compose
  2. Created a folder named xiaomi-mi-scale
  3. Inside the folder I’ve uploaded my docker-compose.yml.
  4. cd /home/pi/, then I run the command: docker pull lolouk44/xiaomi-mi-scale
  5. cd /home/pi/xiaomi-mi-scale/, then I run the command: docker-compose -f docker-compose.yml up -d

Is there anything else I should run in Docker at the same time as this? Right now mi-scale is the only thing runnning.

If this doesn’t work I’ll just buy a separate bluetooth dongle :smiley: Thanks again!

you need to run the command inside the container

Seems like I’m stuck since the container always is restarting:
" pi@raspberrypi:~ $ docker exec -it mi-scale nano /usr/local/lib/python3.8/site-packages/bluepy/btle.py

pi@raspberrypi:~ $ docker exec -it mi-scale /bin/bash
Error response from daemon: Container 7e849f367875a5a50afe44800de0e1c42658ffd3a1d5174044a300781f1ede00 is restarting, wait until the container is running
pi@raspberrypi:~ $ docker exec -it mi-scale nano /usr/local/lib/python3.8/site-packages/bluepy/btle.py
Error response from daemon: Container 7e849f367875a5a50afe44800de0e1c42658ffd3a1d5174044a300781f1ede00 is restarting, wait until the container is running

I managed to run docker container inspect id/name and found UpperDir in JSON output which made me find the directory. The weird thing is that I don’t have the btle.py-file in the directory at all. Is there anything I need to add before installing this docker-file?

stupid question, did you install nano inside the docker?

apk update && apk add nano
cd /
find . -name "btle.py"

then nano with the path retrieved
if adding the line doesn’t work, then I don’t know. It seems to be an issue with bluepy / RPi and maybe a BT USB dongle is what you need…

I gave up on the Raspberry Pi and tried with another Raspberry Pi 3B+ since no store near me has a Bluetooth dongle. Was able to set it up and start the container, it even reported back the value from the scale to Hassio. But for the wrong user, not really sure why…

But, after I stepped off the scale it stopped working and the container went into the restarting-loop. Tried to reboot everything and now it restarts after 6 seconds (as you can see in the picture). Compared to the first time, it doesn’t send the value to hassio before restarting… I checked the logs for the container now and it gives me the same error messages as for the other RPis I’ve tried with.

What version of Raspbian and Docker are you using? :slight_smile: Or do you have any recommendation for Bluetooth dongles that would work?

Out if interest what user did the data come under?
In not using raspbian, I use an HP N54L micro server with ubuntu 16.04.
I have no idea what dongle I have, it was the cheapest btle one I found when I bought it on eBay several years ago

Sorry I have no idea what else to try

It was reported to MQTT under “miScale/Elin/weight” instead of “miScale/Dennis/weight”, but I guess it could have something to do with us being 1KG from each other in the environment variables.

I installed the add-on for RPi4 on my hassio-device and now it seems to work. The result in Hassio differs from 0,5-0,2kg to what’s on the display of my scale. But it’s clearly good enough for me.

Do you know if it’s possible to store weight for pets? Tried to add a third user but my guess is that the scale has some kind of limitation regarding storing of weight-data that doesn’t register human contact.

Thanks again. I’m so happy that it finally works!

As long as your pet is heavy enough for the scale to register it should work. I don’t know what the minimum weight requirement is I’m afraid

Hello @lolouk44 and thanks for your work, I have an HP microserver too on proxmox 6.
The path of my bluetooth isn’t ttyAMA0 :

[supervisor.docker] Can't start addon_local_xiaomi_mi_scale: 500 Server Error: Internal Server Error ("error gathering device information while adding custom device "/dev/ttyAMA0": no such file or directory")

Do you know where can I change this ?
Thanks

I use the standard bluepy library so don’t need to set device path anywhere. No idea where to change this.
Are you using an add on, a docker container or direct script from my github?

Does anyone could give me an example on how to store the scale data historical?
for now i use the mini graph card to show all data in a nice way, but it updates every 1-2 hours… so if you dont use the scale for more than one day, the timeline is filled with the last value which makes it pretty useless :sweat_smile: would be nice to hear how you guys made the visualization and also the comparison of the historical data.

greets

I use your addon directly from your github and addon store integration.

EDIT:
I’ll try this:

{
  "name": "Xiaomi Mi Scale",
  "version": "0.7",
  "slug": "xiaomi_mi_scale",
  "description": "Read weight measurements from scale via BLE",
  "arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
  "startup": "before",
  "boot": "auto",
  "devices": ["/dev/ttyACM0:/dev/ttyACM0:rwm"],
  "host_network": true,
  "privileged": ["NET_ADMIN", "SYS_ADMIN"],
  "options" : {},
  "schema" : {}
}

EDIT2: Won’t work, replace configuration when install

I use influxdb and Grafana for this

I’ve not written the add-on.
What happens if you try the docker container separately?

could you give me some examples? i havent used graphana ^^

Check this post:

thanks work perfect

Just tried to install @Tobi0892 addon but there is no longer any refresh option in the addon store and the addon does not show.