Azure Event Hub
Azure Event Hub 集成允许您接入 Home Assistant 事件总线,并将事件发送到 Azure Event Hub 或 Azure IoT Hub。
首次设置
假设您已有 Azure 账户。否则,请在这里创建免费账户。
您需要创建一个 Event Hub 命名空间和该命名空间中的一个 Event Hub,您可以按照此指南操作。或者,您可以直接从这里部署包含命名空间和 Event Hub 的 ARM 模板。
然后,您必须为 Event Hub 创建一个具有"发送"声明的共享访问策略,或使用命名空间中的 RootManageAccessKey(此密钥具有额外的声明,包括管理事件中心和监听,这些对于此目的不需要),有关 Event Hub 安全性的更多详细信息,请访问这里。
一旦您拥有命名空间、实例、共享访问策略和该策略密钥的名称,您就可以设置集成本身。
另一种方法是使用连接字符串和实例名称,这可以以与共享访问策略相同的方式检索,也可以从 IoT Hub 中的设备获取(Event Hub 兼容的连接字符串)。在 IoT Hub 的情况下,您需要将设备 ID 作为实例名称。
最后需要考虑的是您希望集成多久以批处理方式向您的中心发送消息,这通过 send_interval 设置,默认为 5 秒。由于此组件以异步方式运行,无法保证发送完全按时发生,而且由于您的 Home Assistant 可能因大量事件发生而非常繁忙,它可能会丢弃超过 20 秒加上 send_interval 的旧事件。
此集成可通过 UI 配置。前往 设置 > 设备与服务 添加。
您可以通过 "configuration.yaml" 设置过滤器。
不过滤域或实体将把每个事件发送到 Azure Event Hub,从而占用大量空间和带宽。
::: :::note Event Hub 的保留时间最多为 7 天,如果您不捕获或使用事件,它们将自动从 Event Hub 中删除,默认保留期为 1 天。
过滤器配置
默认情况下,不会排除任何实体。要限制哪些实体被暴露给 Azure Event Hub,您可以使用 filter 参数。
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
在 Azure 中使用数据
有多种方式可以将进入 Event Hub 的数据流式传输到 Azure 的存储中,最简单的方法是使用内置的捕获功能,这允许您将数据捕获到 Azure Blob Storage 或 Azure Data Lake store,详细信息在这里。
Azure(及外部)的其他存储可以通过 Azure Stream Analytics 作业实现,例如 Cosmos DB、Azure SQL DB、Azure Table Storage、自定义写入 Azure Blob Storage 和 Topic 及 Queues。
在分析方面,Event Hub 可以直接输入到 Azure Databricks Spark、Azure Time Series Insights 和 Microsoft Power BI。
在 Azure 中使用数据的最后一种方法是使用 Event Hub 触发器绑定将 Azure Function 连接到 Event Hub。

