Integrating Xiaomi Mi Scale

Can you share your code?
I have setup users based on weight. So to show up under lolo (you probably should change that to your own name by the way) you need to weigh more than 72kg, else it’ll probably show up under “div”

No not natively. You need root privileges to run the script so it won’t work worth hass.io directly. If you have ssh access you could always call the script with a cron job though which should do the trick

luckily (or not) my weigh is more than 72. and i did not change the name or any other variables in those lines.
probably because im using this Yunmai Mini 2 (https://www.amazon.com/Xiaomi-Yunmai-Digital-Bluetooth-Weight/dp/B076WRQ7H9 )

should that be an issue?

2019-05-25 18:50:50,850 ERROR bt-mqtt-gw logger.py:48:log_exception - Retrieving the weight from miscale device xx:xx:xx:xx:xx:xx timed out after 5 seconds
Traceback (most recent call last):
  File "./gateway.py", line 49, in <module>
    mqtt.publish(_WORKERS_QUEUE.get(timeout=10).execute())
  File "/home/pi/bt-mqtt-gateway/workers_manager.py", line 34, in execute
    messages = self._callback(*self._args)
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 18, in status_update
    return [MqttMessage(topic=self.format_topic('weight/kg'), payload=self._get_weight())]
  File "/home/pi/bt-mqtt-gateway/workers/miscale.py", line 29, in _get_weight
    time.sleep(1)
  File "/usr/local/lib/python3.5/dist-packages/interruptingcow/__init__.py", line 74, in handler
    raise exception

Yes it’s most likely because this is a different scale, sorry

1 Like

thank you. maybe one day :slight_smile:

I won’t have time to look into this for the next month or so, I’ll try and give your some instructions to see if the data from the scale has the same format as mine

I have SSH Server on my Hass.io.
I don’t have Linux experience (all other computers on the network are Windows 10).
How can call the script ?

virtual machine or evren windows bash

ill be happy to try. thanks

1 Like

Basically save the file on your pi somewhere that you can obviously remember. Then type sudo crontab -e
And add a new line with the text I provided on my github:
*/5 * * * * python3 /path-to-script/Xiaomi_Scale.py
Obviously replace “path-to-script” with the actual path…

2 Likes

Hello. Congratulations on the tutorials and information you have provided. Unfortunately in my case, I still can’t read data from miscale. I have v2 (MIBCS). How can I read the complete information from it? Most of the time the connection is made but it does not give errors or information. Especially after I measured my weight, report it’s sleeping. (I’m not that heavy :slight_smile:)
I have tried different python scripts, JS, reversedmiscale… and can’t get information from it.
Can you help me?

I’m away for a few weeks but can re-engage once I’m back. I wonder if Xiaomi updated their scale or protocols. I can help your once I’m back (unless someone steps in :wink: )

@lolouk44 I’m currently working on adding this as a component directly into Home Assistant. Is there any reason why you chose to use an external script to receive the data from the scale? Maybe I didn’t think this through and there’s a reason why this is not possible in Home Assistant directly.

Can you provide some insights? Thanks!

I was also thinking or making this a component but since it requires root privileges I stopped. Most users do no want to run ha with root privileges for safety reasons (and rightly so).

I am struggling to get this script to run looks like something to do with mqtt client

pi@raspberrypi:~ $ sudo python3 Xiaomi_Scale.py
Traceback (most recent call last):
  File "Xiaomi_Scale.py", line 162, in <module>
    main()
  File "Xiaomi_Scale.py", line 157, in main
    scanner = btle.Scanner().withDelegate(ScanProcessor())
  File "Xiaomi_Scale.py", line 49, in __init__
    self._start_client()
  File "Xiaomi_Scale.py", line 111, in _start_client
    self.mqtt_client.connect(MQTT_HOST, MQTT_PORT, MQTT_TIMEOUT)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 839, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 962, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.5/socket.py", line 694, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.5/socket.py", line 733, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

Hi. Sorry tried to look into that but don’t maintain paho in any way so got no idea how to help you I’m afraid.

See if you can create a simple script with paho to send a message?

Have you tried to reinstall mqtt?

Updated the script on my github a while ago following an issue raised. Can you try and let me know if it works?

Hi @pickeld, are you still up for this? I’ll have some time on Friday

Did you change MQTT_HOST to your mqtt host?