简单的 HomeAssistant docker-compose 设置
首先,创建 HomeAssistant 驻留的目录。我使用 /opt/homeassistant。
创建 docker-compose.yml:
docker-compose.yml
services:
homeassistant:
container_name: homeassistant
restart: unless-stopped
image: ghcr.io/home-assistant/home-assistant:stable
network_mode: host
privileged: true
environment:
- TZ=Europe/Berlin
volumes:
- ./homeassistant_config:/config
depends_on:
- mosquitto现在启动 homeassistant 以便它创建默认配置文件:
docker-compose-up.sh
docker-compose upOnce you see
homeassistant_ready.txt
homeassistant | [services.d] done.按 Ctrl+C 中止。
现在我们将在 mosquitto_conf/mosquitto.conf 中创建 Mosquitto MQTT 服务器配置文件:
mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## 认证 ##
allow_anonymous false
password_file /mosquitto/config/mosquitto.passwd现在创建 mosquitto 密码文件并使用以下命令修复权限
mosquitto_setup.sh
touch mosquitto_conf/mosquitto.passwd
chown -R 1883:1883 mosquitto_conf我们现在可以开始使用以下命令创建 homeassistant mosquitto 用户
mosquitto_create_user.sh
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd homeassistant输入将用于 homeassistant 用户的随机密码
现在我们可以编辑 homeassistant 配置 homeassistant_config/configuration.yml。这是我的配置 - 确保插入我们之前使用的随机 MQTT 密码而不是 ep2ooy8di3avohn1Ahm6eegheiResh:
homeassistant_config_configuration.yml
# 配置 Home Assistant 的默认设置(前端、api 等)
default_config:
http:
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
ip_ban_enabled: true
login_attempts_threshold: 5
mqtt:
broker: "127.0.0.1"
username: "homeassistant"
password: "ep2ooy8di3avohn1Ahm6eegheiResh"
# 文本转语音
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml现在我们可以使用以下命令启动服务器
docker-compose-up.sh
docker-compose up你也可以使用我们的脚本生成 systemd 服务以在启动时自动启动 docker-compose 配置:
install_docker_compose_service.sh
curl -fsSL https://techoverflow.net/scripts/create-docker-compose-service.sh | sudo bash /dev/stdin现在登录到端口 8123 上的 Web 界面并配置你的 HomeAssistant!
Check out similar posts by category:
Container, Docker, Home-Assistant, MQTT
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow