Google Pub/Sub

The google_pubsub integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] allows you to hook into the Home Assistant event bus and send events to Google Cloud Pub/Sub. The current free tier of GCP should allow you to sync about 1 event every 2 seconds on average (2 million invocations per month).

First time setup

This assumes you already have a Google Cloud project. If you don’t, please create one in the Google Cloud Console

Create a Google Pub/Sub topic in the Google Cloud API Console. The topic name will become something like projects/project-198373/topics/topic-name. Note the last part only (the name you chose): topic-name.

Next, you need to create a Service Account key in the Google Cloud API Console

  • Choose a new “New Service Account”, give it a name and leave the key type as JSON
  • Select the role: Pub/Sub Publisher

This will download the Service Account JSON key to your machine. Do NOT share this with anyone. Place this file in your Home Assistant configuration folder.

Configuration

Add the following lines to your configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] file. 在更改了configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 文件后,重启 Home Assistant 以应用更改。

# Example configuration.yaml entry
google_pubsub:
  project_id: YOUR_PROJECT_ID
  topic_name: YOUR_TOPIC_NAME
  credentials_json: CREDENTIALS_FILENAME

Configuration Variables

project_id string Required

Project ID from the Google console (looks like words-2ab12).

topic_name string Required

The Pub/Sub relative topic name (looks like hass).

credentials_json string Required

The filename of the Google Service Account JSON file.

filter map Required

Filter domains and entities for Google Cloud Pub/Sub. (Configure Filter)

include_domains list (Optional)

List of domains to include (e.g., light).

exclude_domains list (Optional)

List of domains to exclude (e.g., light).

include_entity_globs list (Optional)

Include all entities matching a listed pattern (e.g., sensor.weather_*).

exclude_entity_globs list (Optional)

Exclude all entities matching a listed pattern (e.g., sensor.weather_*).

include_entities list (Optional)

List of entities to include (e.g., light.attic).

exclude_entities list (Optional)

List of entities to include (e.g., light.attic).

Important

Not filtering domains or entities will send every event to Google PubSub, thus hitting the free tier limit very fast. Be sure to fill in this configuration parameter or have a paid subscription for Google Cloud.

Configure filter

By default, no entity will be excluded. To limit which entities are being exposed to Google Pub/Sub, you can use the filter parameter.

# Example filter to include specified domains and exclude specified entities
google_pubsub:
  project_id: YOUR_PROJECT_ID
  topic_name: YOUR_TOPIC_NAME
  credentials_json: CREDENTIALS_FILENAME
  filter:
    include_domains:
      - alarm_control_panel
      - light
    include_entity_globs:
      - binary_sensor.*_occupancy
    exclude_entities:
      - light.kitchen_light

Filters are applied as follows:

  1. 不使用过滤器
    • 包含所有实体
  2. 仅包含
    • 实体列表中的实体包含:include
    • 否则,实体匹配域包含:include
    • 否则,实体匹配通配符包含:include
    • 否则:排除
  3. 仅排除
    • 实体列表中的实体排除:exclude
    • 否则,实体匹配域排除:exclude
    • 否则,实体匹配通配符排除:exclude
    • 否则:包含
  4. 域和/或通配符包含(还可能有排除)
    • 实体列表中的实体包含:include
    • 否则,实体列表中的排除:exclude
    • 否则,实体匹配通配符包含:include
    • 否则,实体匹配通配符排除:exclude
    • 否则,实体匹配域包含:include
    • 否则:排除
  5. 域和/或通配符排除(没有域和/或通配符包含)
    • 实体列表中的实体包含:include
    • 否则,实体列表中的排除:exclude
    • 否则,实体匹配通配符排除:exclude
    • 否则,实体匹配域排除:exclude
    • 否则:包含
  6. 没有域和/或通配符的包含或排除
    • 实体列表中的实体包含:include
    • 否则:排除

以下字符可用于实体通配符:

* - 星号表示零个、一个或多个字符
? - 问号表示零个或一个字符

Saving the data using a Google Cloud Function

To save your data automatically to BigQuery, follow the instructions here. The current free tier of GCP should allow to store up to 10GB of data.