Integrating Xiaomi Mi Scale

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

Thanks, the MAC address was with o instead of 0 (zero).
It’s working now.
Thanks.

1 Like

Hi,
I have different devices running on my home assistant, some of them using mqtt, zigbee, bluetooth and wifi.
For some reason, I am not able to setup Xiaomi Mi Scale.
My setup is a VM running hassio, where the bluetooth is running ok.
I can see the MAC address using Bluetoothctl and connect to the device (same for example with Xiaomi mitja temperature).
In the add-on side, I always see same logs:

-------------------------------------
2020-09-05 13:14:08 - Starting Xiaomi mi Scale...
2020-09-05 13:14:08 - Loading Config From Add-On Options...
2020-09-05 13:14:08 - Config Loaded...
2020-09-05 13:15:01 - Discovery Completed...

The config used by the add-on is:

HCI_DEV: hci0
MISCALE_MAC: 'C0:FB:D9:D3:40:E4'
MQTT_PREFIX: miscale
MQTT_HOST: 127.0.0.1
MQTT_USERNAME: mqtt
MQTT_PASSWORD: mqtt
MQTT_PORT: 1883
TIME_INTERVAL: 30
MQTT_DISCOVERY: true
MQTT_DISCOVERY_PREFIX: homeassistant
USER1_GT: 50
USER1_SEX: male
USER1_NAME: Carlos
USER1_HEIGHT: 167
USER1_DOB: '1990-01-01'
USER2_LT: 30
USER2_SEX: female
USER2_NAME: Serena
USER2_HEIGHT: 95
USER2_DOB: '1990-01-01'
USER3_SEX: female
USER3_NAME: Missy
USER3_HEIGHT: 150
USER3_DOB: '1990-01-01'

I reviewed:
-The MAC–> Is ok.
-The MQTT Host–> assuming that is the server where I am running the MQTT mosquitto (same VM with a IP 192.168.0.25 and therefore 127.0.0.1)
With the addon Zigbee mosquitto broker, I use: server: ‘mqtt://core-mosquitto’
-User: mqtt and password: mqtt, I use the same as in other MQTT add-ons

With this config, home assistant creates the entity, so I can add to my lovelace but nothing happend (obviously if you see the logs)…

Any advice or help???Thanks!

How are you running the mi-scale script ? Add-on? Docker container? Manually after cloning the repo?
If the answer is either of the first 2, 127.0.0.1 won’t work you’ll need the ip address of the server running the mosquito broker. If it’s the 3rd, it may also apply since you’re in a vm…