I have a smart scale which I use to track multiple people’s weight. The weight is provided by the entity sensor.mi_body_composition_scale_c8f9_mass
.
Now, Jane and Paul have a similar weight, so I cannot use only the weight to decide who’s standing on the scale. My idea was to have a button in the home assistant UI, which I can activate to enable weighing one person while the other person is weighed when the switch is disabled.
To this end, I added a boolean input helper (input_boolean.log_weight_paul
) and made it accessible via a button into the UI. Then I set up the following sensor templates:
sensor:
- platform: template
sensors:
weight_jane:
friendly_name: "Weight Jane"
unique_id: "sensor_weight_jane_79c2f3"
device_class: weight
value_template: >-
{% set weight = states('sensor.mi_body_composition_scale_c8f9_mass') | float %}
{% if (50 <= weight < 59) and is_state('input_boolean.log_weight_paul', 'off')%}
{{ states("sensor.mi_body_composition_scale_c8f9_mass") }}
{% else %}
{% set state = states('sensor.weight_jane') %}
{{ state | float if is_number(state) else '' }}
{% endif %}
unit_of_measurement: "kg"
icon_template: mdi:weight-kilogram
- platform: template
sensors:
weight_paul:
friendly_name: "Weight Paul"
unique_id: "sensor_weight_paul_79c2f4"
device_class: weight
value_template: >-
{% set weight = states('sensor.mi_body_composition_scale_c8f9_mass') | float %}
{% if (56 <= weight <= 65) and is_state('input_boolean.log_weight_paul', 'on') %}
{{ states("sensor.mi_body_composition_scale_c8f9_mass") }}
{% else %}
{{ states("sensor.weight_paul") }}
{% endif %}
unit_of_measurement: "kg"
icon_template: mdi:weight-kilogram
For some reason this is not working. When the switch is enabled (the boolean is true), the weight gets assigned to the Paul sensor as expected. However, once the switch is disabled the previous weight is assigned to Jane. Also when the switch is off it will be assigned to both.
Does anybody know what the issue is here? I guess I got something wrong in how these sensor templates work.