Apache License 2.0

项目介绍

dckiller51/bodymiscale 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Apache License 2.0 许可证,目前获得 350 个 Star、52 次 Fork。

仓库全名
dckiller51/bodymiscale
开源许可证
Apache License 2.0
Star 数
350
Fork 数
52
未关闭 Issue
6

README 摘要

Bodymiscale Track your body composition closely with Bodymiscale With this Home Assistant integration, track your body composition closely using data from your weight sensor. You will get detailed information for accurate tracking. How it works BodyMiScale calculates advanced body composition metrics based on your scale's data (Weight and/or Impedance). Unlike simple calculators, it offers four distinct calculation…

完整内容见 GitHub 原始 README 或本页 。

常见问题

bodymiscale 用什么语言开发?

主要使用 Python 编写,采用 Apache License 2.0 许可证,目前有 350 个 Star。

bodymiscale 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 bodymiscale 的源码?

可以直接克隆仓库:git clone https://github.com/dckiller51/bodymiscale.git,默认分支为 main;安装与运行步骤见仓库 README。

bodymiscale 最近还在维护吗?

仓库最近一次更新为 20 小时前,当前有 6 个未关闭 Issue;Star 数为 350,可作为社区活跃度的参考。

关于

Custom_components Body Metrics for Xiaomi Miscale 1 and 2 (esphome or BLE monitor for Homeassistant)

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
461
价值分
225
活跃状态
活跃

语言占比

Python
Shell

Release

README

Bodymiscale

GH-release GH-downloads GH-last-commit GH-code-size hacs_badge Ko-fi

Track your body composition closely with Bodymiscale

With this Home Assistant integration, track your body composition closely using data from your weight sensor. You will get detailed information for accurate tracking.

How it works

BodyMiScale calculates advanced body composition metrics based on your scale’s data (Weight and/or Impedance). Unlike simple calculators, it offers four distinct calculation engines tailored to your hardware and preferences:

  • Xiaomi Mode: Faithful to the original 2017 algorithms for consistency with legacy apps (Zepp Life/Mi Fit).
  • Science Mode: Uses international health standards like Schofield (WHO) for BMR and Pace & Rathbun for body water.
  • S400 Mode: A clinical-grade dual-frequency engine (50/250 kHz) utilizing Deurenberg and Janssen models for precise compartmental analysis.
  • Xiaomi Home Mode (S400): The scale’s own firmware formulas, giving the same values as the Xiaomi Home app.

Here’s a breakdown of the process:

  1. Data Input: Bodymiscale relies on data provided by your configured weight sensor (Weight and optionally Impedance). This can be a sensor or an input_number entity.

  2. Smart Calculation Engine: Depending on your configuration, Bodymiscale applies one of four models:

    • Xiaomi Mode: Uses the original 2017 algorithms for consistency with Zepp Life.
    • Science Mode: Uses international standards like Schofield (WHO) and Pace (0.73).
    • S400 Mode: Automatically activated for dual-frequency data, using Deurenberg and Janssen models.
    • Xiaomi Home Mode (S400): Optional for dual-frequency data, using the S400 firmware formulas.
  3. Validation & Constraints: The engine checks for physiological consistency (e.g., ensuring water doesn’t exceed 73% in Science/S400 modes) and filters out aberrant values.

  4. Output: The calculated metrics are generated as new sensor entities in Home Assistant. These are ready to use in your dashboards, automations, or with the dedicated Lovelace Card.

Key Considerations:

  • Accuracy: The accuracy of the calculated metrics depends heavily on the accuracy of your weight and (if used) impedance measurements. Ensure your sensors are calibrated and providing reliable data.
  • No External Services: Bodymiscale performs all calculations locally within your Home Assistant instance. No data is sent to external services or the internet.

Example:

Let’s say you’ve configured a weight sensor called sensor.my_weight. When you add the Bodymiscale integration, it will:

  1. Read the current value of sensor.my_weight.
  2. Use this value (along with other information like age and gender you provided during configuration) to calculate your BMI, BMR, etc.
  3. Create new sensors like sensor.myname_bmi, sensor.myname_bmr, etc., containing these calculated values.

Prerequisites

Before installing Bodymiscale, ensure you have the following:

  1. A weight sensor in Home Assistant: There is no relationship between Bodymiscale and a specific connected scale. Bodymiscale works with any weight sensor integrated into Home Assistant.

    New in v2026.5.x: You can now point Bodymiscale directly at your scale’s native weight and impedance sensors — no per-user dedicated sensors required. Bodymiscale handles user identification automatically through one of the methods described in the Configuration section (interactive notification, weight range, nearest current weight, or profile ID).

    If you prefer the traditional approach or need data persistence across restarts, an input_number entity remains a robust alternative: its value survives a Home Assistant restart, ensuring Bodymiscale always initialises with a valid weight.

  2. Home Assistant installed.

