Google Calendar Constantly Losing Authentication

Hello

Every couple days my Google Calendar integration stops working. I delete the .google.token file, reboot HA, re-enter the code at google site when prompted and it works. Couple days later - same thing.

Is this normal behavior? Anything I can do to keep the authorization working longer?

Thanks!

Same has been happening here over the 3-4 weeks. I get about 5-7 days out of the authorization and then I have to repeat the process again.

Quick and dirty workaround - run this shell_command once in a while (I have an automation which does this every half an hour):

shell_command:
  google_token: sed -i -e 's/2client.client"}2client.client"}/2client.client"}/g' /config/.google.token

More info:

1 Like

I’ll try it, thanks!

Hi

Got the shell command working and can see the .google.token file is updated every night.

But still have the issue, that i need to re-authenticate. Any ideas?

The trailing stuff changes over time - I had to adapt my shell_command multiple times. At the moment I have this:

google_token: >-
    sed -i -e 's/odule": "oauth2client.client"}odule": "oauth2client.client"}/odule": "oauth2client.client"}/g' /config/.google.token &
    sed -i -e 's/ule": "oauth2client.client"}ule": "oauth2client.client"}/ule": "oauth2client.client"}/g' /config/.google.token

Meanwhile I run that command every minute, because the error happened more often during the day. As I’m using HA on an Intel NUC, running the script often is not a performance issue for me - but still silly, of course…

2 Likes

[nicohirsch]
Please, can you share exactly how to implement this automation with the script?, and screen caputre for example to show how to implement?.

Thanks,

So if the error happens before the shell command fires, you cannot fix it or are you running it so often, just to be sure you never expereience the error?

@josemsubcn Just copy this into your configuration.yaml:

shell_command:
  google_token: >-
    sed -i -e 's/odule": "oauth2client.client"}odule": "oauth2client.client"}/odule": "oauth2client.client"}/g' /config/.google.token &
    sed -i -e 's/ule": "oauth2client.client"}ule": "oauth2client.client"}/ule": "oauth2client.client"}/g' /config/.google.token

Then reboot - and after that you can create an automation like this:

@Martin_Pejstrup I have a wall dashboard with mutiple Google calendars in nearly every room - maybe because of the many calendar requests the error happened very often. That’s why I fire it so often - since then I never had an error showing on my dashboards.

Dear nicohirsch thanks for the help, but I continue to have some errors in the log about the calendar…

> Logger: homeassistant.components.calendar
> Source: components/google/calendar.py:175
> Integration: Calendario (documentation, issues)
> First occurred: 22:38:34 (1 occurrences)
> Last logged: 22:38:34
> 
> google: Error on device update!
> Traceback (most recent call last):
>   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_add_entity
>     await entity.async_device_update(warning=False)
>   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, 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/components/google/calendar.py", line 106, in update
>     self.data.update()
>   File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 285, in wrapper
>     result = method(*args, **kwargs)
>   File "/usr/src/homeassistant/homeassistant/components/google/calendar.py", line 175, in update
>     result = events.list(**params).execute()
>   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 404 when requesting https://www.googleapis.com/calendar/v3/calendars/616jclechijai43018fn6rr4m57e0mio%40import.calendar.google.com/events?orderBy=startTime&maxResults=5&singleEvents=true&timeMin=2021-03-03T22%3A38%3A34.772729%2B01%3A00&alt=json returned "Not Found">

Probably is by other problem…?

Thanks

@josemsubcn That seems to be another problem, but sadly I don’t have a solution for that one.