10void XiaomiMiscale::dump_config() {
11 ESP_LOGCONFIG(TAG,
"Xiaomi Miscale");
12 LOG_SENSOR(
" ",
"Weight", this->weight_sensor_);
13 LOG_SENSOR(
" ",
"Impedance", this->impedance_sensor_);
18 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
21 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
23 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", addr_str);
39 if (this->impedance_sensor_ !=
nullptr) {
40 if (res->version == 1) {
41 ESP_LOGW(TAG,
"Impedance is only supported on version 2. Your scale was identified as version 1.");
43 if (res->impedance.has_value()) {
44 this->impedance_sensor_->publish_state(*res->impedance);
47 this->impedance_sensor_->publish_state(NAN);
64 char uuid_buf[ble_device_base::UUID_STR_LEN];
66 "parse_header(): Couldn't identify scale version or data size was not correct. UUID: %s, data_size: %d",
92 const uint8_t *data =
message.data();
96 if (data[0] == 0x22 || data[0] == 0xa2) {
97 result.
weight = weight * 0.01f / 2.0f;
98 }
else if (data[0] == 0x12 || data[0] == 0xb2) {
99 result.
weight = weight * 0.01f * 0.6f;
100 }
else if (data[0] == 0x03 || data[0] == 0xb3) {
101 result.
weight = weight * 0.01f * 0.453592f;
118 const uint8_t *data =
message.data();
120 bool has_impedance = ((data[1] & (1 << 1)) != 0);
121 bool is_stabilized = ((data[1] & (1 << 5)) != 0);
122 bool load_removed = ((data[1] & (1 << 7)) != 0);
124 if (!is_stabilized || load_removed) {
130 if (data[0] == 0x02) {
131 result.
weight = weight * 0.01f / 2.0f;
132 }
else if (data[0] == 0x03) {
133 result.
weight = weight * 0.01f * 0.453592f;
141 if (impedance == 0 || impedance >= 3000) {
150 if (!result.has_value()) {
151 ESP_LOGVV(TAG,
"report_results(): no results available.");
155 ESP_LOGD(TAG,
"Got Xiaomi Miscale v%d (%s):", result->version,
address);
157 if (result->weight.has_value()) {
158 ESP_LOGD(TAG,
" Weight: %.2fkg", *result->weight);
160 if (result->impedance.has_value()) {
161 ESP_LOGD(TAG,
" Impedance: %.0fohm", *result->impedance);
ESPDEPRECATED("Use address_str_to() instead. Removed in 2027.2.0.", "2026.8.0") std const char * address_str_to(char *buf) const
Return MAC as "XX:XX:XX:XX:XX:XX" string.
uint64_t address_uint64() const
Return MAC as packed uint64 (byte 0 in LSB — matches esp32's address_uint64).
const std::vector< ServiceData > & get_service_datas() const
static ESPBTUUID from_uint16(uint16_t uuid)
const char * to_str(char *buf) const
Write "0xABCD" / "0xABCDEF01" / the dashed 128-bit form, or "None" for an unset UUID,...
bool parse_message_v1_(const std::vector< uint8_t > &message, ParseResult &result)
bool parse_message_(const std::vector< uint8_t > &message, ParseResult &result)
optional< ParseResult > parse_header_(const ble_device_base::ServiceData &service_data)
bool report_results_(const optional< ParseResult > &result, const char *address)
bool parse_message_v2_(const std::vector< uint8_t > &message, ParseResult &result)
const LogString * message
ESPHOME_LOG_TAG(TAG, "xiaomi_miscale")
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
void publish_optional(E *entity, const optional< V > &value)
Publish value to entity when the entity is configured and the value is set.
optional< float > impedance