dckiller51 / bodymiscale

Custom_components Body Metrics for Xiaomi Miscale 1 and 2 (esphome or BLE monitor for Homeassistant)
Apache License 2.0
204 stars 32 forks source link

Multiuser Support #11

Open stefangries opened 3 years ago

stefangries commented 3 years ago

Hello! Thank you for your work on the integration, it is great.

I have a suggestion how to improve the integration even more. This is about multiuser support. For example, the users could be distinguished by the measured weight.

You could configure it like this for example:

bodymiscale:
  model_miscale: "181B"
  sensors:
    weight: sensor.weight_aurelien
    impedance: sensor.impedance_aurelien
  users:
    - name: "Username 1"
      height: 176
      born: "1990-04-10"
      gender: "male"
      weight_low: 70
      weight_heigh: 100
    - name: "Username 2"
      height: 170
      born: "1990-01-12"
      gender: "female"
      weight_low: 0
      weight_heigh: 70

Each user would then get his own entity. For this to be possible, the values would probably also have to be persisted in core.restore_state.

dckiller51 commented 3 years ago

Hello, at the beginning I was part in this direction then my wife and I we have a weight too close. So I went with this solution. In addition it keeps the data well after a restart.

https://community.home-assistant.io/t/exemple-xiaomi-miscale-select-the-person-who-weighs-himself-notif-action/299321

sendorm commented 3 years ago

ESPHOME has a way to do this on sensor scale:

https://esphome.io/components/sensor/xiaomi_miscale2.html

You can add as many users as you want, granted they differ in weight ranges.

norbertjoni commented 2 years ago

Hello, at the beginning I was part in this direction then my wife and I we have a weight too close. So I went with this solution. In addition, it keeps the data well after a restart.

https://community.home-assistant.io/t/exemple-xiaomi-miscale-select-the-person-who-weighs-himself-notif-action/299321

Hello,

There is a solution to do this without nodered? Example with input?

criticallimit commented 2 years ago

Multiuser would be fine without nodered.

Anyone got this working without node red?

Best would be that dckiller can implement this. If it is only a thing of changing the conig.yaml, can somebody give examples how to do?

borpin commented 2 years ago

I'll add a Plus one - this seems like the most logical extension of this.

posreg commented 2 years ago

plus 1 from my side as well!

borpin commented 2 years ago

My solution is to take the readings from the scale, pass through Node-RED to check who it is and then send to their own weight/imp sensors. It also solves the retained issue at the same time.

dckiller51 commented 2 years ago

You must create one bodymiscale per user. The component is based on https://www.home-assistant.io/integrations/plant/

JGAguado commented 2 years ago

Dear @dckiller51, Thanks a lot for your work! Can you please provide an example of configuration for this?

You must create one bodymiscale per user. The component is based on https://www.home-assistant.io/integrations/plant/

dckiller51 commented 2 years ago

Dear @dckiller51, Thanks a lot for your work! Can you please provide an example of configuration for this?

You must create one bodymiscale per user. The component is based on https://www.home-assistant.io/integrations/plant/

hello, your request should not be here. but here is an example

https://community.home-assistant.io/t/exemple-xiaomi-miscale-select-the-person-who-weighs-himself-notif-action/299321

supperka commented 1 year ago

Hello , if i create one bodymiscale per user. Only one card show statistic but others are unavailable ,till next messure, then new is showed other are unavailable. https://ibb.co/mG2Fnrk https://ibb.co/YbLhsHG

SkyTakes commented 9 months ago

Hello , if i create one bodymiscale per user. Only one card show statistic but others are unavailable ,till next messure, then new is showed other are unavailable. https://ibb.co/mG2Fnrk https://ibb.co/YbLhsHG

Hello, Any updates on this? I have the same issue.

s3tFlag commented 9 months ago

plus 1

dckiller51 commented 9 months ago

plus 1

What is your configuration? it is important to have a weight and impedance sensor for each user.

Eskander commented 8 months ago

I use templates to create a new weight sensor per person, then add that sensor to the person's bodymiscale instance. Here's an example that assigns the new scale values to the closest weight sensor:

template:
  - trigger:
      - platform: state
        entity_id:
          - sensor.mi_smart_scale_mass
    sensor:
      - name: "Person 1 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set distance_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set distance_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% if distance_a < 5 and distance_a < distance_b %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_1_mass') }}
          {% endif %}
      - name: "Person 2 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set distance_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set distance_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% if distance_b < 5 and distance_b < distance_a %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_2_mass') }}
          {% endif %}
maciek188 commented 5 months ago

