Google Calendar
Google Calendar integration 允许您将 Google 日历连接到 Home Assistant。该集成添加 calendar 实体,这些实体显示在日历仪表板上,可用于基于任何事件的自动化,或限于特定匹配条件。
前提条件
您需要配置开发者凭据以允许 Home Assistant 访问您的 Google 账户。当前推荐的方法是为 Google 日历创建 Web Auth 凭据,因为相同的凭据适用于所有 Google 集成。以前,此集成仅支持 Device Auth 凭据,这些凭据不再推荐。您可以继续使用 Device Auth 凭据,但它们仅适用于 Google 日历。
Scenario 1: You already have credentials
In this case, all you need to do is enable the API:
- Go to the Google Developers Console Google Calendar API.
- Confirm the project and select Enable for the API.
- 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 Developers Console.
- First, go to the Google Developers Console to enable Google Calendar API.
- Select Create project, enter a project name, and select Create.
- Enable Google Calendar 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 配置。前往 设置 > 设备与服务 添加。
The integration setup then gives you instructions to enter the Application Credentials and authorize Home Assistant to connect to Google Calendar.
OAuth and device authorization steps
- 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.
故障排除
如果设置过程失败并且您看到错误消息,例如身份验证代码已过期,请重试,您可能需要重新尝试流程。您还可以检查日志中的其他错误消息,这些消息可能指示配置错误,例如无效的客户端 ID 或密钥。
如果您的凭据有错误,您可以在应用程序凭据用户界面中删除它们。
视频教程
此视频教程介绍了如何在 Home Assistant 中设置 Google 日历以及如何根据日历事件触发自动化。
日历实体
我的日历中的每个 Google 日历(更多信息)在 Home Assistant 中表示为日历实体。
例如,您名为 Personal 的日历将创建为实体 calendar.personal。您可以重命名实体,或禁用任何您不需要的实体。
日历事件自动化
单个日历事件是为自动化提供支持的内容,例如:
- 在名为 前院灯 的事件开始时打开灯
- 在任何事件开始前 5 分钟发送通知
- 在名为 锻炼 的事件结束 30 分钟后停止媒体播放器。
有关概述,请参阅日历自动化,并阅读有关日历触发变量的更多信息,了解您可以在条件或动作中使用的可用信息,如事件 summary、description、location 等。
日历实体属性
日历实体具有与单个下一个即将发生的事件相关的额外属性。
使用实体状态和属性比使用日历自动化更容易出错且灵活性较低。日历实体本身可能只跟踪单个即将发生的活动事件,无法处理具有相同开始时间的多个事件或重叠事件。
属性
- all_day:如果这是全天事件则为
true/false。如果没有找到事件则为false。 - message:事件摘要。
- description:事件描述。
- location:事件位置。
- start_time:事件开始时间。
- end_time:事件结束时间。
动作:创建事件
google.create_event 动作允许您在日历中创建新的日历事件。
创建事件动作详情
:::note
只有在配置选项中授予了 Home Assistant read-write 访问权限,此功能才可用。
:::
使用目标选择器选择日历 target,data 负载支持以下字段:
:::important
您要么使用 start_date_time 和 end_date_time,要么使用 start_date 和 end_date,要么使用 in。
::: 这是 YAML 中动作的完整示例:
更多配置
更多配置
:::warning 不建议新用户使用这些设置,因为它们与其他 Home Assistant 功能不兼容,但此文档可供现有用户使用。
:::
集成支持从 google_calendars.yaml 文件进行额外配置,该文件适用于 2022.06 之前的现有用户。此文件不再自动填充。

