I’m not sure which version it is, I think it may be V2.
It’s this one anyway and it works well
Thanks guys.
Do you know if there is a docker image for the BLE MQTT integration?
sorry I don’t know any, though above script has everything
If MQTT integration doesn’t work, you can try a bash command instead.
You’d basically need to remove:
- replace
import paho.mqtt.client as mqtt
withimport subprocess
- remove the mqtt bits (
def __init__(self):
anddef _start_client(self):
) - replace
self.mqtt_client.publish(prefix, weight, qos=1, retain=True)
with
MQTT_Command = ["mosquitto_pub", "-h", MQTT_HOST, "-p", MQTT_PORT, "-u", MQTT_USER, "-P", MQTT_PASSWORD, "-t", prefix, "-r", "-m", weight, "-q", "1"]
ps = subprocess.Popen(MQTT_Command)
- replace
self.mqtt_client.publish(prefix, mitdatetime, qos=1, retain=True)
with
MQTT_Command = ["mosquitto_pub", "-h", MQTT_HOST, "-p", MQTT_PORT, "-u", MQTT_USER, "-P", MQTT_PASSWORD, "-t", prefix, "-r", "-m", mitdatetime, "-q", "1"]
ps = subprocess.Popen(MQTT_Command)
- replace
self.mqtt_client.publish(prefix, miimpedance, qos=1, retain=True)
with
MQTT_Command = ["mosquitto_pub", "-h", MQTT_HOST, "-p", MQTT_PORT, "-u", MQTT_USER, "-P", MQTT_PASSWORD, "-t", prefix, "-r", "-m", miimpedance, "-q", "1"]
ps = subprocess.Popen(MQTT_Command)
So let me get this right:
- you connect your mi scale to your raspberry via bluetooth permanently
- the raspberry is running your script 24/7 as a cron job in the background.
- the data obtained from the scale is transferred to raspberry via bluetooth and to mqtt via your script.
- the mqtt data can then be linked to HA.
Is that how it works?
I have a bluetooth dongle on my HA server. The scale seems to hold the last weight info for about 5 min so I have a cron job that runs every 5 min and calls the script.
The script connects to the scale and gets the latest reading and then sends the data to HA over MQTT
You first need to retrieve the MAC address of your scale: sudo hcitool lescan
(step on the scale just before to wake it up) and enter it here instead of REDACTED: MISCALE_MAC = 'REDACTED'
Right I see thanks for that.
Other than weight what else can the script record from the scale?
it returns a data that appears to be impedance but no idea how Xiaomi uses that data to compute other measures so for now I compute BMI in HA
Oh right I see…
I was hoping there would be a way to get body fat percentage etc
well if you manage to find the formula to retrieve it from the impedance, please let me know.
In the meantime, BMI is weight / (height * height)
where weight is in Kg and height is in m.
Hi,
I’ve got mine working with Hassio by linking the mi fit app to google fit and then getting the data using the google fit custom component.
It’s a workaround, but it works and updates fairly quickly.
Thanks!
Does that give you body fat percentage too ?
My scale only gives out weight data so I’m not sure, but I don’t think so.
I got this python script from the Openhab comunity that includes the xiaomi data, from version 2 of the scale:
i’ve just started using HASS, is there a way to execute a python script easily on HASSIO?
Hi,
i tried using the miscale node in node-red on my hassos running on tinker board. but am getting the following error
Error: Cannot find module 'bluetooth-hci-socket
any one having gone through this? or knows a solution?
i couldnt find a node to install matching this. and dont know how to install it externally in HASSIO.
@lolouk44 is this (script) utilized for just 1 person using the scale? or it can record more than 1 person?
Hi @bachoo786
The same script is used for 3 persons. Weights are different enough that I know which person it is based on the weight alone
Here is the script I use
https://github.com/lolouk44/xiaomi_mi_scale/blob/master/Xiaomi_Scale.py
This script is for version 1 of the script right?
Do you cron run this at different intervals or how do you handle the readings?
Hi @Brian_Mollegaard_Ped
Not sure what you mean with
The script it triggered via a cron job indeed that runs every 5 min. This is often enough that the scale doesn’t go into sleep mode, yet not that often that it drains the battery, which I’m really impressed with:
I’ve had the scale for about a year now. I weigh myself once a day and I’ve not had the replace the batteries yet.
Compared to my previous Salter non smart scale that drained its battery within 4 month with no use, it’s quite a change…
Hi @lolouk44
There is at least two versions of the scale, v. 1 measures only weight while v.2 adds fat %, water % and other measurements. I have been thinking about putting a xiaomi vibration sensor on the scale, instead but it seem a bit overkill.
The script works with both v1 and v2 scales. With v2 it sends the body impedance, though I’ve not yet figured out the formula that xiaomi uses to calculate other body measurements.
I personally use this one to figure out the bmi
https://www.organicnutrition.co.uk/images/body-mass-index-formula.jpg