How about more users, like e.g. 4?

Eskander commented 5 months ago

@maciek188, Following the same logic, something like this should work for 4 people:

Note: since HA doesn't initially know the values of sensor.person_1_mass, sensor.person_2_mass, sensor.person_3_mass and sensor.person_4_mass, they'll all be zeroes at first. You should set their proper values in Developer Tools.

template:
  - trigger:
      - platform: state
        entity_id:
          - sensor.mi_smart_scale_mass
    sensor:
      - name: "Person 1 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set delta_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set delta_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% set delta_c = (states('sensor.person_3_mass') | float - weight) | abs %}
          {% set delta_d = (states('sensor.person_4_mass') | float - weight) | abs %}
          {% if delta_a == [delta_a, delta_b, delta_c, delta_d, 5] | min %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_1_mass') }}
          {% endif %}
      - name: "Person 2 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set delta_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set delta_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% set delta_c = (states('sensor.person_3_mass') | float - weight) | abs %}
          {% set delta_d = (states('sensor.person_4_mass') | float - weight) | abs %}
          {% if delta_b == [delta_a, delta_b, delta_c, delta_d, 5] | min %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_2_mass') }}
          {% endif %}
      - name: "Person 3 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set delta_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set delta_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% set delta_c = (states('sensor.person_3_mass') | float - weight) | abs %}
          {% set delta_d = (states('sensor.person_4_mass') | float - weight) | abs %}
          {% if delta_c == [delta_a, delta_b, delta_c, delta_d, 5] | min %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_3_mass') }}
          {% endif %}
      - name: "Person 4 Mass"
        unit_of_measurement: "kg"
        state: >
          {% set weight = states('sensor.mi_smart_scale_mass') | float %}
          {% set delta_a = (states('sensor.person_1_mass') | float - weight) | abs %}
          {% set delta_b = (states('sensor.person_2_mass') | float - weight) | abs %}
          {% set delta_c = (states('sensor.person_3_mass') | float - weight) | abs %}
          {% set delta_d = (states('sensor.person_4_mass') | float - weight) | abs %}
          {% if delta_d == [delta_a, delta_b, delta_c, delta_d, 5] | min %}
            {{ weight }}
          {% else %}
            {{ states('sensor.person_4_mass') }}
          {% endif %}
terslowe commented 5 months ago

I am using BLE monitor and this integration and it shows me on the lovelace card correct data. But i want to use now 2 multi user data registered on separate lovelace card. Now i have followed this topic but don't really understand how i can do that. Can someone please help me?

teras commented 1 month ago

What if I have to distinguish impedance too, based on weight? How can it be guaranteed that the correct value will be set?

Could be something like this? reading both values and set it accordingly?

    state: >
      {% set weight = states('sensor.mi_body_scale_mass') | float %}
      {% set impedance = states('sensor.mi_body_scale_impedance')  %}
      {% if weight >= 90 %}
        {{ impedance }}
      {% else %}
        {{ states('sensor.panayotis_impedance') }}
      {% endif %}
The whole configuration is here: ```yaml template: - trigger: - platform: state entity_id: - sensor.mi_body_scale_mass - sensor.mi_body_scale_impedance sensor: - name: "Panayotis Mass" unit_of_measurement: "kg" state_class: measurement icon: mdi:weight state: > {% set weight = states('sensor.mi_body_scale_mass') | float %} {% if weight >= 90 %} {{ weight }} {% else %} {{ states('sensor.panayotis_mass') }} {% endif %} - name: "Panayotis Impedance" unit_of_measurement: "ohm" state_class: measurement icon: mdi:omega state: > {% set weight = states('sensor.mi_body_scale_mass') | float %} {% set impedance = states('sensor.mi_body_scale_impedance') %} {% if weight >= 90 %} {{ impedance }} {% else %} {{ states('sensor.panayotis_impedance') }} {% endif %} - name: "George Mass" unit_of_measurement: "kg" state_class: measurement icon: mdi:weight state: > {% set weight = states('sensor.mi_body_scale_mass') | float %} {% if weight < 90 %} {{ weight }} {% else %} {{ states('sensor.george_mass') }} {% endif %} - name: "George Impedance" unit_of_measurement: "ohm" state_class: measurement icon: mdi:omega state: > {% set weight = states('sensor.mi_body_scale_mass') | float %} {% set impedance = states('sensor.mi_body_scale_impedance') %} {% if weight < 90 %} {{ impedance }} {% else %} {{ states('sensor.george_impedance') }} {% endif %} ```

EDIT

I tried it and it works! :partying_face: