IvanVojtko / googlefit-homeassistant

MIT License
27 stars 10 forks source link

Error while setting up google_fit platform for sensor #8

Open mr-biz opened 2 years ago

mr-biz commented 2 years ago

Hi! Thank you for creating Googlefit-HomeAssistant. I really would like to have Google Fit data for my family in Home Assistant. This allows for automation to be based upon combinations of criteria such as only allowing children Internet access after they have satisfied a number of criteria. So would like to ask, can Googlefit-HomeAssistant be used for more than one person?

The instructions would benefit from some revision to make them more accessible to a less knowledgeable audience. I have documented my journey and troubleshooting so far. I have enabled the Google Fit API. How do I "Add all Fitness API read scopes"? I downloaded a clientsecret...apps.googleusercontent.com.json is that the correct one? How do I run get_credentials.py?

I created the credentials but HomeAssistant is having errors on startup.

mr-biz commented 2 years ago

It seems that the HACS installation did not install get_credentials.py. So I used a Ubuntu VM to: git clone https://github.com/IvanVojtko/googlefit-homeassistant.git sudo apt install python3-pip

Copied the Google Fit credentials to my VM....then... cp client_secret_blahblahblah.json credentials.json python3 get_credentials.py

Hey Presto! I am provided a URL and pasted into browser -> 2OUATH -> Add all Fitness API read scopes. Now prompted, "Please copy .google_fit.token to your HA configuration directory"

Now back to Home Assistant!

mr-biz commented 2 years ago

I copied .google_fit.token to /root/config/custom_components/google_fit

In configuration.yaml I placed:

sensor:

I restarted Home Assistant and in the logs I got:

2022-02-08 18:22:34 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up google_fit platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform await asyncio.shield(task) File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/google_fit/sensor.py", line 212, in setup_platform setup(hass, config) File "/config/custom_components/google_fit/sensor.py", line 146, in setup return do_authentication(hass, config) File "/config/custom_components/google_fit/sensor.py", line 160, in do_authentication client_id=config[CONF_CLIENT_ID], KeyError: 'client_id'

mr-biz commented 2 years ago

image

rpitera commented 2 years ago

I copied .google_fit.token to /root/config/custom_components/google_fit

I'm having my own issues with installing it and agree about more accessible instructions. But I noticed this line in your thread and the token file should actually be placed in the root of your config directory. - in your case it should be in /root/config.

I'm wondering about this token file though; I've used other GFit integrations in the past and they were working fine until recent changes to the API. But the token files generated look nothing like the one I got as outputted by the get_credentials.py script. My past token files have been in JSON format, but the one the script generated is definitely NOT JSON formatted. I can provide a redacted example if it helps the dev out.

mr-biz commented 2 years ago
mr-biz commented 2 years ago

I'm wondering about this token file though; I've used other GFit integrations in the past and they were working fine until recent changes to the API. But the token files generated look nothing like the one I got as outputted by the get_credentials.py script. My past token files have been in JSON format, but the one the script generated is definitely NOT JSON formatted. I can provide a redacted example if it helps the dev out.

Did you take a look at the closed issue? https://github.com/IvanVojtko/googlefit-homeassistant/issues/6 OP's concern looks similar to your own.

rpitera commented 2 years ago

Thanks, but my token is more like the one in issue #7 . I replied in that thread as well as the reddit topic the dev started. Hoping to hear something on either front. I'm glad that I had at least one small victory, even if it wasn't on my setup though! LOL

IvanVojtko commented 2 years ago

Hey @mr-biz and @rpitera. I've updated a readme file. Google changed some stuff in oauth 2 so I updated my script to generate token but also you need to generate a new OAuth 2 credentials and set your device as Desktop, otherwise it will not work.

Just go here https://console.cloud.google.com/apis/api/fitness.googleapis.com and click on Credentials image On a next screen click Create credentials and select Oauth client ID image Application type should be Desktop app and name whatever you like image Download a JSON file, rename it to credentials.json, copy it to the same directory as get_credentials.py, run the script. It should automatically open a new tab in a browser. Grant all permissions and you should end up with correct .google_fit.token file.