Is there any news here? I’am also looking for a component to integrate the Mi scale.
I just bought one and will test the provided code on this topic then I will revert back
Hi,
has anybody gotten further into this? I would really like to collect the data and show it in my home assistant dashboard.
Best,
Alex
Apparently not
The whole code works, but i stuck at people check algorithm - we got only raw weights but not “person->weight” mapping. Before you can display it - you need to check which person weight it is.
I didn’t want to start home assistant as root, so I wrote a small mqtt gateway for the mi scale: https://gist.github.com/syssi/4108a54877406dc231d95514e538bde9
This is my home assistant configuration:
sensor:
- platform: mqtt
name: "miscale"
state_topic: "miscale/weight/kg"
value_template: "{{ value }}"
unit_of_measurement: "kg"
You have to change the MISCALE_MAC, MQTT_USERNAME, MQTT_PASSWORD and the MQTT_HOST. Have fun! For a successful passive bluetooth scan root privileges are required.
Can you clarify how to install and use this?
Also which model does it work with? I’ll happily by one if I can get the stats to HA
Just download the code (python script). Update L10-L15 and execute the script:
sudo python3 miscalegw.py
The output should look like this:
$ sudo python3 ./miscalegw.py
Scanning for devices...
MQTT connection returned result: Connection Accepted.
Device: 88:ff:ff:ff:ff:ff (public), -59 dBm .
Sent data to topic miscale/weight/kg: xx.x kg
The script publishs one message per execution to the mqtt host. This is the payload:
$ mosquitto_sub -v -h localhost -t '#'
miscale/weight/kg xx.x
The value/sensor can be used in home assistant with this configuration:
sensor:
- platform: mqtt
name: "miscale"
state_topic: "miscale/weight/kg"
value_template: "{{ value }}"
unit_of_measurement: "kg"
I wrote the code for the first generation of the mi scale. The command “sudo hcitool lescan” can help to find the MAC address of the device:
$ sudo hcitool lescan
LE Scan ...
50:8C:B1:3F:EF:C5 IBEACON8
C4:FF:FF:FF:FF:FF Flower care
88:FF:FF:FF:FF:FF MI_SCALE
Does it work with the following ?
did you set it up to run periodically or on demand ?
The script must be called with root permissions because of the needed bluetooth stack. I assume the mentioned component will use the homeassistant user to call the scripts. I just used a cron job:
$ crontab -l -u root
30 * * * * /usr/local/bin/miscalegw.py >/dev/null
Do you think it would be possible to combine the following 2 features and get an independent gateway to grab scale and / or plan data ?
(wishful thinking)
Why do you want to combine both applications?
The way I understand it the plant gateway is and independent tool running outside HA, querying the Xiaomi devices and sending the data to MQTT
If it can also do the job of querying the the scale - I could have a separate Pi running this and getting the data updated without caring for 2 separate tools
Since we are talking about both Xiaomi products they seem related to me…
Your understanding is correct but the bluetooth communication between the plant sensor and the scale doesn’t have anything in common. In easy words: The scale provides something like a broadcast which is captured. The plant sensor provides informations by request & response. Calling both tools successively would be the easiest solution.
I see what you mean
So if I have a dedicated rPi zero for this… I can follow install of both on the same device and have them publish to my HA mqtt ?
any additional preparations you would suggest ?
Yes. Just use both scripts on the same host. No additional preparations.
I am using rPi zero W and something is not working
Any idea what I can do about it ?
(the plantgateway is also not working - I think it’s a BT issue with the installation?)
I am on rasbian lite fresh install after update / upgrade)
pi@raspberrypi:~ $ pi@raspberrypi:~ $ sudo python3 miscalegw.py
Scanning for devices...
MQTT connection returned result: Connection Accepted.
Traceback (most recent call last):
File "miscalegw.py", line 99, in <module>
main()
File "miscalegw.py", line 96, in main
devices = scanner.scan(5)
-bash: pi@raspberrypi:~: command not found File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 679, in scan
self.start(passive=passive)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 617, in start
self._mgmtCmd("le on")
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 272, in _mgmtCmd
rsp = self._waitResp('mgmt')
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 304, in _waitResp
raise BTLEException(BTLEException.INTERNAL_ERROR, "Helper exited")
bluepy.btle.BTLEException: Helper exited
It looks like the bluetooth stack of the rPi zero W does not support some bluetooth low energy features. That’s strange.
VERY strange
on plantgateway I am also seeing a problem with this module
any suggestion how to troubleshoot ?
is this a firmware issue or software ? would another pi work maybe ?
Exception ignored in: <bound method Peripheral.__del__ of <bluepy.btle.Peripheral object at 0xb65a52f0>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 520, in __del__
self.disconnect()
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 416, in disconnect
self._writeCmd("disc\n")
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 268, in _writeCmd
self._helper.stdin.flush()
BrokenPipeError: [Errno 32] Broken pipe
I bet another BLE capable bluetooth stick or a raspberry pi 3 will do out of the box.