Google Drive

This integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] allows you to connect your Google Drive with Home Assistant Backups.

When you set up this integration, your Google Drive will have a new folder called Home Assistant where all the backups will be stored. A separate folder is created for each of your Home Assistant instances. You can rename this folder to whatever you like in Google Drive at any point in time. If you delete the folder, it will automatically be re-created as long as you have the integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] enabled.

To open the backup folder, go to Settings > Devices & services > Google Drive, and select Visit.

For a video walkthrough of the setup instructions, see this video from 13:50 to 19:20

Prerequisites

You need to configure developer credentials to allow Home Assistant to access your Google Account. These credentials are the same as the ones for Google Sheets, Nest, YouTube, and Google Mail. These are not the same as Device Auth credentials previously recommended for Google Calendar.

Scenario 1: You already have credentials

In this case, all you need to do is enable the API:

  1. Go to the Google Cloud console Google Drive API .
  2. Confirm that the correct project is selected, then select Enable.
  3. Continue with the steps described in the Configuration section.

Scenario 2: You do not have credentials set up yet

In this case, you need to generate a client secret first:

To generate client ID and client secret

This section explains how to generate a client ID and client secret in the Google Cloud console.

  1. Go to the Google Cloud console.
  2. Select Create or select a project, then New project, enter a project name, and select Create.
  3. When the project opens, make sure it is selected in the console toolbar at the top. If it isn’t, select it.
  4. Go to Google Drive API , then select Enable.
  5. Go to the Branding page in the Google Auth Platform Console.
  6. If Google Auth Platform is not configured, select Get started:
    • Under App Information, enter an app name (for example, Home Assistant) and select your email address for User support email. Then select Next.
    • Under Audience, select External, then select Next.
    • Under Contact Information, enter your email address, then select Next.
    • Review the Google API Services User Data Policy. If you agree, select the check box, then select Continue and Create.
  7. In the left sidebar, select Branding:
    • Under App domain, enter https://home-assistant.io for Application home page, Application privacy policy link, and Application terms of service link.
    • Under Authorized domains, add home-assistant.io.
  8. In the left sidebar, select Audience:
    • Under Publishing status, select Publish app.

      Otherwise, your credentials will expire every 7 days.

    • If you leave the app in Testing, under Test users, select Add users, add your Google Account email address, then select Save.
  9. In the left sidebar, select Clients:
    • Select Create client.
    • For Application type, choose Web application and give the client a name (for example, Home Assistant Client).
    • Under Authorized redirect URIs, add https://my.home-assistant.io/redirect/oauth, then select Create.

      Note: This is not a placeholder. It is the URI that must be used.

  10. From the resulting dialog, take a note of the Client ID and Client Secret. You cannot retrieve it again after closing the dialog.
  • Once you have noted these strings, select Ok to close.
  • Congratulations! You are now the keeper of a client secret. Guard it in your treasure box. In most cases, your new credentials will be active within a few minutes. However, Google states that activation may take up to five hours in some circumstances.

Configuration

To add the Google Drive service to your Home Assistant instance, use this My button:

Manual configuration steps

If the above My button doesn’t work, you can also perform the following steps manually:

  • Browse to your Home Assistant instance.

  • Go to Settings > Devices & services.

  • In the bottom right corner, select the Add Integration button.

  • From the list, select Google Drive.

  • Follow the instructions on screen to complete the setup.

The integration setup will next give you instructions to enter the Application Credentials (OAuth Client ID and Client Secret) and authorize Home Assistant to connect to Google Drive.

OAuth and device authorization steps
  1. Continue through the steps of selecting the account you want to authorize.

  2. NOTE: You may get a message telling you that the app has not been verified and you will need to acknowledge that in order to proceed.

  3. You can now see the details of what you are authorizing Home Assistant to access with two options at the bottom. Select Continue.

  4. The page will now display Link account to Home Assistant?, note Your instance URL. If this is not correct, refer to My Home Assistant. If everything looks good, select Link Account.

  5. You may close the window, and return back to Home Assistant where you should see a Success! message from Home Assistant.

Sensors

The integration provides the following sensors, which are updated every 6 hours:

  • Total available storage: The storage limit, if applicable. This will be unknown if the user has unlimited storage.
  • Used storage: The total storage usage across all Google services.
  • Used storage in Drive: The usage by all files in Google Drive. This entity is disabled by default.
  • Used storage in Drive Trash: The usage by trashed files in Google Drive. This entity is disabled by default.
  • Total size of backups: The sum of the size of all backups for the current Home Assistant’s installation.

For users that are part of an organization with pooled storage, information about the available storage and used storage across all services is for the organization, rather than the individual user.

Examples

Get started with these automation examples.

Send alert when drive is near storage limit

Send an alert when the drive usage is close to the storage limit and needs clean up.

Example YAML configuration

Create an automation with the following code. Remember to replace your_email_gmail_com with the actual ID of your sensors (found in Settings > Devices & services > Entities) and replace notify.my_device with your actual notifier.

alias: Alert when Google Account is close to storage limit
description: Send notification to phone when drive needs clean up.
triggers:
  - trigger: template
    value_template: >
      {% set used = states('sensor.your_email_gmail_com_used_storage') | float(0) %}
      {% set total = states('sensor.your_email_gmail_com_total_available_storage') | float(0) %}
      {{ used > (total * 0.9) }}
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      title: Google Account is almost full!
      message: >
        Google Account has used up {{ states('sensor.your_email_gmail_com_used_storage') }}GB of {{
        states('sensor.your_email_gmail_com_total_available_storage') | float }}GB.

Removing the integration

To remove an integration instance from Home Assistant

  1. Go to Settings > Devices & services and select the integration card.
  2. From the list of devices, select the integration instance you want to remove.
  3. Next to the entry, select the three dots menu. Then, select Delete.
  • If you remove the integration, the backup folder in Google Drive is not automatically deleted. You have to manually delete it in Google Drive.

Known limitations

  • The integration can only access files that it creates in the backup folder. It cannot access or modify any other files in your Google Drive.

Troubleshooting

If you have an error with your credentials, you can delete them in the Application Credentials user interface.