点击展开更新日志

2025

08-10

【新增】HACS
【新增】米家集成

09-21

【新增】iKuai
【新增】OpenWrt

nexttime

会有些什么呢(❁´◡`❁)

源起

部署

HomeAssistant

官网安装文档:https://www.home-assistant.io/installation/linux

1
2
3
4
5
6
7
8
9
10
11
services:
homeassistant:
container_name: homeassistant
image: "ghcr.io/home-assistant/home-assistant:stable"
volumes:
- /PATH_TO_YOUR_CONFIG:/config
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
restart: unless-stopped
privileged: true
network_mode: host

配置

如果需要使用反向代理,还需要在配置中添加相关配置,否则用域名会拒绝访问。

参考:HTTP-Home Assistant

1
2
3
4
5
6
7
8
# Example configuration.yaml entry
http:
use_x_forwarded_for: true
trusted_proxies: # 重点是这行
- 10.0.0.200
- 172.30.33.0/24
ip_ban_enabled: true
login_attempts_threshold: 5

HACS

Home Assistant Community Store (HACS):https://hacs.xyz/docs/use/download/download/#to-download-hacs

如果是容器部署,可以使用以下命令:

1
2
3
4
5
# 进入容器
docker exec -it <name of the container running homeassistant> bash

# 下载安装脚本
wget -O - https://get.hacs.xyz | bash -

之后从HA 的【设置】-【设备与服务】-【添加集成】,搜索 HACS 添加,需要 Github OAuth 进行身份验证。

HomeAssistant 米家集成

小米官方提供了 Home Assistant 的集成组件,可以很方便的接入米家应用,需要有一个 GitHub 账号做认证。

开源地址:https://github.com/XiaoMi/ha_xiaomi_home

  1. 进入HA容器:

    1
    docker exec -it <HA_CONTAINER_NAME> bash
  2. 安装

    1
    2
    3
    4
    cd /config
    git clone https://github.com/XiaoMi/ha_xiaomi_home.git
    cd ha_xiaomi_home
    ./install.sh /config
  3. 重启容器

  4. 从【设置】-【设备与服务】添加 Xiaomi Home,按照指引登录小米账号就可以把米家的设备导入进来
    这里在跳转认证成功之后,返回的地址是一个本地域名,需要手动加一下hosts或者DNS,验证完成之后删除即可。

iKuai

在 HACS 搜索添加集成即可,作者地址:https://github.com/dscao

之后在设备与服务添加集成即可。

OpenWrt

在 HACS 搜索添加集成即可,作者地址:https://github.com/FUjr/homeassistant-openwrt-ubus/tree/v0.0.4。

文档里提供了详细的安装指导,所以简单说明一下,个别注意事项做一下提醒:

  1. 在 HACS 下载 OpenWrt ubus 集成,重启 HA(设置会弹一个提醒,确认提交就会自动重启);

  2. 在【设置】-【设备与服务】添加 OpenWrt ubus ,填写路由地址和root帐密,如果路由没有无线(比如软路由),无线配置就选择 none ,不然日志会一直报错 Access Denied ;下方服务控制也可以勾选,但应该找不到,没有权限;

  3. SSH 登录 OpenWrt,配置 ACL 权限:
    参考资料:ubus (OpenWrt micro bus architecture)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    # SSH 连接到您的 OpenWrt 路由器
    ssh root@your_router_ip

    # 创建 ACL 目录
    mkdir -p /usr/share/rpcd/acl.d

    # 为 Home Assistant 创建 ACL 文件
    cat > /usr/share/rpcd/acl.d/hass.json << 'EOF'
    {
    "hass": {
    "description": "not quite as super user",
    "read": {
    "ubus": {
    "file": [ "*" ],
    "log": [ "*" ],
    "service": [ "*" ],
    },
    },
    "write": {
    "ubus": {
    "file": [ "*" ],
    "log": [ "*" ],
    "service": [ "*" ],
    },
    }
    }
    }

    # 重启服务以应用更改
    /etc/init.d/rpcd restart && /etc/init.d/uhttpd restart

    新建 hass 登录用户:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    vim /etc/config/rpcd

    # SHA1加密密码
    uhttpd -m <secret>

    # 新增
    config login
    option username 'openwrt'
    option password '$1$$abcdefg'
    list read hass
    list write hass

    # 重启服务
    /etc/init.d/rpcd restart && /etc/init.d/uhttpd restart

    这里为例方便直接把全部权限给了hass,如果觉得不安全,可以只给必要的权限,但是哪些是必要的呢,我不知道,所以干脆全给了。