win11从零搭建 Home Assistant 并接入洗衣机 / 小爱音箱 / 手机推送(爬坑版)
本文基于一次真实搭建过程整理,环境为 Windows 11,目标是:
- 把小天鹅/美的双筒洗衣机(TNDD20-08AIDE)接入 HA
- 洗衣完成时:手机推送 + 网页通知 + 小爱音箱播报
- 把工作间一个"被识别成开关的墙壁开关"变成灯光实体
0. 先说结论:方案选型
| 方案 | 结果 | 结论 |
|---|---|---|
| VirtualBox + HAOS 虚拟机 | ❌ 放弃 | 系统开 Hyper-V/VBS 时 VBox 嵌套虚拟化导致时钟/CPU 异常,Core 反复重启、8123 不监听 |
| Docker Desktop + HA 容器 | ✅ 成功 | 稳定、免虚拟机调度问题,配置目录可直接放工作空间 |
| HAOS 官方镜像 + 专用硬件(树莓派/迷你主机) | 未采用 | 最稳,但需额外硬件 |
这里爬坑几次不知道是模型能力问题还是环境就是不兼容,使用VirtualBox搭建的也能运行起来最终会反复启动服务提示数据损坏后续ai放弃了该方案
最终架构:
Windows 11
└─ Docker Desktop (WSL2)
└─ homeassistant 容器 --network 端口映射 8123
├─ midea_smart_home → 小天鹅双筒洗衣机
├─ xiaomi_miot → 小米账号 / 小爱音箱 / 全屋米家设备
├─ Companion App → 手机推送
└─ Template Light → 工作间灯
1. 环境准备
1.1 基础条件
- Windows 11,内存建议 ≥ 16GB(Docker Desktop 会分给 WSL2)
- 手机装 Home Assistant Companion App(官方,蓝色房子图标)
- 安卓:Google Play
io.homeassistant.companion.android - iOS:App Store 搜
Home Assistant
- 安卓:Google Play
- 美的美居账号(洗衣机已绑定)
- 小米账号(小爱音箱所在账号)
1.2 需要管理员权限的步骤
装 Docker 依赖 WSL2,需要重新启用之前可能为修 VirtualBox 关闭的 Hyper-V/VBS:
以管理员 PowerShell 运行:
bcdedit /set hypervisorlaunchtype auto
dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
然后重启电脑,确认 (Get-CimInstance Win32_ComputerSystem).HypervisorPresent -eq True。
1.3 WSL2 离线安装(国内 wsl --install 报 403 时)
国内网络 wsl --install 经常返回 403,改用离线包:
- 下载 WSL x64 MSI(本次为 3.0.5,约 350MB): github.com/microsoft/W…
- 管理员 PowerShell 静默安装:
msiexec /i wsl.3.0.5.0.x64.msi /qn /norestart wsl --set-default-version 2 wsl --version # 验证,应显示内核版本 - 注意:启用 Windows 功能 ≠ 装好 WSL。必须
wsl --version能返回版本才算成功。
1.4 安装 Docker Desktop
- 下载 Docker Desktop Installer(约 600MB),静默安装:
"Docker Desktop Installer.exe" install --quiet --accept-license - 重启后启动 Docker Desktop,确认
docker info能返回 Server Version。
2. 配置 Docker 代理(关键)
HA 镜像在 ghcr.io,国内直连极慢(本次实测 3KB/s)。普通 Docker Hub 镜像加速源无效。
2.1 给 Docker Desktop 配代理
Docker Desktop → Settings → Resources → Proxies(新版:Settings → Proxies):
- Docker Desktop proxy 下拉选 Manual configuration
- Web Server (HTTP):
http://127.0.0.1:7897(改成你的 Clash 端口) - Secure Web Server (HTTPS):同上
- Bypass:
127.0.0.1,localhost,192.168.0.0/16 - Apply & Restart
容器内装 Clash 不能加速镜像拉取——pull 发生在容器启动前,由守护进程执行。
2.2 验证代理
curl.exe -x http://127.0.0.1:7897 -o NUL -w "%{http_code}" https://ghcr.io/v2/
# 401 是正常的(未授权访问仓库),说明连通
2.3 拉取 HA 镜像
docker pull ghcr.io/home-assistant/home-assistant:stable
3. 运行 HA 容器
3.1 准备配置目录
建议放在工作空间,例如:
D:\个人文件--何晓惠\deepseek-agent\homeassistant
3.2 启动容器(两个关键坑)
docker run -d `
--name homeassistant `
--privileged `
--restart=unless-stopped `
--stop-timeout 60 `
-e TZ=Asia/Shanghai `
-e HTTP_PROXY= -e HTTPS_PROXY= -e ALL_PROXY= -e NO_PROXY='*' `
-e http_proxy= -e https_proxy= -e all_proxy= -e no_proxy='*' `
-v "D:\个人文件--何晓惠\deepseek-agent\homeassistant:/config" `
-p 8123:8123 `
ghcr.io/home-assistant/home-assistant:stable
坑 1:不要用 --network host
Windows Docker Desktop 的 host 网络实际是 WSL2 网络(如 172.28.x.x),端口不会映射到 Windows 本机。必须用 -p 8123:8123。
坑 2:清空代理环境变量
Docker Desktop 配了代理后会往容器注入 HTTP_PROXY 等变量,导致 HA 初始化卡死(python 进程 CPU 不增长、日志为空、8123 不监听)。启动时用 -e XXX_PROXY= 清空。
3.3 初始化
浏览器打开 http://localhost:8123:创建管理员账号、时区 Asia/Shanghai、公制单位。
3.4 获取长期访问令牌
HA 网页 → 左下角头像 → 个人资料 → 长期访问令牌 → 创建令牌(名 agent)→ 复制保存。令牌不要写进文档或提交到代码库。
4. 安装自定义集成
HA 2026.11 自带 marketplace(内置 HACS),但社区集成用"文件方式"装最直接。
4.1 下载并放置
| 集成 | 仓库 | 用途 |
|---|---|---|
| Midea Smart Home | Cyborg2017/midea_smart_home(staging 分支) | 美的/小天鹅洗衣机 |
| Xiaomi Miot Auto | al-one/hass-xiaomi-miot(master 分支) | 小米设备/小爱音箱 |
# 下载 zip
curl.exe -L -o midea.zip https://github.com/Cyborg2017/midea_smart_home/archive/refs/heads/staging.zip
curl.exe -L -o xiaomi.zip https://github.com/al-one/hass-xiaomi-miot/archive/refs/heads/master.zip
# 解压后把 custom_components/<domain> 复制到挂载目录
Copy-Item <解压>\custom_components\midea_smart_home D:\...\homeassistant\custom_components\ -Recurse
Copy-Item <解压>\custom_components\xiaomi_miot D:\...\homeassistant\custom_components\ -Recurse
manifest.json 里的 requirements(lupa、pycryptodome、construct、python-miio 等)会在 HA 重启时自动安装。
4.2 重启 HA
docker restart homeassistant
日志出现 "custom integration ... not tested" 警告是正常的。
5. 接入洗衣机
HA 网页 → 设置 → 设备与服务 → 添加集成 → 搜 Midea Smart Home → 选 auto_add_device → 填美的美居账号密码 → scan_address=auto、scan_mode=broadcast → 勾选设备完成。
这里有个坑爹的点美的这款洗衣机他只能美居云端账号接入本地路由没法搜到暂时没找到解决方案
5.1 生成的实体(TNDD20-08AIDE 双筒)
sensor.midea_<device_id>_db_running_status_l / _r # 左/右筒运行状态
sensor.midea_<device_id>_db_remain_time_l / _r
sensor.midea_<device_id>_db_progress_l / _r
sensor.midea_<device_id>_db_error_code_l / _r
binary_sensor..._db_detergent_needed_l / _r
select..._db_location (left/right)、db_program、db_temperature 等
switch..._db_power、db_control_status
5.2 关键状态值
db_running_status_l/_r 枚举(从集成翻译文件确认):
delay=延时 end=结束 fault=故障 idle=空闲 pause=暂停 standby=待机 start=运行
"洗完"信号 = end(不是 idle/standby)。待机时显示 unknown 正常,运行一次后会上报。
6. 接入小爱音箱并解决 TTS 无声
6.1 接入
添加集成 → 搜 Xiaomi Miot(注意不是 "Xiaomi Miot Auto",搜全名匹配不到)→ 账号集成 → 小米账号密码 → 自动模式 → 勾选设备。
本次生成 5 个 media_player,其中:
media_player.xiaomi_l05c_9d6d_play_control= Mi AI Speaker Play Plus(小爱音箱)
6.2 TTS 无声的排查与解决
现象:xiaomi_miot.intelligent_speaker 服务调用成功但音箱不发声;静音状态被云端反复覆盖;日志有 fetch xiaoai conversation: TypeError。
关键结论:该服务走云端 API,不可靠。改用底层 text 实体(走本地 MIoT action):
# 实体
text.xiaomi_l05c_9d6d_play_text # 播放文本(TTS)
text.xiaomi_l05c_9d6d_execute_text_directive
调用方式:
service: text.set_value
data:
entity_id: text.xiaomi_l05c_9d6d_play_text
value: 洗衣完成,请及时取出衣物
验证成功听到播报。
中文编码坑:用 PowerShell 直接 POST 中文 JSON 会变成 ?????? 或报"非交互模式"。解决:
$body='{"entity_id":"text.xxx","value":"洗衣完成"}'
[System.IO.File]::WriteAllText($tmp,$body,[System.Text.UTF8Encoding]::new($false))
curl.exe -X POST -H "Authorization: Bearer $token" -H 'Content-Type: application/json' --data-binary "@$tmp" URL
(写进自动化 YAML 的中文由 HA 内部处理,无此问题。)
7. 手机推送
手机装官方 Companion App(不是浏览器登录网页!网页版不会生成 notify 实体),用 http://<电脑局域网IP>:8123 登录,允许通知权限。
HA 中出现 notify.mobile_app_xxx(本次为 notify.xiaomi13u)。
测试:
service: notify.send_message
data:
entity_id: notify.xiaomi13u
title: 测试
message: 测试推送
8. 完整自动化(最终版)
文件:configuration.yaml 中 automation: !include automations.yaml
8.1 三条必须遵守的语法规则
- HA 2026.11 手写 automations.yaml 必须用老语法:顶层
trigger:/condition:/action:,触发器用- platform: state,动作用- service: xxx。新语法triggers:/actions: + action:会报"使用了未知动作"。 - service 必须是服务名,不能是实体 ID:
- ✅
service: notify.send_message+data.entity_id: notify.xiaomi13u - ❌
service: notify.xiaomi13u(报Action notify.xiaomi13u not found) text.set_value同理:service +data.entity_id+data.value
- ✅
- 修改 automations.yaml 后调用
automation.reload;HA 设置页残留的 repair 提示是历史记录,点"提交"清除即可。
8.2 最终配置
- id: washer_left_done
alias: 左筒洗衣完成提醒
mode: single
trigger:
- platform: state
entity_id: sensor.midea_208907229532948_db_running_status_l
to: "end"
condition:
- condition: numeric_state
entity_id: sensor.midea_208907229532948_db_remain_time_l
above: 0
action:
- service: notify.send_message
data:
entity_id: notify.xiaomi13u
title: 小乌梅洗衣完成
message: 小乌梅左筒洗衣已完成,请及时取出衣物
- service: persistent_notification.create
data:
title: 小乌梅洗衣完成
message: 小乌梅左筒洗衣已完成,请及时取出衣物
notification_id: washer_left_done
- service: text.set_value
data:
entity_id: text.xiaomi_l05c_9d6d_play_text
value: 小乌梅左筒洗衣完成,请及时取出衣物
# 多房间同步播报:主卧 Mi Smart Clock 4inch + 餐厅 Redmi Smart Display 8inch
- service: text.set_value
data:
entity_id: text.xiaomi_lx04_87b1_play_text
value: 小乌梅左筒洗衣完成,请及时取出衣物
- service: text.set_value
data:
entity_id: text.xiaomi_x08c_f80c_play_text
value: 小乌梅左筒洗衣完成,请及时取出衣物
- id: washer_right_done
alias: 右筒洗衣完成提醒
mode: single
trigger:
- platform: state
entity_id: sensor.midea_208907229532948_db_running_status_r
to: "end"
condition:
- condition: numeric_state
entity_id: sensor.midea_208907229532948_db_remain_time_r
above: 0
action:
# 与左筒完全相同的 5 个动作,仅把文案中的「左筒」改为「右筒」:
# notify.send_message → persistent_notification.create →
# text.set_value × 3(l05c / lx04 / x08c_f80c)
多房间播报说明:每个音箱对应一个
text.<设备>_play_text实体,多一个音箱就多写一个text.set_value动作。区域归属通过.storage/core.device_registry(area_id)+.storage/core.entity_registry(device_id 反查 entity_id)确认。本次三台:工作间/客厅墙边 l05c(Mi AI Speaker Play Plus)、主卧 lx04(Mi Smart Clock 4inch)、餐厅 x08c_f80c(Redmi Smart Display 8inch);客厅还有一台 x08c_1d14 同型号,未加入自动化。
验证:reload → 手动触发 → docker logs 无 "Error executing script",手机/音箱/网页三处收到提醒。
自动化不需要先洗一次衣服才生效,创建即生效。手动测试用
skip_condition:true,真实触发要满足剩余时间>0。
9. 把"开关"变成灯光实体(Template Light)
9.1 场景
工作间的 Xiaomi Smart Wall Switch(model xiaomi.switch.w1)实际控灯,但被识别成 switch.xiaomi_w1_0228_switch。注意小米插件生成的 light.xiaomi_w1_0228_switch 是"指示灯",不是真灯。
这里是为了应对米家里加入的智能开关设备在ha平台没识别成灯光控制的场景
9.2 配置(HA 2026.11 新格式)
文件 lights.yaml:
- light:
- name: "工作间灯"
unique_id: gong_zuo_jian_light_template
state: "{{ is_state('switch.xiaomi_w1_0228_switch', 'on') }}"
turn_on:
- action: switch.turn_on
target:
entity_id: switch.xiaomi_w1_0228_switch
turn_off:
- action: switch.turn_off
target:
entity_id: switch.xiaomi_w1_0228_switch
configuration.yaml:
template: !include lights.yaml
坑:
- HA 2026.11 不支持老格式
light: - platform: template,必须用独立template:段 - 新格式里
toggle是非法选项,不要写 - 模板灯改动必须完整重启容器(
docker restart homeassistant),reload 不生效 - 刚启动 state 短暂为 unknown,约 15 秒后同步
生成实体:light.gong_zuo_jian_deng,开关双向测试正常。
10. 日常维护速查
| 操作 | 命令 |
|---|---|
| 启动/停止 HA | docker start homeassistant / docker stop homeassistant |
| 重启 HA | docker restart homeassistant |
| 看日志 | docker logs homeassistant --tail 50 |
| 改了 configuration.yaml/lights.yaml | 必须完整 docker restart homeassistant |
| 改了 automations.yaml | POST /api/services/automation/reload 即可 |
| 查看实体 | HA 网页 → 开发者工具 → 状态 |
注意事项:
- 电脑需保持开机,睡眠时 HA 停止工作、通知失效
- 遇到新设备接入,重复第 5/6/7 节流程即可
附:本次踩坑总表
| 问题 | 根因 | 解决 |
|---|---|---|
| VBox 虚拟机 Core 反复重启 | Hyper-V/VBS 导致嵌套虚拟化时钟异常 | 弃用 VBox,改 Docker |
| ghcr.io 下载 3KB/s | 国内直连慢,Hub 加速源无效 | Docker Desktop 守护进程配代理 |
| WSL 装不上(403) | wsl --install 在线源被拒 | 下载 x64 MSI 离线安装 |
| 容器 8123 不通 | --network host 在 Windows 不映射端口 | 用 -p 8123:8123 |
| 容器初始化卡死 | Docker 代理变量注入容器 | 启动时清空 *_PROXY 变量 |
| 集成搜不到 | 搜索名是 "Xiaomi Miot" 非 "Xiaomi Miot Auto" | 用正确名称搜索 |
| 小爱 TTS 无声 | 云端接口不可靠 | 用 text.set_value 写 play_text 实体 |
| 中文变 ?????? | PowerShell 编码 | curl + UTF-8 文件传 body |
| 自动化"未知动作" | 新语法 / service 写成实体 ID | 老语法 + service: notify.send_message + data.entity_id |
| switch 变 light 失败 | HA 2026.11 template 格式变更 | 独立 template: 段,无 toggle,完整重启 |
最终结论
- 美的这款小乌梅不是很支持接入HA,接入后只能通过ha做基础的启动停止功能操作,洗衣结束的状态也不好拿到(ai分析是美的官方没做推送支持,要想和米家音响联动只能手机上获取美的美居的推送在做转发)
- 本地路由也没法直接搜索到洗衣机设备只能通过美居远端拿到,这个是最坑爹的地方
- 米家本身的设备对HA的支持度都还是比较高的如果想让米家设备全部通过HA控制还是不错的