引言:为什么选择 Home Assistant
智能家居不是年轻人的专利。我花 3000 块把 10 年老房子改造成智能家,核心就是开源平台 Home Assistant(HA)。相比小米、HomeKit,HA 的优势是本地运行、隐私可控、设备兼容性强。
硬件清单(总预算≈3000 元)
| 设备 | 数量 | 单价 | 小计 |
|---|---|---|---|
| 树莓派 4B 4GB | 1 | 450 | 450 |
| Zigbee 网关(Sonoff) | 1 | 80 | 80 |
| 智能开关(零火版) | 5 | 60 | 300 |
| 人体传感器 | 4 | 50 | 200 |
| 温湿度传感器 | 3 | 40 | 120 |
| 智能插座 | 6 | 50 | 300 |
| LED 灯带(5 米) | 2 | 80 | 160 |
| 网关/路由器 | 1 | 200 | 200 |
| 杂项(电源/线材) | – | – | 300 |
| 合计 | – | – | 2110 |
核心自动化配置示例
HA 的自动化用 YAML 配置,下面是我常用的三个场景:
1. 离家自动布防
automation:
- alias: "离家模式"
trigger:
platform: state
entity_id: person.li_hua
to: "not_home"
action:
- service: light.turn_off
target: {entity_id: all}
- service: switch.turn_off
target: {entity_id: all}
- service: alarm_control_panel.alarm_arm_away
target: {entity_id: alarm_control_panel.home_alarm}
2. 夜间人体感应开灯
automation:
- alias: "走廊夜灯"
trigger:
platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
condition:
- condition: sun
after: sunset
- condition: numeric_state
entity_id: sensor.hallway_light
below: 50
action:
- service: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 30
color_temp: 4000
3. 空调节能策略
automation:
- alias: "空调节能"
trigger:
platform: numeric_state
entity_id: sensor.living_room_temperature
above: 28
condition:
- condition: state
entity_id: person.li_hua
state: "home"
action:
- service: climate.set_temperature
target: {entity_id: climate.living_room_ac}
data: {temperature: 26}
避坑指南
- 开关一定要买零火版:单火版容易闪烁,稳定性差
- Zigbee 设备优先选同品牌:混用可能配对失败
- 树莓派要配散热:HA 24 小时运行,夏天容易过热
- 备份!备份!备份!:HA 配置定期快照,避免重置
进阶玩法
装好基础自动化后,可以试试这些:
- 接入小爱同学/天猫精灵做语音控制
- 用 Node-RED 做可视化流程编排
- 接入 HomeKit 让 iPhone 用户也能控制
- 用 Grafana 做能耗监控看板
结语
智能家居的核心不是设备多贵,而是自动化是否贴合生活习惯。HA 学习曲线陡,但一旦跑通,你会发现:真正的智能,是让房子主动服务人,而不是人伺候设备。

