Google Sheets
Google Sheets 集成允许您将 Google Drive 连接到 Home Assistant。该集成添加了一个动作,允许您向 Sheets 文档追加行。其思想是您可以在那里存储数据以供进一步处理。当您设置配置条目时,您的云端硬盘将有一个名为 Home Assistant 的新表格。然后您可以将其重命名为您喜欢的任何名称。
注意: 该集成目前只能访问在设置期间创建的那一个文档。
前提条件
您需要配置开发者凭据以允许 Home Assistant 访问您的 Google 账户。 这些凭据与 Nest、YouTube 和 Google Mail 的凭据相同。 这些与之前为 Google Calendar 推荐的 Device Auth 凭据不同。
场景 1:您已有凭据
这种情况下,您只需要启用 API:
- 前往 Google Developers Console 中的 Google Drive API 和 Google Sheets API。
- 确认项目后,为 API 选择 启用。
- 继续按照配置部分中的步骤操作。
场景 2:您尚未设置凭据
这种情况下,您需要先生成客户端密钥:
生成客户端编号和客户端密钥
本节说明如何在 Google Developers Console 中生成客户端 ID 和客户端密钥。
- First, go to the Google Developers Console to enable Google Drive API and Google Sheets 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 Sheets。
账户授权步骤
- 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.
故障排除
如果您的凭据出现错误,可以在应用程序凭据用户界面中删除它们。
视频教程
此视频教程说明了如何设置 Google Sheets 集成以及如何将数据从 Home Assistant 添加到 Google Sheet。
动作:追加表格
google_sheets.append_sheet 动作允许您向设置时创建的 Sheets 文档添加数据行。
动作详情
动作:获取表格
您可以使用 google_sheets.get_sheet 动作从 Sheets 文档中检索数据行。

