Quickstart · 30 分钟跑通 AI × 全屋智能(无语音)
本教程是 2026-07 重组后的版本:用户决定去掉语音助手(避免隐私/复杂度/硬件投入),聚焦 AI 跑全屋智能:MQTT + Z2M 接绿米设备 → InfluxDB 长存 → AppDaemon 预测触发 → Grafana 可视化 → 本地 LLM 自动总结。所有数据本地,不依赖任何云服务。
0. 准备(5 分钟)
| 件 | 条件 |
|---|---|
| NAS | 16GB+ RAM(Linux,Docker 已装),已按 nas-overview 装好 |
| Zigbee 协调器 | SONOFF Zigbee 3.0 USB Dongle Plus-P(¥80-100) |
| 绿米 / Aqara 子设备 | 至少 1 个墙开 + 1 个插座 + 1 个人体(或门磁) |
| 现有 Aqara Hub | 如果你有,保留 Hub 给摄像头云和 HomeKit 用;NAS 用 SONOFF 协调器进 Z2M |
| 路由器 | 关 AP 隔离,启用 mDNS / Bonjour |
| 时间 | 30 分钟 |
施工 + 软件分工:如果绿米设备多,先让师傅现场装配(见 home-ai-install-guide §1 师傅 brief),软件调试下面 30 分钟搞定。
1. 装 HA + Mosquitto + InfluxDB(10 分钟)
mkdir -p ~/ha/{config,z2m,influxdb,grafana,mosquitto}docker-compose.yml 摆平 HA + MQTT + InfluxDB:
version: "3"
services:
homeassistant:
image: ghcr.io/home-assistant/home-assistant:stable
restart: unless-stopped
network_mode: host
privileged: true
environment:
TZ: Asia/Shanghai
volumes:
- ~/ha/config:/config
mosquitto:
image: eclipse-mosquitto:2
restart: unless-stopped
network_mode: host
volumes:
- ~/ha/mosquitto:/mosquitto
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
influxdb:
image: quay.io/influxdata/influxdb:2.7
restart: unless-stopped
network_mode: host
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: admin
DOCKER_INFLUXDB_INIT_PASSWORD: changeme
DOCKER_INFLUXDB_INIT_ORG: home
DOCKER_INFLUXDB_INIT_BUCKET: ha
volumes:
- ~/ha/influxdb:/var/lib/influxdb2~/ha/mosquitto/mosquitto.conf:
allow_anonymous true
persistence true
persistence_location /mosquitto/data/
cd ~/ha && docker compose up -dHA 配置 → 浏览器 http://NAS-IP:8123 完成 onboarding。然后 Add Integration:
- InfluxDB 2.x:
api_version: 2,orghome,bucketha,token 粘贴。
2. 装 Zigbee2MQTT + 接绿米(10 分钟)
docker run -d \
--name zigbee2mqtt \
--restart=unless-stopped \
--network=host \
--device=/dev/ttyACM0 \
-v ~/ha/z2m:/app/data \
-e TZ=Asia/Shanghai \
ghcr.io/koenkk/zigbee2mqtt:stableZ2M web UI:http://NAS-IP:8080(首次无密码)。点 “Permit join” → 60 秒窗口 → 绿米设备按住配对键 5-7 秒 → 等弹窗。
⭐ 绿米 / Aqara 设备 Z2M 兼容矩阵详见 home-ai-install-guide §2;核心结论:墙开 / 插座 / 传感器 / 窗帘电机 / Cube / 灯具 → 全 Z2M;摄像头 / 门锁部分 → 留 Aqara Hub 走云/HomeKit。
HA → Add Integration → “MQTT” → broker localhost:1883。所有绿米设备以 entity 出现。
3. AppDaemon + 预测触发(5 分钟)
docker run -d \
--name appdaemon \
--restart=unless-stopped \
--network=host \
-v ~/ha/appdaemon:/conf \
-e TZ=Asia/Shanghai \
-e HA_URL=http://localhost:8123 \
-e TOKEN=!secret ha_token # 永 token,HA 个人资料页生成
acockburn/appdaemon:latest~/ha/appdaemon/apps/auto_energy.py:
import appdaemon.plugins.hass.hassapi as hass
class AutoSchedule(hass.Hass):
"""非工作时段 + 无人 -> 关空调;回家前 30 分钟预热"""
def initialize(self):
self.listen_state(self.on_presence, "person.you", new="not_home", duration=300)
self.listen_state(self.on_coming_home, "proximity.you_home",
new="below_value", value=2000, old="above_value")
def on_presence(self, entity, attribute, old, new, kwargs):
# 离家 5 分钟 → 自动关主灯 + 关空调
self.call_service("light/turn_off", entity_id="all")
self.call_service("climate/set_hvac_mode",
entity_id="climate.living_room",
hvac_mode="off")
def on_coming_home(self, entity, attribute, old, new, kwargs):
# 离家 < 2km → 提前暖
self.call_service("climate/turn_on",
entity_id="climate.living_room")
self.call_service("climate/set_temperature",
entity_id="climate.living_room",
temperature=22)apps.yaml 加:
auto_energy:
module: auto_energy
class: AutoSchedule重启 appdaemon container:docker restart appdaemon。
4. 装 Grafana 看板(2 分钟)
docker run -d \
--name grafana \
--restart=unless-stopped \
-v ~/ha/grafana:/var/lib/grafana \
-e GF_USERS_DEFAULT_THEME=light \
-p 3000:3000 \
grafana/grafana:latestAdd DataSource:URL = http://NAS-IP:8086(InfluxDB),query language = InfluxQL。
预置看板模板:实时功率 / 今日能耗 / 本月 / 异常事件 4 张面板。见 home-ai-energy §5 详细 yaml。
5. 本地 LLM 自动总结(可选,2 分钟)
如果想”每天 22:00 自动总结今日能耗”:
# Ollama + Qwen2.5-7B-Instruct
docker run -d \
--name ollama \
--restart=unless-stopped \
-v ~/ha/ollama:/root/.ollama \
-p 11434:11434 \
ollama/ollama:latest
# 拉国产模型(国内 ModelScope 镜像)
docker exec ollama ollama pull qwen2.5:7bapps/daily_summary.py:
import appdaemon.plugins.hass.hassapi as hass
import requests
class DailyBrief(hass.Hass):
def initialize(self):
self.run_daily(self.run_brief, "22:00:00")
def run_brief(self, kwargs):
actual = self.get_state("sensor.daily_energy")
yesterday = self.get_state("sensor.yesterday_energy")
delta = (float(actual) - float(yesterday)) / float(yesterday) * 100
prompt = (f"今天家里用电 {actual} 度,比昨天 {'高' if delta > 0 else '低'} {abs(delta):.1f}%。"
f"说一下大概原因 + 明天怎么用低谷电价。50 字以内,中文。")
rsp = requests.post("http://localhost:11434/api/generate",
json={"model": "qwen2.5:7b", "prompt": prompt, "stream": False})
summary = rsp.json()["response"].strip()
self.call_service("notify/dingtalk_bot", message=summary) # 或 企业微信效果:每晚 22 点钉钉 / 企业微信推送一段 AI 生成的”今天耗电情况 + 明天建议”。
6. 验证 / 调试清单
| 现象 | 排查 |
|---|---|
| HA 找不到 Mosquitto | broker 写 localhost:1883,确认 docker --network:host |
| Z2M 显示协调器 offline | ls /dev/ttyACM*,确认 dongle 识别 |
| 绿米设备入网失败 | Aqara 子设备(尤其单火墙开)需 5+cm 离 Aqara Hub,别共入网同一台 |
| InfluxDB 写不进 | 去 HA 看 InfluxDB 集成,Tags 字段验证 entity_id 全英文 |
| ML 跑不动 | N100 也能跑 Prophet,但训练数据应抽样到 < 5 万点 |
| LLM 慢 | Ollama 模型≥14B 时,N100 不够,换工作站 + nas-route-b-expandable |
7. 你跑通后能用的功能
- 全屋 Zigbee 设备毫秒级本地响应(Z2M)
- 暖通预热 / 离家节能(AppDaemon)
- Grafana 看实时 / 历史 能耗
- 本地 LLM 每晚推送 AI 生成的能耗小结到微信 / 钉钉
- 异常用电告警(下面接 / 详见 home-ai-energy §5.3)
- 摄像头视频流仍走绿米 Aqara Home App(HA 集成查看)
- 没做的事:Voice PE / Wake word / Whisper / Piper / 中文化语音助手
本章后续:见 home-ai-predict 详细作息学习 + home-ai-energy 详细能耗管理 + home-ai-decisions 决策矩阵。
引用
- ✓ https://www.home-assistant.io/integrations/influxdb/ — InfluxDB 集成
- ✓ https://www.home-assistant.io/docs/energy/ — Energy Dashboard
- ✓ https://github.com/acockburn/appdaemon — AppDaemon 自动化框架
- ✓ https://ollama.com — 本地 LLM runtime
- ✓ https://github.com/koenkk/zigbee2mqtt — Z2M 主仓