(Optional) Impedance sensor:

If you plan to use an impedance sensor for advanced metrics (lean body mass, body fat mass, etc.), make sure an impedance sensor is available in Home Assistant. Since v2026.5.x, the scale’s own impedance sensor can be shared across profiles — Bodymiscale assigns the measurement to the correct user automatically.

(Optional) Last weigh-in sensor:

If you plan to integrate your own last weigh-in sensor, make sure a dedicated sensor is properly configured in Home Assistant.

(Optional) Stabilized sensor:

If your scale exposes a stabilization signal (e.g. Xiaomi S400 via ESPHome or xiaomi_ble), you can configure it here. When this sensor turns ON, Bodymiscale fires the recalculation immediately — bypassing the 5-second debounce window. This ensures instantaneous results regardless of whether the weight or impedance values have changed since the last measurement.

With the interactive push notification identification method, the stabilized sensor also decides when the notification is sent: only when it turns from OFF to ON. Many scale integrations (e.g. xiaomi_ble) re-publish the last weight on every Bluetooth advertisement, including idle packets after a weighing and periodic rebroadcasts. Without a stabilized sensor, these rewrites can trigger extra notifications once the previous one has expired. If your scale exposes a stabilized sensor, configuring it is strongly recommended with the notification method.

The stabilized sensor also drives the last measurement time: when configured, it is only updated when the sensor turns from OFF to ON for a weight accepted by the profile, i.e. once per real weighing. Re-published weights, Bluetooth rebroadcasts and Home Assistant restarts no longer move it. Without a stabilized sensor, every new weight reading (even an identical one) updates it.

Generated data

Bodymiscale calculates the following metrics. Note that some advanced parameters require an impedance sensor, and clinical-grade multi-compartment metrics are exclusive to dual-frequency hardware (e.g., Xiaomi S400).

Data Description Sensor / Mode Required
Weight Measured weight Weight
Height User height Config
Age User age Config
BMI Body Mass Index (Standard) Weight
Basal Metabolism (BMR) Calories burned at rest (Schofield/Katch-McArdle) Weight / LBM
Visceral Fat Fat around organs (Zepp Life / S400 Corrected) Weight / ECW Ratio
Ideal Weight Recommended weight based on height/age Config
BMI Category Underweight to Obesity classification Weight
Lean Body Mass (LBM) Body mass without fat Impedance
Body Fat Mass Total body fat mass Impedance
Water (TBW) Total Body Water percentage Impedance
Bone Mass Bone mineral content estimation Impedance
Muscle Mass Total muscle mass (including organs) Impedance
Protein Percentage of protein in the body Impedance
ECW Extracellular Water (L) Dual-frequency (S400)
ICW Intracellular Water (L) Dual-frequency (S400)
ECW/TBW Ratio Hydration & Inflammation status Dual-frequency (S400)
BCM Body Cell Mass (Active Tissue) Dual-frequency (S400)
Skeletal Muscle Actual SMM (validated via MRI) Dual-frequency (S400)

ℹ️ Dual-frequency metrics: These require a scale capable of measuring impedance at multiple frequencies (50 kHz and 250 kHz). They offer a deeper look into your cellular health and hydration levels.

Calculation Methods

Bodymiscale allows you to choose between four calculation levels. The formulas used depend on your hardware and the selected calculation mode.

1. Xiaomi (Legacy 2017)

The original algorithm based on the 2017 Mi Fit ecosystem (reverse-engineered).

  • With Impedance: Calculates full body composition based on original Xiaomi regression formulas.
  • Best for: Maintaining 1:1 consistency with historical Mi Scale, Zepp Life, or Mi Fit data.

2. Scientific (New in v2026.4.0)

Modern physiological equations for higher precision, recommended for active profiles.

A. Without Impedance (Weight only)

Uses standardized anthropometric equations:

  • BMR (Basal Metabolic Rate): Uses the Schofield Equation (official WHO standard).
  • BMI & Ideal Weight: Calculated using the Devine Formula, adjusted for modern height/weight ratios.
B. With Impedance (Single-frequency)

