Google Pub/Sub
The google_pubsub
integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] allows you to hook into the Home Assistant event bus and send events to Google Cloud Pub/Sub
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 Consoleprojects/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.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes.
# Example configuration.yaml entry
google_pubsub:
project_id: YOUR_PROJECT_ID
topic_name: YOUR_TOPIC_NAME
credentials_json: CREDENTIALS_FILENAME
Configuration Variables
The Pub/Sub relativehass
).
Filter domains and entities for Google Cloud Pub/Sub. (Configure Filter)
Include all entities matching a listed pattern (e.g., sensor.weather_*
).
Exclude all entities matching a listed pattern (e.g., sensor.weather_*
).
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:
- No filter
- All entities included
- Only includes
- Entity listed in entities include: include
- Otherwise, entity matches domain include: include
- Otherwise, entity matches glob include: include
- Otherwise: exclude
- Only excludes
- Entity listed in exclude: exclude
- Otherwise, entity matches domain exclude: exclude
- Otherwise, entity matches glob exclude: exclude
- Otherwise: include
- Domain and/or glob includes (may also have excludes)
- Entity listed in entities include: include
- Otherwise, entity listed in entities exclude: exclude
- Otherwise, entity matches glob include: include
- Otherwise, entity matches glob exclude: exclude
- Otherwise, entity matches domain include: include
- Otherwise: exclude
- Domain and/or glob excludes (no domain and/or glob includes)
- Entity listed in entities include: include
- Otherwise, entity listed in exclude: exclude
- Otherwise, entity matches glob exclude: exclude
- Otherwise, entity matches domain exclude: exclude
- Otherwise: include
- No Domain and/or glob includes or excludes
- Entity listed in entities include: include
- Otherwise: exclude
The following characters can be used in entity globs:
*
- The asterisk represents zero, one, or multiple characters
?
- The question mark represents zero or one character
Saving the data using a Google Cloud Function
To save your data automatically to BigQuery, follow the instructions here