lovelace-body-miscale-card icon indicating copy to clipboard operation
lovelace-body-miscale-card copied to clipboard

Breaking out additional info into own entities?

Open Stooovie opened this issue 3 years ago • 9 comments

Hi, thanks for the component. How would I break out the individual measurements such as Body fat, Visceral fat or BMI into their own entities so I can track them over time with things like Grafana? Thank you!

Stooovie avatar Jul 27 '21 15:07 Stooovie

Hi, I'd be keen for this information as well. Thanks!

SmarterHomeLife avatar Aug 05 '21 08:08 SmarterHomeLife

The easiest way is to create a sensor template. One sensor per attibute exemple:

- platform: template
  sensors:
    test_bmi:
      friendly_name: "Test BMI"
      value_template: >
        {{ state_attr('bodymiscale.test', 'bmi') }}

test_bmi = name sensor (sensor.test_bmi) (sensor.test_water)....... value_template = replace bmi for attribute (water, visceral_fat....) {{ state_attr('bodymiscale.test', 'bmi') }}

dckiller51 avatar Aug 05 '21 09:08 dckiller51

Thanks very much! I'll give that a go tonight.

SmarterHomeLife avatar Aug 05 '21 09:08 SmarterHomeLife

I am a little bit confused on this one... this is an HA config, .test i the name of the esphome integration?

alinelena avatar Aug 19 '21 13:08 alinelena

Je suis un peu confus sur celui-ci... c'est une config HA, .test i le nom de l'intégration esphome ?

It is a sensor template in ha.

Test in model {{ state_attr('bodymiscale.name', 'bmi') }}

dckiller51 avatar Aug 19 '21 13:08 dckiller51

ok got it.. here is small bash script to generate sensors for all the attributes. all you need to provide as argument is the user names as defined in esphome (user1,... in the example)

#!/usr/bin/env bash

user=$1

attr=(bmi basal_metabolism visceral_fat ideal bmi_label lean_body_mass body_fat water bone_mass muscle_mass fat_mass_to_lose fat_mass_to_gain protein body_type body_score metabolic_age)
units=(None kcal None kg None kg % % kg kg kg kg % None None years)
echo "- platform: template"
echo "  sensors:"
i=0
for a in ${attr[*]}; do 
echo "    ${a}_$user:
      friendly_name: \"${user^}'s ${a/_/ }\""
if  [[ "${units[i]}" != "None" ]]; then
echo "      unit_of_measurement: \"${units[i]}\""
fi
echo "      value_template: >
        {{ state_attr('bodymiscale.$user', '$a') }}"
((i++))          
done


update to have units

alinelena avatar Aug 20 '21 06:08 alinelena

above example is fine, if you want to use platform template.. if one wants to use template: integration things are slightly different

- sensor:
  - name: "metabolic age alin"
    unit_of_measurement: "years"
    state: >
      {{ state_attr('bodymiscale.alin', 'metabolic_age') }}
    state_class: measurement

i assumed in configuration.yaml one has

template: !include templates.yaml

a script to generate all for a user

#!/usr/bin/env bash

user=$1

attr=(bmi basal_metabolism visceral_fat ideal bmi_label lean_body_mass body_fat water bone_mass muscle_mass fat_mass_to_lose fat_mass_to_gain protein body_type body_score metabolic_age)
units=(No kcal No kg No kg % % kg kg kg kg % No No years)
i=0
for a in ${attr[*]}; do 
echo "- sensor:
  - name: \"${a/_/ } $user\""
echo "    unit_of_measurement: \"${units[i]}\""
echo "    state: >
      {{ state_attr('bodymiscale.$user', '$a') }}
    state_class: measurement"
((i++))          
done

this approach shall make sensors available in statistics for HA. note the weight and impedance for a user are not. a cheap solution will be to reexport them by adding them to the list. probably this is nicer to be set at esphome level for these too... digging it

alinelena avatar Aug 20 '21 08:08 alinelena

l'exemple ci-dessus est bien, si vous voulez utiliser un modèle de plate-forme.. si l'on veut utiliser un modèle : les choses d'intégration sont légèrement différentes

- sensor:
  - name: "metabolic age alin"
    unit_of_measurement: "years"
    state: >
      {{ state_attr('bodymiscale.alin', 'metabolic_age') }}
    state_class: measurement

j'ai supposé que dans configuration.yaml on a

template: !include templates.yaml

un script pour tout générer pour un utilisateur

# ! /usr/bin/env bash

utilisateur = $1

attr=(bmi basal_metabolism visceral_fat ideal bmi_label lean_body_mass body_fat water bone_mass muscle_mass fat_mass_to_lose fat_mass_to_gain protein body_type body_score métabolique_age)
unités=(Non kcal Non kg Non kg % % kg kg kg kg % Non Non années)
i=0
pour  un  dans  ${attr[*]} ;  do  
echo  " - sensor: 
  - name: \" ${a / _ / }  $user \" "
 echo  "     unit_of_measurement: \" ${units[i]} \" "
 echo  "     state: > 
      {{ state_attr('bodymiscale . $user ', ' $a ') }} 
    state_class: mesure " 
(( i ++ ))          
 done

cette approche doit rendre les capteurs disponibles dans les statistiques pour l'HA. notez que le poids et l'impédance pour un utilisateur ne le sont pas. une solution bon marché sera de les réexporter en les ajoutant à la liste. c'est probablement plus agréable d'être réglé au niveau esphome pour ceux-ci aussi... en le creusant

Your approach is very interesting. But if I understood correctly that makes your script limited to esphome? For example, for my part, I no longer use esphome for users, only for weight and impedance data. Now I have node red which sends me a notification so that I select the person who weighs himself. This card and component should be open to the other solution.

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

dckiller51 avatar Aug 20 '21 22:08 dckiller51

yap this assumes person selection is done at esphome level... I like it like that ideally all the processing will be nice to happen their so HA just displays... all I tried there was to generalise you solution from there and in second to port it to the template integration which supposes to be better for stats.

alinelena avatar Aug 20 '21 23:08 alinelena