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 an Azure IoT Hub.

First time setup

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

You need to create an Event Hub namespace and an 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.

The alternative approach is to use a connection string and instance name, this can be retrieved in the same way as the Shared Access Policy and this can also be gotten for a device in an IoT Hub (Event Hub-compatible connection string). In the case of IoT Hub, you need to put the Device ID as the instance name.

The final thing to consider is how often you want the integration to send messages in a batch to your hub, this is set with the send_interval, with a default of 5 seconds. Since this component runs in an asynchronous way there is no guarantee that the sending happens exactly on time, and because your Home Assistant might be very busy with lots of events happening it might discard several events that are older then 20 seconds plus the send_interval.

Configuration

Adding Azure Event Hub to your Home Assistant instance can be done via the user interface, by using this My button:

Manual configuration steps

You can setup filters through the configuration.yaml.

Not filtering domains or entities will send every event to Azure Event Hub, thus taking up a lot of space and bandwidth.
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.

Filter Configuration

By default, no entity will be excluded. To limit which entities are being exposed to Azure Event Hub, you can use the filter parameter.

# Example filter to include specified domains and exclude specified entities
azure_event_hub:
  filter:
    include_domains:
      - alarm_control_panel
      - light
    include_entity_globs:
      - binary_sensor.*_occupancy
    exclude_entities:
      - light.kitchen_light

Filters are applied as follows:

  1. No includes or excludes - pass all entities
  2. Includes, no excludes - only include specified entities
  3. Excludes, no includes - only exclude specified entities
  4. Both includes and excludes:
    • Include domain and/or glob patterns specified
      • If domain is included, and entity not excluded or match exclude glob pattern, accept
      • If entity matches include glob pattern, and entity does not match any exclude criteria (domain, glob pattern or listed), accept
      • If domain is not included, glob pattern does not match, and entity not included, reject
    • Exclude domain and/or glob patterns specified and include does not list domains or glob patterns
      • If domain is excluded and entity not included, reject
      • If entity matches exclude glob pattern and entity not included, reject
      • If entity does not match any exclude criteria (domain, glob pattern or listed), accept
    • Neither include or exclude specifies domains or glob patterns
      • If entity is included, accept (as #2 above)
      • If entity include and exclude, the entity exclude is ignored

The following characters can be used in entity globs:

* - The asterisk represents zero, one, or multiple characters ? - The question mark represents a single character

Configuration Variables

filter map (Optional)

Filter domains and entities for Event Hub.

Default:

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

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 an 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 an Azure Function to the Event Hub using the Event Hub trigger binding.