Azure Event Hub


The Azure Event Hub integration allows you to hook into the Home Assistant event bus and send events to Azure Event Hub or to a Azure IoT Hub.

First time setup

This assumes you already have a Azure account. Otherwise create a Free account here.

You need to create a Event Hub namespace and a Event Hub in that namespace, you can follow this guide. Alternatively you can directly deploy an ARM template with the namespace and the Event Hub from here.

You must then create a Shared Access Policy for the Event Hub with ‘Send’ claims or use the RootManageAccessKey from your namespace (this key has additional claims, including managing the event hub and listening, which are not needed for this purpose), for more details on the security of Event Hubs go here.

Once you have the name of your namespace, instance, Shared Access Policy and the key for that policy, you can setup the integration itself.

Configuration

Add the following lines to your configuration.yaml file:

# Example configuration.yaml entry
azure_event_hub:
  event_hub_namespace: NAMESPACE_NAME
  event_hub_instance_name: EVENT_HUB_INSTANCE_NAME
  event_hub_sas_policy: SAS_POLICY_NAME
  event_hub_sas_key: SAS_KEY
  filter:
    include_domains:
    - homeassistant
    - light
    - media_player

Configuration Variables

event_hub_namespace

(string)(Required)

The name of your Event Hub namespace.

event_hub_instance_name

(string)(Required)

The name of your Event Hub instance.

event_hub_sas_policy

(string)(Required)

The name of your Shared Access Policy.

event_hub_sas_key

(string)(Required)

The key for the Shared Access Policy.

filter

(map)(Required)

Filter domains and entities for Event Hub.

Default value:

Includes all entities from all domains

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_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).

Not filtering domains or entities will send every event to Azure Event Hub, thus taking up a lot of space.
Event Hubs have a retention time of at most 7 days, if you do not capture or use the events they are deleted automatically from the Event Hub, the default retention is 1 day.

Using the data in Azure

There are a number of ways to stream the data that comes into the Event Hub into storages in Azure, the easiest way is to use the built-in Capture function and this allows you to capture the data in Azure Blob Storage or Azure Data Lake store, details here.

Other storages in Azure (and outside) are possible with a Azure Stream Analytics job, for instance for Cosmos DB, Azure SQL DB, Azure Table Storage, custom writing to Azure Blob Storage and Topic and Queues.

On the analytical side, Event Hub can be directly fed into Azure Databricks Spark, Azure Time Series Insights and Microsoft Power BI.

The final way to use the data in Azure is to connect a Azure Function to the Event Hub using the Event Hub trigger binding.