cyberjunky / home-assistant-garmin_connect

The Garmin Connect integration allows you to expose data from Garmin Connect to Home Assistant.
MIT License
243 stars 35 forks source link

Weight Sensors change at midnight to 'unknown'? #42

Open alvinchen1 opened 2 years ago

alvinchen1 commented 2 years ago

Hello, great integration. I have noticed that with my Garmin Fit Scale, that my weights come through, but at about midnight my local time, the values revert to "unknown".

image

Here's an example of weight, that shows the value in the history log, but seems the state changes from the value to 'unknown' at shortly before midnight local. (It is currently almost 11:00 local, and the screen shot shows 11 hours ago last change).

This appears to affect the following sensors:

sensor.body_fat sensor.bmi sensor.body_water sensor.bone_mass sensor.muscle_mass sensor.visceral_fat sensor.weight

All of which have values, but then change to 'unknown'. I looked over your code, and it looks like you are just taking stuff from Garmin and putting it into the sensor, but perhaps, it is possible to do a check on these weight values and if they come through as 'unknown' from Garmin, maybe drop it and don't pass it on to the sensor?

I'd be happy to provide additional debug or logs information if it would help to resolve this issue. Thanks!

Tazmanian79 commented 1 year ago

Anyone had already found a solution for this? I have exact the same issue.

cyberjunky commented 1 year ago

This is a longer known issue, got an aha moment, and suspect we need to use UTC datetime to calculate date, will test it.

markblokpoel commented 1 year ago

This issue still comes up for me. Weight /scale data is lost after midnight. Any additional info I can give? I'm in timezone CET+1.

ML19821 commented 1 year ago

I've got the same issue

gllmlbrt commented 9 months ago

HI, I have the same issue. Is there a temporary work around or a version to test any fix ?

cyberjunky commented 9 months ago

Hi guys, this issue of no data around midnight has been there from the beginning, I thoughted it maybe had something to do with timezone differences.. But didn't get it fixed yet. Will ask if author of Garth has same experience, I will keep you updated?

Broekman commented 9 months ago

Anyone looking for a temporary mitigation could use the template sensor below.

template:
  - trigger:
      - platform: state
        entity_id: sensor.weight
        not_to:
          - unknown
          - unavailable
    sensor:
      - name: "Garmin - weight"
        icon: "mdi:weight-kilogram"
        device_class: weight
        unit_of_measurement: "kg"
        state_class: measurement
        state: >-
          {{ trigger.to_state.state | float(0) }}
Broekman commented 9 months ago

Aside from my previous comment, for other sensors it could be nice to have a total_increasing sensor which you can than plot in a graph like is done in e.g. the HA energy dashboard. Still a bit annoying if you miss a day or not update before midnight as it will reset back to unknown/unavailable again until the next update, but it's better than nothing 😅

  - trigger:
      - platform: state
        entity_id: sensor.total_kilocalories
        not_to:
          - unknown
          - unavailable
    sensor:
      - name: "Garmin - total calories"
        icon: "mdi:dumbbell"
        unit_of_measurement: "kcal"
        state_class: total_increasing
        state: >-
          {{ trigger.to_state.state | float(0) }}

@cyberjunky are these kind of total_increasing values available from the Garmin interface instead of a daily value that resets?