---
title: Home Assistant 集成 - 智能家居自动化警报和 IoT 通知
sidebarTitle: Home Assistant
description: 将 Echobell 与 Home Assistant 集成以获取智能家居即时通知的完整指南。设置安防系统、温度传感器、运动检测、门锁和自动化触发器的 Webhook 警报，支持推送通知或电话提醒。
---

import { Step, Steps } from "fumadocs-ui/components/steps";

# Home Assistant 集成

[Home Assistant](https://www.home-assistant.io/)是一个强大的开源家庭自动化平台，注重本地控制和隐私保护。通过将 Echobell 与 Home Assistant 集成，您可以在智能家居发生重要事件时立即收到通知或电话，例如安全警报、温度阈值超标或自动化触发器。

本指南将介绍如何使用 Webhook 或 RESTful 通知服务设置 Home Assistant 自动化，向您的 Echobell 通知频道发送通知。

## 前提条件

在开始之前，请确保您具备：

- iOS 设备上已安装[Echobell 应用](https://apps.apple.com/app/apple-store/id6743597198?pt=128151925&ct=docs-developer-home-assistant-zh&mt=8)
- 有效的 Echobell 频道（如果没有，请在应用中创建）
- 正在运行的 Home Assistant 实例（建议 2023.1 或更高版本）
- 访问 Home Assistant 配置的权限

## 方法一：使用 Webhook 触发器（推荐）

使用 Webhook 方法是最灵活的方式，允许您发送自定义数据并在通知中使用[模板变量](/docs/template)。

<Steps>
<Step>
### 获取Echobell Webhook URL

1. 打开 Echobell 应用并导航到您的频道
2. 点击您的频道查看详情
3. 在 Triggers 部分找到 **Webhook URL**
4. 复制 URL，格式类似：`https://hook.echobell.one/t/YOUR_TOKEN`
</Step>
<Step>

### 创建 Home Assistant 自动化

在 Home Assistant 中，您可以使用`rest_command`服务触发 Echobell 通知。首先，在`configuration.yaml`中添加 REST 命令：

```yaml
rest_command:
  echobell_notify:
    url: "https://hook.echobell.one/t/YOUR_TOKEN"
    method: POST
    content_type: "application/json"
    payload: '{"title": "{{ title }}", "message": "{{ message }}"}'
```

将`YOUR_TOKEN`替换为您实际的 Echobell Webhook 令牌。

添加后，重启 Home Assistant 以加载新配置。

</Step>
<Step>
### 在自动化中使用

现在您可以从任何自动化中调用此服务。以下是门被打开时发送通知的示例：

```yaml
automation:
  - alias: "Door Open Alert"
    trigger:
      - platform: state
        entity_id: binary_sensor.front_door
        to: "on"
    action:
      - service: rest_command.echobell_notify
        data:
          title: "安全警报"
          message: "前门于 {{ now().strftime('%H:%M') }} 被打开"
```

</Step>
<Step>
### 配置通知模板

在 Echobell 频道设置中，配置通知模板以显示 Webhook 数据：

- **标题模板**：`{{title}}`
- **内容模板**：`{{message}}`

这确保了当自动化触发时，您将收到包含自定义标题和消息的通知。

</Step>
</Steps>

## 方法二：使用 RESTful 通知平台

如需更紧密的集成，您可以将 Echobell 配置为 Home Assistant 的通知服务。

### 配置

在`configuration.yaml`中添加：

```yaml
notify:
  - name: echobell
    platform: rest
    resource: https://hook.echobell.one/t/YOUR_TOKEN
    method: POST_JSON
    data:
      title: "{{ title }}"
      message: "{{ message }}"
```

将`YOUR_TOKEN`替换为您的 Echobell Webhook 令牌并重启 Home Assistant。

### 使用通知服务

现在您可以像使用其他通知服务一样使用 Echobell：

```yaml
automation:
  - alias: "Low Battery Alert"
    trigger:
      - platform: numeric_state
        entity_id: sensor.phone_battery
        below: 20
    action:
      - service: notify.echobell
        data:
          title: "电量不足警告"
          message: "手机电量仅剩 {{ states('sensor.phone_battery') }}%"
```

## 下一步

Echobell 与 Home Assistant 集成成功后：

- 探索[通知类型](/docs/notification)设置不同的警报优先级
- 使用[条件](/docs/conditions)智能过滤通知
- 查看[模板变量](/docs/template)了解高级消息格式化
- 阅读[Webhook 最佳实践](/docs/webhook)优化集成

## 相关资源

- [Home Assistant REST 命令文档](https://www.home-assistant.io/integrations/rest_command/)
- [Home Assistant RESTful 通知平台](https://www.home-assistant.io/integrations/notify.rest/)
- [Echobell Webhook 文档](/docs/webhook)
- [Echobell 模板系统](/docs/template)
