智能家居实战:用 Home Assistant 打造自动化灯光系统

智能家居实战:用 Home Assistant 打造自动化灯光系统

引言

智能家居不是买个智能灯泡那么简单。真正的智能,是让设备在你需要时自动响应,而不是掏出手机控制。本文用 Home Assistant 搭建一套自动化灯光系统,成本不到 500 元。

硬件清单

设备 数量 价格
树莓派 4B (2GB) 1 ¥280
小米智能灯泡 (WiFi 版) 3 ¥49×3
人体传感器 2 ¥39×2

Home Assistant 安装

使用官方镜像最省心:

# 写入镜像到 SD 卡
sudo dd if=homeassistant-rpi4-64.img of=/dev/sdX bs=4M conv=fsync

# 首次启动后访问 http://homeassistant.local:8123

配置自动化

核心逻辑:有人移动→开灯,2 分钟无人→关灯。configuration.yaml 配置:

automation:
  - alias: "客厅自动开灯"
    trigger:
      platform: state
      entity_id: binary_sensor.living_room_motion
      to: "on"
    action:
      service: light.turn_on
      target:
        entity_id: light.living_room
        
  - alias: "客厅自动关灯"
    trigger:
      platform: state
      entity_id: binary_sensor.living_room_motion
      to: "off"
      for:
        minutes: 2
    action:
      service: light.turn_off
      target:
        entity_id: light.living_room

进阶技巧

1. 日落触发:只在日落后启动自动化

condition:
  condition: sun
  after: sunset

2. 亮度自适应:白天 80%,夜晚 30%

service_data:
  brightness_pct: >
    {% if states(""sun.sun"") == ""above_horizon"" %}
      80
    {% else %}
      30
    {% endif %}

避坑指南

  • WiFi 灯泡断连?换 Zigbee 版本更稳定
  • 传感器误触发?调整灵敏度和延迟时间
  • Home Assistant 卡顿?关闭不用的集成

总结

这套系统运行 3 个月,零故障。关键是本地执行,不依赖云端,断网也能用。下一步可以接入语音控制或添加场景模式。

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注