Switches to advanced bioelectrical impedance analysis (BIA) models:

  • Lean Body Mass (LBM): Uses clinically validated equations to calculate non-fat tissue, with a sex-specific correction for females (factor 0.84) to account for lower lean mass at identical height/weight/impedance.
  • Water & Protein: Derived from LBM using standardized physiological constants (Pace 73% for hydration and Wang 19.5% for proteins).

3. S400 (Dual-frequency)

Exclusive to dual-frequency hardware capable of measuring impedance at 50 kHz and 250 kHz.

  • Advanced BIA Models: Implements a hardware-calibrated baseline for LBM, with sexual dimorphism correction, combined with clinical models like Deurenberg (1995) for multi-frequency water analysis, and Janssen (2000) for skeletal muscle.
  • BMR (Basal Metabolic Rate): Uses the Katch-McArdle equation (370 + 21.6 × LBM), based on the measured lean body mass. The Schofield Equation (WHO standard) is used as a fallback when no lean body mass is available.
  • Visceral Fat: Standard Zepp Life base estimate.
  • Exclusive Metrics: Unlocks 5 clinical metrics: Extracellular Water (ECW), Intracellular Water (ICW), ECW/TBW Ratio, Body Cell Mass (BCM), and MRI-validated Skeletal Muscle Mass (SMM).

4. Xiaomi Home (S400 firmware)

