-
Notifications
You must be signed in to change notification settings - Fork 36
Plugin: BS440google Store weight in Google Fit
Google Fit (in Playstore and AppStore) records your daily activity (steps, workouts etc) automatically. You can also provide data manually but even cooler: you can now instruct BS440 to send your recorded weight to Google Fit.
Create a BS440google.ini file in the plugin directory containing the scale users and their associated authentication json to Google Fit, like:
[Person1]
username: Jane
googleauthfile: /home/pi/BS440/plugins/google_jane.json
[Person2]
username: Joe
googleauthfile: /home/pi/BS440/plugins/google_joe.json
See here how to grant BS440 access to your Google Fit personal data.
The Google auth file is expected to reside in the BS440 folder. If you prefer it to be elsewhere provide the full path in the ini file.
The Google code needs some new imports which can be installed with
sudo pip install httplib2
sudo pip install pyyaml
sudo pip install python-dateutil --upgrade
sudo pip install pytz --upgrade
sudo pip install --upgrade google-api-python-client
sudo pip install --upgrade oauth2client
The log - when succesfully - will look like this: (values are faked)
Wed, 23 Oct 2019 21:58:03 INFO execute Starting plugin: BS440google
Wed, 23 Oct 2019 21:58:03 INFO execute ini read from: /home/pi/BS440/plugins/BS440google.ini
Wed, 23 Oct 2019 21:58:03 INFO execute Updating Google Fit for user Joe with weight 75.1 and google authfile: /home/pi/BS440/plugins/google_joe.json
Wed, 23 Oct 2019 21:58:03 INFO GetGoogleClient Creating Google client
Wed, 23 Oct 2019 21:58:03 INFO GetGoogleClient Reading auth file /home/pi/BS440/plugins/google_joe.json
Wed, 23 Oct 2019 21:58:03 WARNING autodetect file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect
from . import file_cache
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module>
'file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth')
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth
Wed, 23 Oct 2019 21:58:03 INFO _retrieve_discovery_doc URL being requested: GET https://www.googleapis.com/discovery/v1/apis/fitness/v1/rest
Wed, 23 Oct 2019 21:58:04 INFO GetGoogleClient Google client created
Wed, 23 Oct 2019 21:58:04 INFO AddGoogle Created a new dataset: 1571883645094135040-1571872635094153984
Wed, 23 Oct 2019 21:58:04 INFO method URL being requested: GET https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.weight%3A453726354637%3Aunknown%3Aunknown%3A10000001?alt=json
Wed, 23 Oct 2019 21:58:04 INFO AddGoogle Data Source ID: raw:com.google.weight:4537376354637:unknown:unknown:10000001
Wed, 23 Oct 2019 21:58:04 INFO method URL being requested: PATCH https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.weight%3A453381787840%3Aunknown%3Aunknown%3A10000001/datasets/1571883645094135040-1571872635094153984?alt=json
Wed, 23 Oct 2019 21:58:04 INFO AddGoogle Created a new dataset: 1571883645094135040-1571872635094153984
Wed, 23 Oct 2019 21:58:04 INFO method URL being requested: GET https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.body.fat.percentage%3A453381787840%3Aunknown%3Aunknown%3A10000001?alt=json
Wed, 23 Oct 2019 21:58:04 INFO AddGoogle Data Source ID: raw:com.google.body.fat.percentage:453381763524:unknown:unknown:10000001
Wed, 23 Oct 2019 21:58:04 INFO method URL being requested: PATCH https://www.googleapis.com/fitness/v1/users/me/dataSources/raw%3Acom.google.body.fat.percentage%3A456539287463%3Aunknown%3Aunknown%3A10000001/datasets/1571860687263645372-1576253827632891904?alt=json
Wed, 23 Oct 2019 21:58:05 INFO execute Finished plugin: BS440google
The warning should do no harm as from https://github.com/googleapis/google-api-python-client/issues/299. Tried the cache_discovery=False without success.
When debugging temporarely remove the try: except: block around
self.googleClient = self.GetGoogleClient(googleauthfile)
self.AddGoogle(self.googleClient, weightdata[0]['weight'], WEIGHTD, googleauthfile)
self.AddGoogle(self.googleClient, bodydata[0]['fat'], FATD, googleauthfile)
otherwise the process will die silently without usefull error messages...
It sometimes takes a while for the new weight to show in the Google Fit app, not sure how to force the app to read the updated data.