Hi there,
I’m using the excellent bodymiscale custom component to capture two weights from my Xiaomi scales but the way the code has been designed, the weight value is not persistent and if ESPHome is upgraded (which happens quite frequently lately), the weight value is lost and the entity returns a value of unknown
.
I’m wondering if someone knows Lambda well enough to add a mqtt.publish Action that would publish the read weight to a defined topic with retain enabled as I think that would be a good workaround? Current code I’m using below.
sensor:
- platform: xiaomi_miscale
mac_address: '12:34:56:78'
weight:
name: "Xiaomi Mi Scale Weight"
id: weight_miscale
on_value:
then:
- lambda: |-
if (id(weight_miscale).state >= 67 && id(weight_miscale).state <= 80) {
return id(weight_user1).publish_state(x);}
else if (id(weight_miscale).state >= 45 && id(weight_miscale).state <= 65) {
return id(weight_user2).publish_state(x);}
- platform: template
state_class: measurement
name: Weight Pete
id: weight_user1
unit_of_measurement: 'kg'
icon: mdi:weight-kilogram
accuracy_decimals: 2
- platform: template
state_class: measurement
name: Weight Ali
id: weight_user2
unit_of_measurement: 'kg'
icon: mdi:weight-kilogram
accuracy_decimals: 2