vmanuel / hacs-google-fit Goto Github PK
View Code? Open in Web Editor NEW♥️ HACS Google Fit integration for Home Assistant
License: MIT License
♥️ HACS Google Fit integration for Home Assistant
License: MIT License
I installed the integration via HACS
After rebooting hass im getting notification:
Google Fit Setup
Error: Invalid response 400. Error: invalid_scope
You will need to restart hass after fixing.
But never any login code message as I get with google calendar for example
No .token
files are created in config folder.
And in logs I have this error message:
Logger: homeassistant.components.sensor
Source: custom_components/google_fit/sensor.py:293
Integration: Sensor (documentation, issues)
First occurred: 11:04:27 (1 occurrences)
Last logged: 11:04:27
google_fit: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 735, in async_device_update
await task
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper
result = method(*args, **kwargs)
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/google_fit/sensor.py", line 460, in update
height_datasources = self._get_datasources('com.google.height')
File "/config/custom_components/google_fit/sensor.py", line 293, in _get_datasources
datasources_request = self._client.users().dataSources().list(
AttributeError: 'NoneType' object has no attribute 'users'
Tried removing pycache, reinstalling, creating the token file by hand based on OAuth Playground always the same error and no .token file
I have noticed that there hasn't been any work done on this project in some time and am wondering if there are any plans to continue work on it?
Can you extend the code with reading blood pressure from google fit? Im syncing data from Omron to google fit so that I can log it in HA.
There are also more measurements which may be interesting to add considering new smartwatches that can log blood oxygen.
Unsure what happens but sleep sensor is now 100% not working anymore. Is this a bugs or maybe Google change its API?
Is there any way to change the measurement units from metric to imperial for us 'freedom unit' impaired folks? I'm sure it could be done with templates, but it seems like the sensor should use the HA unit_system setting.
Or is this a limitation of the API?
Getting this in the logs:
2021-05-13 10:55:05 WARNING (SyncWorker_5) [googleapiclient.http] Encountered 403 Forbidden with reason "forbidden"
2021-05-13 10:55:05 ERROR (MainThread) [homeassistant.components.sensor] google_fit: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 365, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 482, in async_device_update
await task
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 278, in wrapper
result = method(*args, **kwargs)
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 278, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/google_fit/sensor.py", line 517, in update
for datapoint in self._get_dataset_from_last_update(self.DATA_SOURCE)["point"]:
File "/config/custom_components/google_fit/sensor.py", line 308, in _get_dataset_from_last_update
return self._client.users().dataSources(). \
File "/usr/local/lib/python3.8/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/googleapiclient/http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://fitness.googleapis.com/fitness/v1/users/me/dataSources/derived%3Acom.google.heart_rate.bpm%3Acom.google.android.gms%3Amerge_heart_rate_bpm/datasets/1620852120000000000-1620892504000000000?alt=json returned "Cannot read data of type com.google.heart_rate.bpm">
In the Google API I've got the scope of heartRate.read
and heartRate.write
enabled and all.
Configuration:
sensor:
- platform: google_fit
name: Google Fit
client_id: !secret google_client_id
client_secret: !secret google_client_secret
Hi, first of all thank you for this nice addon!
I have followed your guide to setup google fit, but i get the following error:
Error: Invalid response 400. Error: invalid_scope
You will need to restart hass after fixing.
I can read the google calendar, and the google fit api is enabled.
Do i miss something ?
Error logs...
2021-12-18 10:11:02 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_weight_lbs (<class 'custom_components.google_fit.sensor.GoogleFitWeightLbsSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:06 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform google_fit is taking over 10 seconds.
2021-12-18 10:11:08 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_weight_kg (<class 'custom_components.google_fit.sensor.GoogleFitWeightKGSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:08 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_heart_rate (<class 'custom_components.google_fit.sensor.GoogleFitHeartRateSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:12 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_height (<class 'custom_components.google_fit.sensor.GoogleFitHeightSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:12 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_steps (<class 'custom_components.google_fit.sensor.GoogleFitStepsSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:13 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_sleep (<class 'custom_components.google_fit.sensor.GoogleFitSleepSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:13 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_meditation (<class 'custom_components.google_fit.sensor.GoogleFitMeditationSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:14 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_move_time (<class 'custom_components.google_fit.sensor.GoogleFitMoveTimeSensor'>) implements device_state_attributes. Please report it to the custom component author.�������
2021-12-18 10:11:14 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_calories (<class 'custom_components.google_fit.sensor.GoogleFitCaloriesSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:14 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_distance_km (<class 'custom_components.google_fit.sensor.GoogleFitDistanceKmSensor'>) implements device_state_attributes. Please report it to the custom component author.
2021-12-18 10:11:15 WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.richard_distance_mi (<class 'custom_components.google_fit.sensor.GoogleFitDistanceMiSensor'>) implements device_state_attributes. Please report it to the custom component author.
2020-05-04 22:20:56 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.google_fit. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/loader.py", line 393, in _load_file
module = importlib.import_module(path)
File "/usr/local/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.google_fit\u200b'
Hi.
I've got
2021-05-09 13:42:52 ERROR (MainThread) [homeassistant.components.sensor] google_fit: Error on device update!
Traceback (most recent call last):
File "d:\program\python\python38\lib\site-packages\homeassistant\helpers\entity_platform.py", line 407, in _async_add_entity
await entity.async_device_update(warning=False)
File "d:\program\python\python38\lib\site-packages\homeassistant\helpers\entity.py", line 516, in async_device_update
await task
File "d:\program\python\python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "d:\program\python\python38\lib\site-packages\homeassistant\util\__init__.py", line 280, in wrapper
result = method(*args, **kwargs)
File "d:\program\python\python38\lib\site-packages\homeassistant\util\__init__.py", line 280, in wrapper
result = method(*args, **kwargs)
File "d:\User\.homeassistant\custom_components\google_fit\sensor.py", line 309, in update
weight_datasources = self._get_datasources('com.google.weight')
File "d:\User\.homeassistant\custom_components\google_fit\sensor.py", line 276, in _get_datasources
data = datasources_request.execute()
File "d:\User\.homeassistant\deps\Python38\site-packages\oauth2client\_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "d:\User\.homeassistant\deps\Python38\site-packages\googleapiclient\http.py", line 835, in execute
resp, content = _retry_request(
File "d:\User\.homeassistant\deps\Python38\site-packages\googleapiclient\http.py", line 163, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "d:\User\.homeassistant\deps\Python38\site-packages\oauth2client\transport.py", line 186, in new_request
credentials._refresh(orig_request_method)
File "d:\User\.homeassistant\deps\Python38\site-packages\oauth2client\client.py", line 756, in _refresh
self._do_refresh_request(http)
File "d:\User\.homeassistant\deps\Python38\site-packages\oauth2client\client.py", line 812, in _do_refresh_request
raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Bad Request
What am I doing wrong?
I have this integration enabled and configured:
- platform: google_fit
name: Google Fit
client_id: !secret google_calendar_client_id
client_secret: !secret google_calendar_client_secret
scan_interval: 300
Hi. Why I can't find this component in HACS?
What name does it have there?
I tried to add your repo as a custom URL in HACS and see this message:
An error ocoured while processing
Exception: HacsException
Message: Repostitory structure for master is not compliant
Could not add this repository, make sure it is compliant with HACS.
Is your repo meant to be added to HACS?
As of this month API for Sleep and Heartbeat is being updated. So we get no reading on those API
Installed via HACS, created a separate project on Google console and enabled the Fit API on it. Created my OAuth credentials and put them in secrets. Added config to sensors.yaml as shown:
- platform: google_fit
name: Google Fit
client_id: !secret gfit_client_id
client_secret: !secret gfit_client_secret
Restarted HA. Got authentication notification and completed all steps accordingly, receiving a success message at the end. Waited a bit, then went into Dev > States but I'm not seeing any sensors created. Did I miss something? I opened Fit on my phone and it's working and receiving daily data and I know I used the proper account for authentication... I must have missed something though as I don't have any sensors at all.
Great work with the integration. Would love to see ability to add more then one account. So far I'm successful with doing it the dirty way by multiplying integrating and renaming it to google fit 2 but its a headache to update.
For users having issues with the updated heart rate and sleep permissions:
I tried first adding the required scopes to the sensor.py
removing my token file but then I got a invalid_scope
error, I searched a bit, but couldn't figure out why.
After some more messing around I found a method that seems to work
Required;
Let's goo!
Go to oauthplayground
Click on "Step 1 Select & authorize APIs"
Scroll down to Fitness API v1
Normally all scopes should be enabled with read and write (this isn't fully needed, but I didn't had the time to fully figure out what needs to be enabled)
If not, these are the ones that worked for me:
Click on "Auhtorize APIs" and go trough the authorization steps
In step 2, click on Exchange authorization code for tokens
On the right you should see something like this:
copy the full json part on the bottom (with the access_token, scope, ...)
open your .<name>_google_fit.token
file. This should be on the same level as your configuration.yaml
file (I suggest you create a copy and format it, for easy working and having a backup)
Paste the copied json in the token_response
part (this should have the same keys, maybe different order)
Copy the full access_token
(yellow in reference screenshot), full refresh_token
(purple in reference screenshot) to the upper part of the json
Copy the following scopes (green in reference screenshot) to the scopes part (remove the ones you didn't authorize):
"scopes": [
"https://www.googleapis.com/auth/fitness.location.write",
"https://www.googleapis.com/auth/fitness.sleep.read",
"https://www.googleapis.com/auth/fitness.heart_rate.read",
"https://www.googleapis.com/auth/fitness.location.read",
"https://www.googleapis.com/auth/fitness.activity.read",
"https://www.googleapis.com/auth/fitness.body.write",
"https://www.googleapis.com/auth/fitness.activity.write",
"https://www.googleapis.com/auth/fitness.body.read",
"https://www.googleapis.com/auth/fitness.sleep.write",
"https://www.googleapis.com/auth/fitness.heart_rate.write"
],
Refrenced screenshot of my <name>.google_fit.token
file (not my full tokens obvisouly) :
I'm still waiting for a new token token to be generated, but this should give any issue (from my knowledge of these tokens, but then again I don't understand why the scope was giving issues)
Hello @vmanuel and friends...
First I would like to say thanks for this amazing work....
Now I will say my problem... actually I am trying do this both sensors work in my home asssistant, but I really not know more what I should to do... I have date from others sensors, less Heart and Sleep...
Could you help me?
Thank you, any suggest will be welcome!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.