Optional for dual-frequency hardware: select Xiaomi — Xiaomi Home (S400 only) as the calculation mode.

  • Same values as the Xiaomi Home app: Body fat, lean mass, muscle, water, bone, protein, skeletal muscle, visceral fat, BMR and metabolic age (body age) use the formulas of the S400 firmware, reverse-engineered by @RX14 and checked against the original firmware running in an emulator (#474).
  • Validated on real weighings: On 10 S400 weighings reported with their Xiaomi Home values, 4 match the app exactly on every metric. Across all 10, the mean gap is 0.1 point on body fat and 2.5 kcal on BMR.
  • Other metrics: ECW, ICW, ECW/TBW ratio and BCM keep the S400 scientific formulas, computed from the Xiaomi Home body fat and lean mass.
  • Default unchanged: Existing S400 profiles keep the S400 scientific formulas (shown as Scientific). Switch in the integration options if you prefer the Xiaomi Home values.

💡 Deep Dive: For a full breakdown of the clinical formulas and scientific references (Sun, Janssen, Deurenberg, Wang, etc.), see the Advanced Metrics Documentation.

Note: The results of these modes will differ. Scientific and S400 modes are recommended for users looking for clinical-grade estimations, while Xiaomi Legacy is best for those tracking progress against years of historical scale data.

Installation

Via HACS

  1. Open HACS in Home Assistant.
  2. Go to the “Integrations” tab.
  3. Search for “Bodymiscale”.
  4. Click “Install”.

Manual

  1. Download the latest version archive from the releases page.
  2. Unzip the archive.
  3. Copy the entire custom_components/bodymiscale folder into your config/custom_components folder in Home Assistant. The final path should be /config/custom_components/bodymiscale.
  4. Restart Home Assistant.

Configuration

  1. Open Home Assistant and go to “Settings” -> “Devices & Services” -> “Add Integration”.
  2. Search for “Bodymiscale”.
  3. Personalize your integration:
    • First Name (or other identifier): Enter your first name or another identifier. Important: This identifier will determine the name of your Bodymiscale component in Home Assistant, as well as the names of all sensors created by it. Choose a clear and relevant name.
    • Date of Birth: Enter your date of birth in YYYY-MM-DD format.
    • Calculation Mode: Choose between Xiaomi (Legacy 2017) or Scientific. The Scientific mode (added in v2026.4.0) provides a more granular approach to body composition for specific profiles.

      S400 users: The S400 dual-frequency engine is activated automatically when you configure two impedance sensors (impedance_low + impedance_high) and select Dual-frequency S400 as the impedance_mode. Choose Scientific for its dedicated clinical formulas, or Xiaomi — Xiaomi Home (S400 only) to get the same values as the Xiaomi Home app. Xiaomi — Zepp Life is for single-frequency scales only and cannot be selected with the S400.

    • Gender: Select your gender (Male/Female).
    • User identification method (new in v2026.5.x): Choose how Bodymiscale determines which user to assign a measurement to when using the scale’s native sensors:
      • Weight range: Each user is assigned a weight interval (e.g. 60–75 kg). Bodymiscale routes the measurement automatically.
      • Nearest current weight: Bodymiscale assigns the measurement to the user whose last known weight is closest to the measured value. A configurable tolerance window (default ±5 kg) ensures the measurement is rejected if no user is close enough. An initial weight must be provided at setup so the filter is operational from the very first weighing.
      • Interactive push notification: After each weighing, a notification is sent to the chosen mobile device(s). Select several phones so anyone in the household can confirm from their own phone. The user taps their name to confirm the measurement. If a stabilized sensor is configured (recommended), the notification is sent only when it turns ON.
      • Profile ID: For recent scales (e.g. Xiaomi S400 via Xiaomi Home) that broadcast a user slot ID — Bodymiscale matches it directly with no extra step.
      • None — manual assignment: No automatic identification. Use this if each person still has their own dedicated sensors.
  4. Select your weight sensor: Choose the existing weight sensor in Home Assistant (e.g., a sensor, or an input_number). Since v2026.5.x, you can select the scale’s shared native sensor directly. If you prefer data persistence across restarts, an input_number entity is still a solid choice.
  5. Impedance sensor (optional): If you have an impedance sensor, select it here. Since v2026.5.x, the scale’s own sensor can be shared across profiles. This sensor is required to calculate advanced metrics (lean body mass, body fat mass, etc.).
  6. Stabilized sensor (optional): If your scale exposes a stabilization binary sensor (e.g. Xiaomi S400 via ESPHome or xiaomi_ble), select it here. When it turns ON, Bodymiscale recalculates immediately without waiting for the debounce window. Particularly useful for scales where weight or impedance may not change between two consecutive measurements. With the interactive notification method, it also ensures a notification is sent only once per real weighing, and it keeps the last measurement time accurate.
  7. Click “Save”.

Explanation of choices:

  • First Name/Identifier: This field is important because it allows you to personalise the integration and avoid conflicts if multiple people use Bodymiscale in your home. The name you choose will be used to name the entities created by the integration (e.g., sensor.firstname_weight, sensor.firstname_bmi, etc.).
  • Date of Birth and Gender: This information is needed to calculate some metrics, such as basal metabolism.
  • User identification method: Since v2026.5.x, Bodymiscale can share the scale’s native sensors across multiple profiles and route each measurement to the right user automatically — no per-user dedicated sensors needed. The nearest_weight method is a good fit for households where each person’s weight is sufficiently distinct and stable.

Tips:

  • If you do not have an impedance sensor, some metrics will not be available. You can still use Bodymiscale to get basic information (weight, BMI, etc.).
  • If you are migrating from a setup with per-user dedicated sensors, you can keep your existing input_number entities and select None — manual assignment as the identification method to preserve your current workflow.

FAQ

  • Why are some values missing? You must have an impedance sensor configured for Bodymiscale to calculate metrics like Lean Body Mass, Body Fat Mass, and advanced S400 data.
  • How accurate is the data? Bodymiscale uses peer-reviewed scientific formulas (Scientific/S400 modes) or original Xiaomi constants (Legacy). However, accuracy depends heavily on your scale’s sensors and consistent measurement conditions.

Data Persistence & Multi-user Management

Since v2026.5.x, multi-user management no longer requires per-user dedicated sensors. Bodymiscale assigns measurements to the correct profile using the identification method configured for each user (weight range, nearest current weight, interactive notification, or profile ID).

For detailed configuration examples, please refer to the example_config README.

This folder includes:

  • esphome_configuration.yaml: Complete ESPHome setup for Xiaomi Mi Scales.
  • weight_impedance_update.yaml: HA configuration to generate sensors via ESPHome or BLE Monitor.
  • interactive_notification_user_selection_weight_data_update.yaml: Automation blueprint for user selection via interactive notifications.

⚠️ Medical Disclaimer

Bodymiscale is NOT a medical device.

  1. Informational Purpose Only: The metrics calculated by this integration (BMI, BMR, Body Fat, Visceral Fat, etc.) are estimations based on mathematical formulas and bioelectrical impedance analysis. They are provided for personal tracking and educational purposes only.
  2. Not Medical Advice: The data generated by Bodymiscale should not be used to diagnose, treat, or prevent any medical condition. Always seek the advice of a physician or other qualified health provider with any questions you may have regarding a medical condition.
  3. Accuracy: While Bodymiscale uses peer-reviewed scientific formulas, results may vary based on sensor quality and individual physiological differences. Do not make significant changes to your diet or exercise routine based solely on these metrics.
  4. No Liability: The author of this integration is a developer, not a medical professional. By using this integration, you acknowledge that the author is not responsible for any health-related decisions made based on the provided data.

☕ Support

If you find Bodymiscale useful and want to support its development, you can buy me a coffee!

Ko-fi

评论

暂无评论