How to integrate Google Calendar with Home Assistant
Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.
This guide will show you how to integrate Google Calendar with Home Assistant in detail. This integration has many benefits, and events from your Google Calendar can be used in automations and scripts. Another possible use is to display the calendar using the beautiful Calendar Card that is an official part of the Home Assistant Lovelace dashboard.
While there is a guide on how to integrate Google Calendar with Home Assistant on the website, it is rather bare-bones. There are no screenshots and now solutions to frequent issues. For that reason, I have decided to set up and document the process to help you do the same.
Unfortunately, the integration of Google Calendar with Home Assistant isn't as easy as copy/pasting your calendars URL or clicking a few buttons in the dashboard. To make the integration possible, you are required to go through numerous steps.
This integration doesn't start in Home Assistant or the configuration.yaml file. Instead, you will first be heading to the Google Cloud Platform. Just as I was, you might not be familiar with this complex looking platform. However, there is not much you can do wrong if you follow the steps.
Create a new Google Cloud Platform project
The first step is to either create a new project in the Google Cloud Platform, or select an existing one. To cover all bases and make this guide as extensive as possible, I am creating a new project. If you have already created a project for a previous integration, I recommend using that one. That way, you won't have an individual project for every integration that might need the Google Cloud Platform.
After creating or selecting a project, a confirmation message announcing that the API has been enabled should appear. Click on the button labelled Go to credentials to continue.
Product
CanaKit Raspberry Pi 4 Extreme Kit - Aluminum Edition
GeeekPi Raspberry Pi 4 8GB Starter Kit
CanaKit Raspberry Pi 4 4GB Starter PRO Kit
CanaKit Raspberry Pi 4 Basic Kit
Model
Raspberry Pi 4 Model B (8 GB)
Raspberry Pi 4 Model B (8 GB)
Raspberry Pi 4 Model B (4 GB)
Raspberry Pi 4 Model B (8 GB)
PSU
Power supply with noise filter
USB-C power supply (5V/3.6A)
Power supply with noise filter
Power supply with noise filter
Accessories
Premium Aluminum Case with Built-In Passive Heat Sink Cooling
Case; cooling fan wit four aluminium heatsinks, 64 GB microSD card, two HDMI cables
Premium High-Gloss Case with Integrated Fan Mount, Low Noise Bearing System Fan
Leave the API set to the Google Calendar API. As this integration doesn't gather any third party's user data, the option application data is sufficient. And as the integration of Google Calendar with Home Assistant doesn't require access to any other services, you can select no in the final question.
After you have clicked next, you will be taken to the service account details. Here you will have to give your account a name. As you can see, I went for the obvious. You will also be assigned an account identification and, if you wish to do so, you can add an account description.
You can simply click yourself through part two and three, as nothing has to be changed and both parts are optional. Once complete, click on the button labelled done one final time.
Generating a Client ID and Client Secret for Home Assistant
Unfortunately, the Google Calendar integration with Home Assistant isn't complete yet. There are several further steps in the Google Cloud Console you will need to go through, before switching to Home Assistant. Once you click done in the previous step, you will be redirected to the APIs and services settings. Here you will need to configure a consent screen before moving on.
Once selected, choose the user type external and continue by clicking on the button labelled create. You are next required to enter a few details on your “app” (don't be confused by the naming). Give the app a name, a good choice would be Home Assistant, and enter your email as the user support email. The app logo is, luckily, optional. Fill in any other required information before moving on.
As we won't be using any scopes, you can skip the next step by clicking on save and continue. Finally, add your email as a test user. With that, the consent screen configuration is complete, and you can move on.
Creating credentials for the Google Calendar integration with Home Assistant
It is now finally time to create credentials, which allow Home Assistant to integrate with Google Calendar and fetch events. After completing the previous step, you should be redirected back to the APIs and services page. From there, select the option to create credentials and choose OAuth client ID.
Select the application type TVs and Limited Input devices from the dropdown and give it a name. This choice might not make any sense, but it is the correct one. As for the name, I once again recommend you enter something you will be able to recognize later, for example, Home Assistant Credentials. To finish things off, you will need to click on create.
A pop-up displaying your client identification and client secret will appear. Do not close this pop-up until you have copied both in to an external editor, as they will be needed later on. If you do accidentally close this pop-up, you will be able to find them in the credentials overview. Simply click on the pencil icon, and they will be displayed on the right-hand side. You must never share these credentials with anyone. If you have done so, delete the credentials immediately and create a new identification and secret.
Give your application a recognizable name.Copy both the Client ID and Client Secret from this pop-up.By clicking on the pencil icon, you can view your Home Assistant credentials.
Making sure the Google Calendar API is enabled
To save yourself from a future headache, it is recommended you double-check whether the Google Calendar API has been enabled by clicking on Library in the left-hand menu.
In the library, search for and select the Google Calendar API. If you have followed this guide correctly, you should see a green tick and the message API Enabled. If not, enable the API here.
If the tick is green, the Google Calendar API is enabled.
How to integrate Google Calendar with Home Assistant
I have good news for you: the integration of Google Calendar with Home Assistant is now almost complete. To finish things off, add the following three lines, which you should have saved in your text editor, to your configuration.yaml file:
As the client identification and secret strings are highly confidential, I recommend storing them in your secrets.yaml file, and not directly in the configuration file. There are two further optional options that can be configured:
By adding track_new_calendar: false, new calendars added to your Google Calendar account won't be tracked and integrated with Home Assistant. You can select which calendars shall be tracked later on, so I would not include this variable and leave it set to default.
The line calendar_access: read_only will not grant Home Assistant the right to create new events or modify existing ones. When set to read-only, you will not be able to have events created by automations or scripts. If you want to do more than only display your Google Calendar, you will need to remove this line.
Once complete, it is simply a case of restarting Home Assistant and waiting for the authentication notification to appear. As of writing, there is however an issue that will likely prevent that from happening.
Google Calendar authentication code expired
There is a possibility that once Home Assistant has started again, an error message, stemming from the Google Calendar integration, will appear. This error message reads:
“Authentication code expired, please restart Home Assistant and try again”
However, no matter how many times you restart Home Assistant, the same message will continually appear. Thankfully, there is a workaround that has been published on GitHub: Enter the general settings and set your time zone to Etc/GMT. After saving the settings, restart Home Assistant and a notification prompting you to complete the authentication should appear. Simply click on the link in that notification, follow the steps, and enter your code.
Once the Google Calendar integration with Home Assistant setup is complete, you can change the time zone back to what you previously had set. The integration will continue working as expected.
An error message that is frequently displayed when trying to integrate Google Calendar with Home Assistant.The setting can be changed after the final step required for the Google Calendar integration with Home Assistant.
Configuring individual Google Calendars
At this point, the Google Calendar integration with Home Assistant should be complete, and you should be able to see your individual calendars in the developer options. Additionally, Home Assistant will have created a new file with the name google_calendars.yaml. You can find this file in the same folder as the configuration.yaml file.
Within this YAML file, you will find all the calendars stored in your Google Calendar account. There are several variables that can be customized using basic YAML. Just make sure you never change the cal_id, or things will stop working.
Required variables for the Google Calendar integration with Home Assistant
The name (what you see in the frontend) and device_id (what your scripts and automations will use) can be changed to your liking. Both are required.
By setting the variable track: to false, you can have Home Assistant ignore that specific calendar. For example, in the code posted above, I would set the weather calendar to not be tracked, as I already have an integration with MeteoSwiss set up in Home Assistant. You are required to keep this variable, whether you change it or not, in the configuration.
Optional variables for the Google Calendar integration with Home Assistant
By using ignore_availability, you can instruct Home Assistant to respect the free/busy flag in Google Calendar, or not.
The variable max_results allows you to set how many calendar events will be fetched by Home Assistant. The default setting is 5. If you wish to have more events fetched, you can increase this number.
Using search, you can include events that only have a certain term in their title. For example, if you wanted a calendar that will only track the days you have to put the bins out, you could set it to search: bins. If “bins” is also included in the events title, it will only display those events.
Finally, you can set an offset to pre-trigger the state change on the sensor. If you wanted the sensor to change half an hour before the event, you would have to add offset: !!-30. If you wanted it to change one and a half hours beforehand, you can use offset: !!-01:30.
About Liam Alexander Colman
Liam Alexander Colmanis an experienced Home Assistant user who has been utilizing the platform for a variety of projects over an extended period. His journey began with a Raspberry Pi, which quickly grew to three Raspberry Pis and eventually a full-fledged server. Liam's current operating system of choice is Unraid, with Home Assistant comfortably running in a Docker container. With a deep understanding of the intricacies of Home Assistant, Liam has an impressive setup, consisting of various Zigbee devices, and seamless integrations with existing products such as his Android TV box. For those interested in learning more about Liam's experience with Home Assistant, he shares his insights on how he first started using the platform and his subsequent journey.