Since a while I’m owning great Withings Scale which has a capability to store measurements in a cloud. Because I’m using Garmin GPSes (and Garmin Connect), I’d love to synchronize the measurements to the Garmin Connect site.
Lucky, I found a great script garmin-withings.
Unfortunately, after latest changes in the Garmin Connect (implementation of SSO on march 2014) the script stopped to work. I’ve compiled changes proposed by https://github.com/cpfair/tapiriik and it seems that the script with my updates works again (well, at least until further changes in Garmin Connect…)
You can find the script on https://github.com/jaroslawhartman/withings-sync
ToDo
Garmin Connect can display a lot of other parameters, not only weight and body fat level:
It would be great to calculate all these figures and post them to Garmin Connect, right? 🙂
Did you notice that this script is not working anymore? It gives me this error message:
Traceback (most recent call last):
File “sync.py”, line 125, in
main()
File “sync.py”, line 60, in main
sync(**opts.__dict__)
File “sync.py”, line 117, in sync
cookie = garmin.login(garmin_username, garmin_password)
File “/Users/Cezex/Utilities/Withings2Garmin/garmin.py”, line 132, in login
cookies = self._get_cookies(email=username, password=password)
File “/Users/Cezex/Utilities/Withings2Garmin/garmin.py”, line 100, in _get_cookies
data[“lt”] = re.search(“name=\”lt\”\s+value=\”([^\”]+)\””, preResp.text).groups(1)[0]
AttributeError: ‘NoneType’ object has no attribute ‘groups’
Will you be able to fix it?
Hi,
Thanks for pointing this out. Indeed, I see in the logs same issue .
Will take a look if this can be fixed. Pity Garmin is messing with the login.
Seems to be fixed, see https://github.com/jaroslawhartman/withings-garmin-v2
Hi,
Seems it’s fixed now, see: https://github.com/jaroslawhartman/withings-garmin-v2 (download garmin.py)
Once again – thanks for flagging. Somehow I overlooked this problem.
Jarek
Hi.
I’m trying to run the script, but I’m getting “user EVG has not opened withings data”. As I understand my Withings profile should be public, but I can’t find a wake to make it so, neither in the web interface or in Android app.
Could you help me with that please?
Although, I was able to sync by commenting out these three lines:
if not user.ispublic:
print ‘user %s has not opened withings data’ % withings_shortname
return
This script is not working for me. It gives me this error message:
==> Python sync.py – no – upload> weight.fit
Traceback (most recent call last):
File “sync.py”, line 126, in
main()
File “sync.py”, line 59, in main
sync(**opts.__dict__)
File “sync.py”, line 118, in sync
session = garmin.login(garmin_username, garmin_password)
File “/Users/aurelio/Desktop/Garmin/withings-garmin/garmin.py”, line 139, in login
session = self._get_session(email=username, password=password)
File “/Users/aurelio/Desktop/Garmin/withings-garmin/garmin.py”, line 77, in _get_session
data[“lt”] = re.search(“name=\”lt\”\s+value=\”([^\”]+)\””, preResp.text).groups(1)[0]
AttributeError: ‘NoneType’ object has no attribute ‘groups’
Hi, is this script working for you ? It generated the .fit file, upload to garmin connect but I see no data in garmin. I tried also upload fit file manually with the same result. Any clue ?
Thanks
$ ./sync.py –no-upload -v > file.fit
generating fit file…
appending weight scale record… 2017-11-16 18:58:01 Nonekg None%
appending weight scale record… 2017-11-16 18:58:01 Nonekg None%
appending weight scale record… 2017-11-16 18:58:01 75.15kg 16.713%
appending weight scale record… 2017-11-16 00:12:32 Nonekg None%
$
Hm, can’t really reproduce this issue, even when ran same command:
generating fit file…
appending weight scale record… 2017-11-18 08:15:36 Nonekg None%
appending weight scale record… 2017-11-18 08:15:36 76.891kg 17.259%
attempting to upload fit file…
weight.fit has been successfully uploaded!
What I found strange in your results is multiple lines with Nonekg, especially, the last line. Perhaps this is confusing the script?
interestingly, I’ve run the script just now and seem to have gone through. maybe it was some temp issue on garmin side 🙂 thanks
I built my own version of a Withings-to-Garmin sync tool and hosted it here: https://smartscalesync.com/?utm_source=jhpl
It’s not free but there’s time/maintenance overhead to running it yourself locally so I thought people might be interested.
Hi Patrick,
Thank you for this comment, somehow I’ve overlooked it.
This is very good initiative! I trust it will find its customers.
Good luck and best regards,
Jarek
I love this script! I’ve never touched Python before, but I managed to make it work. Thank you!
I’m now trying to import all previous data (last 2 years) and I’m really struggling to set the date range, it’s probably really simple, but I know nothing about python and I’ve been struggling with this for the last hour, can anyone help me out?
Hi Johan,
All you need to do is use
-f
parameter. As per helpjhartman@wieloryb:~/scripts/withings-garmin-v2$ ./sync.py --help
Usage: sync.py [options]
Options:, --gu= , --gp= password to login Garmin Connect., --fromdate= , --todate=
-h, --help show this help message and exit
--garmin-username=
username to login Garmin Connect.
--garmin-password=
-f
-t
--no-upload Won't upload to Garmin Connect and output binary-
strings to stdout.
-v, --verbose Run verbosely
you can use -f to specify from date, for example:
jhartman@wieloryb:~/scripts/withings-garmin-v2$ ./sync.py --garmin-username=[username] --garmin-password=[pwd] -f 20170101
I hope it will help,
Jarek
Hi Jarek,
I had the date format wrong.
I have my old data in garmin connect down.
Thank you so much!
Regrads,
Johannes
I’m glad it’s working!
Regards, Jarek
Hi, I’m getting an error with this every time I try to enter the auth code from the withing website.
Withings: Get Access Token
Received error(s):
invalid_grant: Wrong redirect_uri – Please use same as the one set to get authorization code
I’ve tried it several times, making sure I’m copying it correctly and doing it within 30 seconds, but it never works.
Any ideas?
I’ve checked it on my side and all seems working very fine.
I believe you’ve changed something with the
"callback_url": "https://wieloryb.uk.to/withings/withings.html",
but not registered a new app. Suggestion: use same callback URL or follow steps needed to register a new app (but this is more complex).Regards,
Jarek
Hi Jarek,
I didn’t change anything. But I tried it on my Windows laptop and it all works fine. When I run it from my QNAP NAS it fails, even though I’m doing exactly the same thing.
I’m not sure what’s going on. If I copy the WIthings config from the Windows laptop to the QNAP device, it then gets through the Withings authentication but then fails on the Garmin login.
I have a suspicion that it may be something to do with the Python environment on the QNAP, or a problem with the Requests module, as there were a few warnings installing it on the QNAP.
Thanks for checking.
Indeed, it’s looks like a problem with sending HTTP requests.
Regards!