Skip to content

Commit 614392f

Browse files
committed
[xiaomi_miscale] Add support for S400
Signed-off-by: zry98 <dev@zry.io>
1 parent 90fd6c3 commit 614392f

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
16.9 KB
Loading

content/components/sensor/xiaomi_miscale.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,44 @@ sensor:
2929
name: "Xiaomi Mi Scale Impedance"
3030
```
3131
32+
### MJTZC01YM
33+
34+
Xiaomi Body Composition Scale S400 can also measure impedance with 50kHz low frequency and heart rate. It must be first added in the Mijia (Xiaomi Home) app to start sending out advertisement packets containing metrics data, and to display the body fat percentage and heart rate on the scale's screen. It also supports multi-profile if configured in the app.
35+
36+
Since the messages are encrypted, you must provide a bindkey to be able to decrypt them, please see [Other encrypted devices](/components/sensor/xiaomi_ble#other-encrypted-devices).
37+
38+
{{< img src="xiaomi_miscale_s400.jpg" alt="Xiaomi MiScale S400" width="30.0%" class="align-center" >}}
39+
40+
```yaml
41+
sensor:
42+
- platform: xiaomi_miscale
43+
mac_address: XX:XX:XX:XX:XX:XX
44+
bindkey: 0728974d657a4b60964c1b1677f35f7c
45+
weight:
46+
name: "Xiaomi Mi Scale Weight"
47+
accuracy_decimals: 1
48+
# for pounds
49+
# filters:
50+
# - multiply: 2.20462
51+
# unit_of_measurement: "lb"
52+
heart_rate:
53+
name: "Xiaomi Mi Scale Heart Rate"
54+
impedance:
55+
name: "Xiaomi Mi Scale Impedance High"
56+
impedance_low:
57+
name: "Xiaomi Mi Scale Impedance Low"
58+
timestamp:
59+
name: "Xiaomi Mi Scale Timestamp"
60+
profile_id:
61+
name: "Xiaomi Mi Scale Profile ID"
62+
allowed_profile_ids:
63+
- 1
64+
```
65+
3266
## Configuration variables
3367
3468
- **mac_address** (**Required**, MAC Address): The MAC address of the scale.
69+
- **bindkey** (*Optional*, string, 32 characters, case insensitive): The key to decrypt the BLE advertisements messages. **Only required for S400**.
3570
- **weight** (*Optional*): The information for the weight sensor.
3671
3772
- All options from [Sensor](/components/sensor).
@@ -40,10 +75,28 @@ sensor:
4075
4176
- All options from [Sensor](/components/sensor).
4277
78+
- **impedance_low** (*Optional*): The information for the low frequency impedance sensor. **Only available on S400**
79+
80+
- All options from :ref:`Sensor <config-sensor>`.
81+
4382
- **clear_impedance** (*Optional*): Clear the impedance information if a weight reading without impedance is received. Defaults to `false`. **Only available on MiScale2**
4483

4584
Useful in the example below if a person steps onto the scale without waiting for the complete measurement. Without setting the flag the impedance reading of the measurement before will be used for the currently measured person.
4685

86+
- **heart_rate** (*Optional*): The information for the heart rate sensor. **Only available on S400**
87+
88+
- All options from :ref:`Sensor <config-sensor>`.
89+
90+
- **timestamp** (*Optional*): The information for the timestamp sensor, not recommended to use as the built-in RTC drifts quickly without constant syncing with the app. **Only available on S400**
91+
92+
- All options from :ref:`Sensor <config-sensor>`.
93+
94+
- **profile_id** (*Optional*): The information for the profile ID sensor. **Only available on S400**
95+
96+
- All options from :ref:`Sensor <config-sensor>`.
97+
98+
- **allowed_profile_ids** (*Optional*, list of uint8): A list of profile ID to be allowed to publish metric states. Any ID (``any``) will be allowed if this parameter is omitted. **Only available on S400**
99+
47100
### Configuration example with multiple users
48101

49102
You have to replace the numbers in the lambdas to determine your weight which is between X weight and X weight.
@@ -100,6 +153,59 @@ sensor:
100153
accuracy_decimals: 0
101154
```
102155

156+
For S400, if you have configured multiple profiles in the Mijia (Xiaomi Home) app:
157+
158+
```yaml
159+
sensor:
160+
- platform: xiaomi_miscale
161+
mac_address: XX:XX:XX:XX:XX:XX
162+
bindkey: 0728974d657a4b60964c1b1677f35f7c
163+
weight:
164+
name: "Xiaomi Mi Scale Weight"
165+
id: weight_miscale
166+
impedance:
167+
name: "Xiaomi Mi Scale Impedance High"
168+
id: impedance_miscale
169+
impedance_low:
170+
name: "Xiaomi Mi Scale Impedance Low"
171+
id: impedance_low_miscale
172+
heart_rate:
173+
name: "Xiaomi Mi Scale Heart Rate"
174+
id: heart_rate_miscale
175+
profile_id:
176+
name: "Xiaomi Mi Scale Impedance"
177+
on_value:
178+
then:
179+
- lambda: |-
180+
float weight = id(weight_miscale).state;
181+
float impedance = id(impedance_miscale).state;
182+
float impedance_low = id(impedance_low_miscale).state;
183+
uint8_t heart_rate = id(heart_rate_miscale).state;
184+
185+
switch (int(x)) {
186+
case 1:
187+
if (weight)
188+
id(weight_user1).publish_state(weight);
189+
if (impedance)
190+
id(impedance_user1).publish_state(impedance);
191+
if (impedance_low)
192+
id(impedance_low_user1).publish_state(impedance_low);
193+
if (heart_rate)
194+
id(heart_rate_user1).publish_state(heart_rate);
195+
return;
196+
case 2:
197+
if (weight)
198+
id(weight_user2).publish_state(weight);
199+
if (impedance)
200+
id(impedance_user2).publish_state(impedance);
201+
if (impedance_low)
202+
id(impedance_low_user2).publish_state(impedance_low);
203+
if (heart_rate)
204+
id(heart_rate_user2).publish_state(heart_rate);
205+
return;
206+
}
207+
```
208+
103209
## See Also
104210

105211
- {{< docref "/components/esp32_ble_tracker" >}}

0 commit comments

Comments
 (0)