Google Drive
此集成允许您将 Google Drive 与 Home Assistant 备份连接。设置此集成时,您的 Google Drive 将有一个名为 Home Assistant 的新文件夹,所有备份都将存储在其中。要打开此文件夹,请前往 设置 > 设备与服务 > Google Drive,然后选择 访问。您可以随时在 Google Drive 中将此文件夹重命名为您喜欢的任何名称。如果您删除该文件夹,只要集成启用,它将自动重新创建。
有关设置说明的视频演示,请观看此视频从 13:50 到 19:20
前提条件
您需要配置开发者凭据以允许 Home Assistant 访问您的 Google 账户。 这些凭据与 Google Sheets、Nest、YouTube 和 Google Mail 的凭据相同。 这些与之前为 Google Calendar 推荐的 设备授权 凭据不同。
场景 1:您已有凭据
这种情况下,您只需要启用 API:
- 前往 Google Developers Console 中的 Google Drive API。
- 确认项目后,为 API 选择 启用。
- 继续按照配置部分中的步骤操作。
场景 2:您尚未设置凭据
这种情况下,您需要先生成客户端密钥:
生成客户端编号和客户端密钥
本节说明如何在 Google Developers Console 中生成客户端 ID 和客户端密钥。
- First, go to the Google Developers Console to enable Google Drive API.
- Select Create project, enter a project name, and select Create.
- Enable Google Drive API.
- Navigate to APIs & Services > Credentials.
- In the left sidebar, select OAuth consent screen.
- Complete the app information and create the consent screen.
- Under Publishing status > Testing, select Publish app.
- In the left sidebar, select Clients and create a Web application client.
- Add
https://my.home-assistant.io/redirect/oauthto Authorized redirect URIs and select Create. - Copy the Client ID and Client Secret before closing the dialog.
此集成可通过 UI 配置。前往 设置 > 设备与服务 添加。
随后,集成设置流程会引导您输入应用程序凭据,并授权 Home Assistant 连接到 Google Drive。
账户授权步骤
- Continue through the steps of selecting the account you want to authorize.
- You may get a message telling you that the app has not been verified and that you need to acknowledge it to proceed.
- Review what Home Assistant is requesting access to, then select Continue.
- When the page displays Link account to Home Assistant?, confirm that Your instance URL is correct, then select Link Account.
- You can close the window and return to Home Assistant, where you should see a Success! message.
传感器
集成提供以下传感器,每 6 小时更新一次:
- 总可用存储空间:存储限制(如适用)。如果用户有无限存储空间,这将显示为未知。
- 已用存储空间:所有 Google 服务的总存储使用量。
- Drive 已用存储空间:Google Drive 中所有文件的使用量。此实体默认禁用。
- Drive 回收站已用存储空间:Google Drive 中已删除文件的使用量。此实体默认禁用。
- 备份总大小:当前 Home Assistant 安装的所有备份大小之和。
对于属于具有共享存储空间的组织的用户,有关所有服务的可用存储空间和已用存储空间的信息是针对组织的,而不是针对个人用户的。
示例
从这些自动化示例开始。
当云盘接近存储限制时发送警报
当云盘使用量接近存储限制并需要清理时发送警报。
配置示例
使用以下代码创建自动化。请记得将 your_email_gmail_com 替换为您传感器的实际 ID(在 设置 > 设备与服务 > 实体 中找到),并将 notify.mobile_app_your_device 替换为您的实际通知器。
移除集成
从 Home Assistant 中移除集成实例
- 前往 设置 > 设备与服务,然后选择该集成卡片。
- 在设备列表中,选择您要删除的集成实例。
- 在该条目旁边,选择三点菜单
,然后选择 删除。
- 如果您移除集成,Google Drive 中的 Home Assistant 文件夹不会自动删除。您必须在 Google Drive 中手动删除它。
已知限制
- 集成只能访问它在 Home Assistant 文件夹中创建的文件。它无法访问或修改您 Google Drive 中的任何其他文件。
故障排除
如果您的凭据有错误,您可以在 应用凭据 用户界面中删除它们。

