{"id":16359449,"url":"https://github.com/zibous/ha-miscale2","last_synced_at":"2025-03-21T00:31:43.697Z","repository":{"id":151552306,"uuid":"296389987","full_name":"zibous/ha-miscale2","owner":"zibous","description":"Code to read weight measurements from Xiaomi Mi Body Composition Scale.","archived":false,"fork":false,"pushed_at":"2023-09-25T16:32:22.000Z","size":30272,"stargazers_count":37,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T19:21:21.343Z","etag":null,"topics":["fitness","home-assistant","mqtt-broker","python3","xiaomi-mi-scale","xmtzc05hm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zibous.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-17T17:00:11.000Z","updated_at":"2025-03-10T19:41:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a841f87-2f8f-4d11-9382-658a6d9822ce","html_url":"https://github.com/zibous/ha-miscale2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zibous%2Fha-miscale2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zibous%2Fha-miscale2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zibous%2Fha-miscale2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zibous%2Fha-miscale2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zibous","download_url":"https://codeload.github.com/zibous/ha-miscale2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717391,"owners_count":20498283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fitness","home-assistant","mqtt-broker","python3","xiaomi-mi-scale","xmtzc05hm"],"created_at":"2024-10-11T02:08:22.746Z","updated_at":"2025-03-21T00:31:40.276Z","avatar_url":"https://github.com/zibous.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connector for Xiaomi Mi Scale - Develop Version\n\n\n## Body Composition Scale 2 (XMTZC05HM) Data to MQTT / Influxdb\nCode to read weight measurements from Xiaomi Body Scales.\n\n\n\n![app_states](docs/app_states.png)\n\n## Prerequisites\n\nAn MQTT broker is needed as the counterpart for this daemon. Even though an MQTT-less mode is provided, it is not recommended for normal smart home automation integration. MQTT is huge help in connecting different parts of your smart home and setting up of a broker is quick and easy.\n\n- Body Composition Scale 2 (XMTZC05HM)\n\n- ESP32 (BLE SCANNER),  see  [ESP32 Application](esp32/README.md)\n\n- Raspberry or Linux computer\n\n- Python 3 (min)\n\n- MQTT broker\n\n- Libs see requirements.txt\n\n- Optional Homeassistant, see [Settings \u0026 Views Homeassistant](docs/homeassistant/README.md)\n\n- Optional influxdb, see  [Influx DB \u0026 Grafana Dashboard](docs/influxdb/README.md)\n\n  \n\n## Installation\n\nOn a modern Linux system just a few steps are needed to get the daemon working. The following example shows the installation under Debian/Raspbian below the `/opt` directory:\n\n\n```bash\n$ su -\n$ cd /opt/\n$ git clone https://github.com/zibous/ha-miscale2.git\n$ cd /opt/ha-miscale2\n$ sudo pip3 install -r requirements.txt\n\n```\n\nTo match personal needs, all operation details can be configured using the file **conf.py** The file needs to be created first:\n\n```bash\n$ cd /opt/ha-miscale2\n$ cp conf.py.dist conf.py\n\n# edit configuration settings\n$ nano conf.py\n\n$ chmod +x app.py\n$ chmod +x mqttservice.py\n$ chmod +x service.sh\n$ chmod +x service_mqtt.sh\n\n## tests\n$ python3 app.py\n$ ./app.py\n$ ./app.py \u0026\u0026 tail -f /var/log/syslog | grep MIBCS2\n\n$ python3 mqttservice.py\n$ ./mqttservice.py \u0026\u0026 tail -f /var/log/syslog | grep MIBCS2\n\n```\n\n\n\n## Application for Raspberry / Linux computer\n\nRead [Xiaomi Mi Body Composition Scale](https://www.mi.com/global/mi-body-composition-scale) data from a Raspberry Pi in Python 3.\n\n### Execution\n`python3 app.py`\n\n## MQTT service for ESP32 Devices\nA simple Python script which provides a MQTT gateway for ESP Devices, easily extensible via custom workers. Application for ESP Devices see:\n\nDetails see :  [ESP 32 Appliciaton]( esp32/README.md)\n\n\n\n## Configuration\n\nYou most probably want to execute the program **continuously in the background**. This can be done either by using the internal daemon or cron.\n\nSystemd service for  - on systemd powered systems the **recommended** option\n\n### Application Service:\n   ```bash\n   $ sudo cp /opt/ha-miscale2/service_app.template /etc/systemd/system/ha-miscale.service\n   \n   $ sudo systemctl daemon-reload\n   $ sudo systemctl start ha-miscale.service\n   $ sudo systemctl stop ha-miscale.service\n   $ sudo systemctl status ha-miscale.service\n   \n   $ sudo systemctl enable ha-miscale.service\n   ```\n\n### MQTT Service:\n   ```bash\n   $ sudo cp /opt/ha-miscale2/service_mqtt.template /etc/systemd/system/ha-miscale-mqtt.service\n   \n   $ sudo systemctl daemon-reload\n   $ sudo systemctl start ha-miscale-mqtt.service\n   $ sudo systemctl status ha-miscale-mqtt.service\n   \n   $ sudo systemctl enable ha-miscale-mqtt.service\n   ```\n\u003cbr/\u003e\n\n## MQTT Data for Homeassistant / Applications\n\nThe calculation results are saved once as a history in the data folder, published as an MQTT payload and optionally saved in the defined InfluxDB.\n\n**Sample MQTT Payload**\n\nTopic: `tele/miscale2/Peter/measured`\u003cbr\u003e\nThese data are published by the \"ESP32 Application\" and can either be processed directly in another application. In my case, this data is evaluated via the Python application and the additional data is calculated and then published (Infuxdb, Homeassistant).\n```json\n{\n\t\"user\": \"Peter\",\n\t\"sex\": \"male\",\n\t\"athletic\": true,\n\t\"age\": 64.85,\n\t\"weight\": 68.2,\n\t\"unit\": \"kg\",\n\t\"impedance\": 539,\n\t\"bmi\": 22.27,\n\t\"water\": 43.11,\n\t\"fat\": 18.4,\n\t\"timestamp\": \"2020-10-05 06:23:03\",\n\t\"version\": \"1.0.1\",\n\t\"icon\": \"mdi:scale-bathroom\",\n\t\"attribution\": \"Data provided by Peter Siebler\"\n}\n```\n\nTopic: `tele/miscale2/Peter/data` \u003cbr/\u003e\nThis data is published by the \"calc module\"\n```json\n{\n   \"measured\":70.65,\n   \"calcweight\":70.65,\n   \"unit\":\"kg\",\n   \"impedance\":485,\n   \"timestamp\":\"2020-09-18T06:34:29Z\",\n   \"scantime\":\"2020-09-18 08:34:29\",\n   \"user\":\"Peter\",\n   \"sex\":\"male\",\n   \"athletic\":true,\n   \"age\":64.8,\n   \"metabolic_age\":40.39,\n   \"bmi\":23.07,\n   \"bodytype\":\"balanced\",\n   \"weight\":70.65,\n   \"idealweight\":66.5,\n   \"lbm\":55.76,\n   \"fat\":13.14,\n   \"fattype\":\"to_gain\",\n   \"idealfat\":1.98,\n   \"visceral\":7.39,\n   \"water\":55.72,\n   \"bone\":3.64,\n   \"muscle\":52.17,\n   \"protein\":20.47,\n   \"bmr\":1222.9,\n   \"targetweight\":68.0,\n   \"icon\":\"mdi:scale-bathroom\",\n   \"attribution\":\"Data provided by Peter Siebler\"\n}\n```\n\u003cbr/\u003e\n\n\nTopic: `tele/miscale2/Peter/scores` \u003cbr/\u003e\nThis data is published by the \"calc module\"\n```json\n{\n\t\"user\": \"Peter\",\n\t\"score\": 90.0,\n\t\"deltas\": {\n\t\t\"weight\": -0.8,\n\t\t\"fat\": -0.21,\n\t\t\"water\": 0.0,\n\t\t\"muscle\": 0.0,\n\t\t\"visceral\": -0.4,\n\t\t\"protein\": 0.02\n\t},\n\t\"states\": {\n\t\t\"weight\": \"Abgenommen\",\n\t\t\"fat\": \"Abgenommen\",\n\t\t\"water\": \"Keine Ver\\u00e4nderung\",\n\t\t\"muscle\": \"Abgenommen\",\n\t\t\"protein\": \"Zugenommen\"\n\t},\n\t\"scores\": {\n\t\t\"bmi\": 0.0,\n\t\t\"fat\": 10.0,\n\t\t\"visceral\": 0.0,\n\t\t\"muscle\": 0.0,\n\t\t\"water\": 0.0,\n\t\t\"bones\": 0.0,\n\t\t\"bmr\": 0.0,\n\t\t\"protein\": 0.0\n\t},\n\t\"caloric\": {\n\t\t\"caloricmin\": 2100,\n\t\t\"caloricmax\": 2400,\n\t\t\"deficitmin\": 1677,\n\t\t\"deficitmax\": 1923\n\t},\n\t\"engergieexp\": 2491,\n\t\"macronut\": { \"protein\": 872.0, \"carbohydrates\": 1246.0, \"fat\": 374.0 },\n\t\"version\": \"1.0.1\",\n\t\"timestamp\": \"2020-10-05 06:23:03\",\n\t\"icon\": \"mdi:scale-bathroom\",\n\t\"attribution\": \"Data provided by Peter Siebler\"\n}\n\n```\n\n\u003cbr\u003e\n\u003ca href=\"https://www.buymeacoff.ee/zibous\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\n\n\n\u003cbr\u003e\n\u003chr\u003e\n \n\n# Acknowledgements:\n\n+ Thanks @lolouk44 to https://github.com/lolouk44/xiaomi_mi_scale\u003cbr\u003e\n+ Formulas to calculate the various values/measures, I've got them from https://github.com/wiecosystem/Bluetooth\n\n\n# Informations\n- https://inbodyusa.com/general/technology/\u003cbr\u003e\n- https://github.com/limhenry/web-bluetooth-mi-scale\u003cbr\u003e\n- https://www.medeia.com/dtr_bioscan_bia.htm\u003cbr\u003e\n- https://www.jstor.org/stable/41463874\u003cbr\u003e\n- https://www.wikihow.fitness/Determine-Lean-Body-Mass\u003cbr\u003e\n- https://www.omnicalculator.com/health/body-fat#how-to-calculate-body-fat\u003cbr\u003e\n- https://calculator-online.net/ideal-weight-calculator/\u003cbr\u003e\n- https://en.wikipedia.org/wiki/Body_mass_index\u003cbr\u003e\n- https://www.calculator.net/bmi-calculator.html\u003cbr\u003e\n- https://www.calculator.net/calorie-calculator.html\u003cbr\u003e\n- https://www.omnicalculator.com/health/bmr-katch-mcardle#what-is-the-katch-mcardle-calculator\u003cbr\u003e\n- https://www.omnicalculator.com/health/maintenance-calorie\u003cbr\u003e\n- https://en.wikipedia.org/wiki/Body_water\u003cbr\u003e\n- https://de.wikipedia.org/wiki/Ponderal-Index\u003cbr\u003e\n- https://en.wikipedia.org/wiki/Body_fat_percentage\u003cbr\u003e\n- https://en.wikipedia.org/wiki/Lean_body_mass\u003cbr\u003e\n- http://elsenaju.de/AMI-Rechner.html\u003cbr\u003e\n- http://elsenaju.de/Kalorien-Bedarf-Rechner.html\u003cbr\u003e\n- https://www.calculator.net/lean-body-mass-calculator.html\u003cbr\u003e\n- http://www.dev.egofit.de/biadata-org/\u003cbr\u003e\n- https://github.com/zewelor/bt-mqtt-gateway\u003cbr\u003e\n- https://www.mi.com/global/mi-body-composition-scale\u003cbr\u003e\n- https://dev.to/henrylim96/reading-xiaomi-mi-scale-data-with-web-bluetooth-scanning-api-1mb9\u003cbr\u003e\n- https://github.com/Wingjam/ReverseMiScale/blob/master/miScale.py\u003cbr\u003e\n- https://tanita.de/hilfe-und-anleitungen/richtige-interpretation-ihrer-messwerte/\u003cbr\u003e\n- https://github.com/oliexdev/openScale\u003cbr\u003e\n- https://support.withings.com/hc/en-us/articles/218500778-Body-What-are-the-normal-ranges-for-body-composition-\u003cbr\u003e\n- https://googlechrome.github.io/samples/web-bluetooth/scan.html\u003cbr\u003e\n- https://github.com/IanHarvey/bluepy/blob/master/docs/scanner.rst\u003cbr\u003e\n- https://passionhome.sg/xiaomi-mi-body-composition-scale-v2-tips-and-instructions/ \u003cbr\u003e\n- https://github.com/rando-calrissian/esp32_xiaomi_mi_2_hass\u003cbr\u003e\n- https://github.com/limhenry/web-bluetooth-mi-scale\u003cbr\u003e\n\n# Omron, Medisana, Xiaomi\n- https://www.amazon.de/Omron-HBF-511B-E-Ganzkörperanalyse-Waage-BF511-blau/dp/B0033AGBW0\u003cbr\u003e\n- https://www.amazon.de/Medisana-TargetScale-3-0-Waage/dp/B01MZ1VBWZ/\u003cbr\u003e\n- https://www.amazon.de/Xiaomi-Smart-Bluetooth-Monitor-Display/dp/B07WNM9B57/\u003cbr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzibous%2Fha-miscale2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzibous%2Fha-miscale2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzibous%2Fha-miscale2/lists"}