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.

配置

要将 Azure Event Hub integration 添加到您的 Home Assistant 实例中,请使用此 My 按钮:

手动配置步骤

如果上述 My 按钮不起作用,您也可以手动执行以下步骤:

You can setup filters through the configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more].

Warning

Not filtering domains or entities will send every event to Azure Event Hub, thus taking up a lot of space and bandwidth.

Note

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

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

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

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.