Calorie and weight loss tracker

Hey Smart home people, I wanted to share a little project I made to help with my weight loss journey.
There is just one prerequisite, I use the gamin connect integration which is linked to MyFitnessPal.
I made 2 number helpers:

  1. maintenance calories (mine is 2500)
  2. current weight
    First I made some sensors which calculate daily weight loss, assuming there are 7700 calories in a Kg of Bodyfat:
    consumed_calories - maintenance_calories / 7700
    so, if daily I consume only 2000 calories, theoretically I would lose 0.07kg (70g) a day.
- platform: template
  sensors:
    weight_loss_nils_food_kg:
      friendly_name: "Nils Weight Loss food"
      value_template: "{{ ((states('sensor.consumed_kilocalories') | float(0) - states('input_number.nils_calories_maintenance') | float) / 7700 ) | round(2) }}"
      unit_of_measurement: 'kg'

I added a second sensor which also takes in the “active” calories:

- platform: template
  sensors:
    weight_loss_nils_active_kg:
      friendly_name: "Nils Weight Loss with activity"
      value_template: "{{ (((states('sensor.consumed_kilocalories') | float(0)) + (states('sensor.active_kilocalories_kilocalories') | float(0)) - states('input_number.nils_calories_maintenance') | float) / 7700) | round(2) }}"
      unit_of_measurement: 'kg'

Lastly I made to sensors to show the weight after the day’s loss and a silly one to show the remaining calories to reach my weight goal:

- platform: template
  sensors:
    weight_after_loss_nils_food_kg:
      friendly_name: "Nils Weight After Loss Food"
      value_template: "{{ (states('input_number.nils_current_weight') | float + states('sensor.weight_loss_nils_food_kg') | float(0)) }}"
      unit_of_measurement: 'kg'

Total remaming Kcal:

- platform: template
  sensors:
    nils_remaining_calories_to_goal:
      friendly_name: "Remaining Calories to Goal"
      value_template: "{{ ((states('input_number.nils_actual_weight_placeholder') | float(0) - states('sensor.nils_withings_weight_goal') | float(0)) * 7700) | round(0) }}"
      unit_of_measurement: 'kcal'

5 Likes

Thanks for your inspiration.

I did something like that myself, based on your data.

I added a basic BMR calculator as well as a sensor which calculates my active calories based on my steps.

EDIT: Can you please tell me how you added your weight vs projected?

Hey, that’s great! I love it with the steps as well.

For that graph I used the cusom:mini-graph-card.

Here is the code just for that part…

- type: custom:mini-graph-card
        entities:
          - entity: input_number.nils_current_weight
            name: Calculated weight
            color: green
            show_fill: true
            unit: kg
          - entity: sensor.nils_withings_weight
            name: Actual Weight
            color: blue
            show_fill: true
            show_state: true
        name: Nils weight vs Projected
        line_width: 2
        points_per_hour: 1
        hours_to_show: 502
        font_size: 60
        height: 160
        animate: true
        smoothing: true
        decimals: 2
        hour24: true
1 Like

I also have a smart scale with HA (sensor.withings_weight_kg) and I want to create a card showing the weight loss value over the past XX days.

Have you managed to do this? I’m looking for inspiration.
Thank