jaroslawhartman/withings-sync

Is the command idempotent?

maruina opened this issue · 6 comments

Hi, I have the script wrapped in a while loop to run every 15 minutes but I end up having a lot of duplicates on my Garmin Connect as per the screenshot.

image

Am I doing something wrong? The while loop is just something like

while true; do
            withings-sync
            echo "Command completed. Sleeping ${SLEEP} seconds..."
            sleep "${SLEEP}"
done

I noticed in my logs that this behavior started around may 10. Previously, duplicate fit uploads to Garmin where handled by Garmin to show up only once. Unfortunately I can't seem to find a changelog for the Garmin Connect backend services.

There do is a maintenance at the moment (the script won't upload) so lets cross our fingers that they noticed and are rolling out a fix for this.

edit: the maintenance didn't fix this... duplicates are still accepted by Garmin

I'm seeing the same issue as well. Started on the 4th or 5th of the month for me (maybe the night of the 4th since that only had about 4 or 5 entries and my cronjob is set to run hourly). I may just set it to run once a day around lunch time to be certain for a weigh-in to occur by then, at least until Garmin's API gets fixed

Hi big thanks for this project... Just got a garmin smart watch and thought I would have to ditch my withings scale as well as 3 years worth of weight data.

I have noticed this as well...

Is it possible to pass a date + time to the --fromdate?

At least then we could locally log last run, and increment by 60 seconds or whatever... Just an idea.

Warning, I am by no means an expert with python, withings or the garmin APIs...

But I was able to resolve this using the following:

In sync.py update def date_parser(s) to return datetime.strptime(s, '%Y-%m-%d-%H:%M:%S').

This will allow you to pass a --fromdate in the following syntax:

YYYY-MM-DD-HH:MM:SS

So what I am doing is locally recording when the last withings to garmin sync was done and on subsequent requests I am passing a --fromdate with that date + time - 60 seconds, rounded down to 00 seconds.

This way I am basically only sending garmin my latest weight.

I of course did an initial push of all my past data.

This seams to do the trick for me. Its only been up for an hour or so but so far so good. Only getting the latest weigh in sent over.


Bonus round : For those like me who have a fairly well built home iot setup... I am also logging when the scale hits my wifi, and when it does, I have my scripts execute the sync. Of course be sure to script in some niceness checks to make sure that regardless of if the conditions for a sync are met you only hit the withings / germin APIs every XX minutes...

Enjoy!

Bonus round : For those like me who have a fairly well built home iot setup... I am also logging when the scale hits my wifi, and when it does, I have my scripts execute the sync. Of course be sure to script in some niceness checks to make sure that regardless of if the conditions for a sync are met you only hit the withings / germin APIs every XX minutes...

Enjoy!

This is brilliant!
How do you detect the scale on Wifi, i'm thinking of pinging it every so often, but I am sure there must be a more elegant solution?

I believe there's a PR intended to solve this problem, #38