我这里有个4电极算体脂的:
template:
- sensor:
- name: "Real Body Fat"
unique_id: real_body_fat_percentage
unit_of_measurement: "%"
icon: mdi:human
state: >
{% set weight = states('sensor.weight') | float(0) %}
{% set impedance = states('sensor.impedance') | float(0) %}
{# === 请在此处填入你的个人信息 === #}
{% set height = 175 %} {# 身高 cm #}
{% set age = 30 %} {# 年龄 #}
{% set sex = 'male' %} {# 性别: male 或 female #}
{# =============================== #}
{% if weight > 10 and impedance > 0 %}
{# 1. 计算 LBM (瘦体重/去脂体重) - 通用公式 #}
{# LBM = coefficient * height^2 / impedance + ... #}
{# 这里使用针对亚洲人体质优化的通用公式 #}
{% set h2 = height * height %}
{% if sex == 'female' %}
{% set lbm = (0.252 * h2 / impedance) + (0.473 * weight) + (0.13 * age) - 10.5 %}
{% else %}
{% set lbm = (0.252 * h2 / impedance) + (0.473 * weight) + (0.13 * age) - 13.5 %}
{% endif %}
{# 2. 计算体脂率: (总重 - 瘦体重) / 总重 #}
{% set fat_rate = (1 - (lbm / weight)) * 100 %}
{# 3. 安全限制,防止出现负数或离谱数值 #}
{% if fat_rate < 5 %}
5.0
{% elif fat_rate > 60 %}
60.0
{% else %}
{{ fat_rate | round(1) }}
{% endif %}
{% else %}
0
{% endif %}
- name: "BMI"
unique_id: body_mass_index
unit_of_measurement: "kg/m²"
icon: mdi:calculator
state: >
{% set weight = states('sensor.weight') | float(0) %}
{% set height = 175 / 100.0 %} {# 填入你的身高(米) #}
{% if weight > 0 %}
{{ (weight / (height * height)) | round(1) }}
{% else %}
0
{% endif %}
|