Integrating Xiaomi Mi Scale

Is it possible to support Mi Scale model XMTZC01HM with this component?

maybe. Have you tried it already? What do you see in the logs?

Hi Everybody!

I’ve got the MiScale V1 (without body composition).

It works great with KGs, but I can’t get lbs to work. Has anyone been able to get it to work?

The scale has a hardware button under the battery cover to select units.
If I do select Lbs on the scale, it reports the weight as KG to home assistant, and results in an error

Thanks lolouk44 for putting it all together

Can you raise an issue on the repo and share the error pls?

Thanks for the reply. I tested it with Jin and it worked as well as it did with KG. Its just the Lbs that are not reporting

I tested it, checked the log, but couldn’t find an error message anywhere - Not sure if I’m imagining that message! I remember something about being above the max weight - Though I also tried weighing in with 50lbs, just so I would be within the scales acceptable range even if it registered as KG. There’s nothing that comes through on homeassistant

Let me know if there’s anything else I can try to help. I looked at your code, and suspect it has to do with the if statement when designating the units, but couldn’t get much further than that.

Hello lolouk44,

I am using your addon on https://github.com/lolouk44/hassio-addons/. Thanks a lot for that.

However, I have this error:

-------------------------------------
2020-08-25 09:18:00 - Starting Xiaomi mi Scale...
2020-08-25 09:18:00 - Loading Config From Add-On Options...
2020-08-25 09:18:00 - Config Loaded...
2020-08-25 09:18:04 - Discovery Completed...
2020-08-25 09:18:09 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 11, error: Rejected)
2020-08-25 09:18:44 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 11, error: Rejected)
2020-08-25 16:49:55 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 11, error: Rejected)
2020-08-25 16:50:30 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 11, error: Rejected)
2020-08-25 16:51:05 - Bluetooth connection error: Failed to execute management command 'scanend' (code: 11, error: Rejected)
2020-08-25 16:51:05 - 5+ Bluetooth connection errors. Resetting Bluetooth...

Is this because of “Xiaomi passive BLE monitor sensor platform” HACS?
In Xiaomi mi Scale addon, I already config to use HCI_DEV: hci0 which is current active bluetooth dev. Is there way to solve this?

thank you

I have the same issues. after restarting bl in ubuntu it works but after a few times I got this message again.

my setup is: esxi with an ubuntu vm with a home assistant docker.

There seem to be issues sharing bluetooth when used by multiple apps.
I’ve set my script to sleep for 30 sec by default to allow other apps to use the bluetooth radio, but if other apps take constant control of the BT radio there isn’t much I can do

Can you try to not use the other app just to confirm it works well?
If so one workaround would be to get a cheap BT dongle…

Can you try the same as above pls?

I will order a bl stick indeed. thanks!

1 Like

Thank You for the work of this addon.
But for my rpi3 when I use it i got

Bluetooth connection error: Failed to execute management command 'le on' (code: 17, error: Invalid Index)

I do not use the bluetooth or wifi of rpi for any other service. Maybe you have any ideas why it is giving me this error. Thanks.

I’m not sure to be honest. There are a few things you could try from this post

Or you could try a Bluetooth dongle. I haven’t written the bluepy library, just using it, but it looks like it’s development has stalled…

1 Like

I’m also getting lots of “Failed to execute management command ‘scanend’”, either code 11/3/13. And nothing else should be using bluetooth. I have a dongle in a Windows PC running Ubuntu under VirtualBox, and HA on that.

I reduced the TIME_INTERVAL to 10 so I didn’t have to wait too long for failures.

I noticed that once you get 5 errors in a row (10 seconds apart in my case - any longer implies one worked, so the 5+ resets), you get another message saying “Resetting Bluetooth”. A few seconds later I then get:

Can't init device hci0: Connection timed out (110)

Then hciconfig reports hci0 as down and I need to do a sudo hciconfig hci0 up to get it working again. Without this the addon doesn’t resume working.

This is normal. I wait for 5 fails before trying to reset the BT radio by issuing the hciconfig hci0 reset command…
Have you had a look at the link to the bluepy repo I sent above? Unfortunately I haven’t written the bluepy library, I’m just using it so not sure how to progress…

I’m not getting the ‘le on’ error. For me it does work for a while.

If I type in sudo hciconfig hci0 reset I get the “Can’t init device” error every time, and afterwards hci0 is down. It sometimes seems to come up by itself somehow (presumably this addon doing resets and some work), but sometimes doesn’t and requires a sudo hciconfig hci0 up.

So to me it looks like the problem in my case is the reset failing. There’s a 7 year old VirtualBox issue that is identical, but it’s saying it’s fixed here. It also says a reset is just a down followed by an up. I get the following results:

  • sudo hciconfig hci0 reset
    Always fails with “Can’t init device”
  • sudo hciconfig hci0 down ; sudo hciconfig hci0 up
    Also always fails
  • sudo hciconfig hci0 down
    sudo hciconfig hci0 up
    (i.e. commands entered separately) Always works

Could you therefore change the code to replace the single reset command, with one to do a down, followed a second later by another to do an up? Perhaps this would improve the reliability.

Thanks.
I’m working on an update where I’ve integrated your suggested change. Watch this space :slight_smile:

That’s great. I also noticed your code has HCI_DEV to specify the device, but the reset on line 319 is currently hardcoded to hci0.

I’ve set up a binary sensor that monitors bluetooth every minute, so I can compare your new code before and after to see if it helps.

Thanks I’ve also fixed this in the new code :slight_smile:

Hi,
I have followed the instructions on the addon.
I am using rpi with the latest home assistant.
In the logs of the addon I see only this:
2020-09-04 11:57:24 - Starting Xiaomi mi Scale…
2020-09-04 11:57:24 - Loading Config From Add-On Options…
2020-09-04 11:57:24 - Config Loaded…
2020-09-04 11:57:27 - Discovery Completed…

The sensors are not updating.
What am I doing wrong ?
Should I enabled Bluetooth on Home assistant or it’s enabled by default ?
Can someone help ?

Silly question, did you step on the scale?
Have you set your scale’s MAC address correctly?
If yes to both, please share you add-on config (redact credentials)

1 Like