Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip all measurements below 80Kg ? #38

Open
criticallimit opened this issue Oct 31, 2021 · 9 comments
Open

skip all measurements below 80Kg ? #38

criticallimit opened this issue Oct 31, 2021 · 9 comments

Comments

@criticallimit
Copy link

criticallimit commented Oct 31, 2021

This is more a question.

Is it possible to skip all data/update/states/attributes when a person is using a scale who is below 80Kg?

Reason is:
Me, main user of the intergration, is above 80Kg. But all others in our household are below 80Kg nd they are not interested in details exept weight the scale is showing when they use it.
But that destroyes my longterm data.
So, it is possible to avoid all data transferred or stored when the user is below 80Kg?

Of course, a multi user arrangment would be better, but for the beginning that would help to skip all below 80Kg.

Thanx

@dckiller51
Copy link
Owner

The idea of ​​the component is to have one addition per user. Your problem is certainly related to the backup problem when you restart. Look for my node red to solve the problem.

@criticallimit
Copy link
Author

backup problem is solved when restart HA.

I´m asking for a small hint to avoid measurements transferred to HA when another user is using the scale.

Node red is no option.

can you point me to code and file, where I can enter a small code to avoid transferring data when user is below 80Kg?

For me, your inetrgation is working fine and I love it. But I have a wife and a kid using the scale as well.
So my graph and daily, weekly, monthly statistics are destroyed by these users. ;-)

@criticallimit criticallimit changed the title skip all measurements above 80Kg ? skip all measurements below 80Kg ? Oct 31, 2021
@dckiller51
Copy link
Owner

You can create a model sensor. This is the one you add to bodymiscale.

#- platform: template
  sensors:
    weight_username:
      friendly_name: "Weight User name"
      value_template: >-
        {% set weight = states('sensor.xiaomi_mi_scale_weight') | float %}
          {% if 80 <= weight <= 120 %}
            {{ states("sensor.xiaomi_mi_scale_weight") }}
          {% else %}
            {{ states("sensor.weight_username") }}
          {% endif %}
      unit_of_measurement: 'kg'
      icon_template: mdi:weight-kilogram

@criticallimit
Copy link
Author

that´s what I also think about.

But all other attributes are changing as well, like BMI, body_fat etc.

wouldn't it be easier to implement a weight-range in the bodymiscale.yaml?

like this:

`
Dirk:
sensors:
weight: sensor.waage_weight
impedance: sensor.waage_impedance
height: 189
weight: 90
born: "1966-09-13"
gender: "male"
model_miscale: "181B"

Mo:
sensors:
weight: sensor.waage_weight
impedance: sensor.waage_impedance
height: 155
weight: 40
born: "2010-11-12"
gender: "male"
model_miscale: "181B"
`
due to weight attribute in both profiles you can set a range
range for "Dirk": 90 +-5
range for "Mo": 40 +-5

your Integration can now decide if the data is to write to bodymiscale.dirk or bodymiscale.Mo ?

I´m not able to prog these changes, but maybe you can think about it and implement a multi user option...

in the meantime I will play with template sensors in HA. Maybe there is a solution in a template sensor I can´t see at the moment...

But thanx anyway for your quick reply!

@dckiller51
Copy link
Owner

I understand but this is the reverse of this components. It should read your weight sensor. So you must have an independent weight sensor for each user.

@criticallimit
Copy link
Author

criticallimit commented Nov 1, 2021

The Xiaomi App can handle this and automatically put the Data to the Person. Don´t know on which base, but I think it´s weight in relation to impedance.
But I did it now with template sensors for 3 Persons, which is working fine.
3 pairs of weight/impedance, one for every user. No matter who is on the scale, the data is going automatically to the right person. this, of course, is not working when a 4th person (guest) is using the scale. For that I have to put a switch to select a person. But that means, that every time you have to select a person before weighing.
An automatic selection solution I haven´t found, because weight and impedance is to close together for male or female humans.

Thank you for pointing me in the right direction. Learned a lot, and slowly come into HA, Yaml, py
Thanx!

@borpin
Copy link
Contributor

borpin commented Nov 11, 2021

I understand but this is the reverse of this components. It should read your weight sensor. So you must have an independent weight sensor for each user.

But what you could (probably) easily do is split up the configuration such that

scale_name:
  model_miscale: "181B"
  sensors:
    weight: sensor.ble_weight
    impedance: sensor.ble_impedance
 stats_user1:
   name: user1
   height: 182
   born: "1964-04-10"
   gender: "male"
   min_weight: 60
   max_weight: 70
 stats_user2:
   name: user2
   height: 182
   born: "1964-04-10"
   gender: "male"
   min_weight: 70
   max_weight: 90

Granted the user must not let the weight ranges overlap.

I also think each person's stats should be a device with each attribute being an entity

@TheFes
Copy link

TheFes commented Dec 16, 2021

If you use an ESP with ESPHome to collect the data, you can set this in the ESPHome config:

  - platform: xiaomi_miscale
    mac_address: "50:FB:19:17:34:96"
    weight:
      name: "Xiaomi Mi Scale Weight"
      id: weight_miscale
      on_value:
        then:
          - lambda: |-
              if (id(weight_miscale).state >= 69 && id(weight_miscale).state <= 77.49) {
                return id(weight_user2).publish_state(x);}
              else if (id(weight_miscale).state >= 77.50 && id(weight_miscale).state <= 83) {
                return id(weight_user1).publish_state(x);}
    impedance:
      name: "Xiaomi Mi Scale Impedance"
      id: impedance_xiaomi
      on_value:
        then:
          - lambda: |-
              if (id(weight_miscale).state >= 69 && id(weight_miscale).state <= 77.49) {
                return id(impedance_user2).publish_state(x);}
              else if (id(weight_miscale).state >= 77.50 && id(weight_miscale).state <= 83) {
                return id(impedance_user1).publish_state(x);}
  - platform: template
    name: Weight Martijn
    id: weight_user1
    unit_of_measurement: "kg"
    state_class: "measurement"
    icon: mdi:weight-kilogram
    accuracy_decimals: 2
  - platform: template
    name: Impedance Martijn
    id: impedance_user1
    unit_of_measurement: "ohm"
    icon: mdi:omega
    accuracy_decimals: 0
  - platform: template
    name: Weight Marleen
    id: weight_user2
    unit_of_measurement: "kg"
    icon: mdi:weight-kilogram
    state_class: "measurement"
    accuracy_decimals: 2
  - platform: template
    name: Impedance Marleen
    id: impedance_user2
    unit_of_measurement: "ohm"
    icon: mdi:omega
    accuracy_decimals: 0

69 kg to 77.49 kg is assigned to Marleen
77.5 kg to 83 kg is assigned to Martijn

All other values are ignored.

You could also include the impedance to further finetune it, but in my case they are too close to each other to be useful.

@dckiller51
Copy link
Owner

C'est plus une question.

Est-il possible d'ignorer toutes les données/mises à jour/états/attributs lorsqu'une personne utilise une balance de moins de 80 kg ?

La raison est la suivante : moi, principal utilisateur de l'intégration, je pèse plus de 80 kg. Mais tous les autres membres de notre foyer pèsent moins de 80 kg et ils ne sont pas intéressés par les détails, sauf le poids que la balance affiche lorsqu'ils l'utilisent. Mais cela détruit mes données à long terme. Alors, est-il possible d'éviter toutes les données transférées ou stockées lorsque l'utilisateur est en dessous de 80Kg ?

Bien sûr, un arrangement multi-utilisateurs serait préférable, mais pour le début, cela aiderait à sauter tout en dessous de 80 kg.

Merci

Did you solve your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants