开源项目 Smarthome-homeassistant-config 使用教程
1. 项目的目录结构及介绍
目录结构
Smarthome-homeassistant-config/
├── automations/
├── blueprints/
├── custom_components/
├── www/
├── .gitignore
├── configuration.yaml
├── customize.yaml
├── home-assistant_v2.db
├── homeassistant.log
├── secrets.yaml
└── ui-lovelace.yaml
目录介绍
- automations/: 存放自动化脚本的目录。
- blueprints/: 存放蓝图的目录,用于复用自动化配置。
- custom_components/: 存放自定义组件的目录。
- www/: 存放静态资源的目录,如图片、CSS 文件等。
- .gitignore: Git 忽略文件列表。
- configuration.yaml: 主配置文件,包含 Home Assistant 的核心配置。
- customize.yaml: 用于自定义实体属性的文件。
- home-assistant_v2.db: Home Assistant 的数据库文件。
- homeassistant.log: Home Assistant 的日志文件。
- secrets.yaml: 存放敏感信息的文件,如密码、API 密钥等。
- ui-lovelace.yaml: Lovelace UI 的配置文件。
2. 项目的启动文件介绍
启动文件
- configuration.yaml: 这是 Home Assistant 的主配置文件,包含了系统的基本配置,如 MQTT 服务器、传感器、设备等。
启动流程
- 加载配置文件: Home Assistant 启动时会首先加载
configuration.yaml
文件。 - 初始化组件: 根据配置文件中的设置,初始化各个组件。
- 启动服务: 启动各个服务,如 MQTT 服务、HTTP 服务等。
- 加载自动化和蓝图: 加载
automations/
和blueprints/
目录中的自动化脚本和蓝图。
3. 项目的配置文件介绍
主要配置文件
-
configuration.yaml: 主配置文件,包含以下主要部分:
- homeassistant: 核心配置,如时区、名称等。
- mqtt: MQTT 服务器的配置。
- sensor: 传感器的配置。
- switch: 开关的配置。
- light: 灯光的配置。
- automation: 自动化的配置。
- script: 脚本的配置。
-
secrets.yaml: 用于存放敏感信息,如密码、API 密钥等。这些信息可以在
configuration.yaml
中通过!secret
引用。 -
customize.yaml: 用于自定义实体属性,如名称、图标等。
-
ui-lovelace.yaml: Lovelace UI 的配置文件,用于定义前端界面。
配置示例
# configuration.yaml 示例
homeassistant:
name: Home
latitude: 37.8
longitude: -122.4
elevation: 10
unit_system: metric
time_zone: America/Los_Angeles
mqtt:
broker: 192.168.1.5
port: 1883
username: user
password: !secret mqtt_password
sensor:
- platform: mqtt
name: "Temperature"
state_topic: "home/temperature"
light:
- platform: yeelight
devices:
192.168.1.20:
name: Bedroom Light
# secrets.yaml 示例
mqtt_password: your_password
api_key: your_api_key
# customize.yaml 示例
light.bedroom_light:
friendly_name: "卧室灯"
icon: mdi:lightbulb
# ui-lovelace.yaml 示例
title: Home Assistant
views:
- title: Overview
icon: mdi:home
cards:
- type: entities
title: Important Devices
entities:
- light.bedroom_light
- sensor