目 录CONTENT

文章目录

群晖DSM下Docker安装Home Assistant Container(无supervisor)

华灯
2024-04-15 / 0 评论 / 0 点赞 / 19 阅读 / 7696 字

一、安装HomeAssistant
这个没什么好讲的了,请参考官方文档:Linux - Home Assistant (home-assistant.io)
所有操作都需要切换到root权限

sudo -i

二:安装MQTT服务

本帖隐藏的内容

下文中/volume1/docker 需要自己按需调整

null

#建立MQTT配置目录

mkdir -p /volume1/docker//mosquitto/config
mkdir -p /volume1/docker/mosquitto/data
mkdir -p /volume1/docker/mosquitto/log

#建立MQTT配置文件

vi /volume1/docker/mosquitto/config/mosquitto.conf

写入以下内容

persistence true
persistence_location /mosquitto/data
log_dest file /mosquitto/log/mosquitto.log
listener 1883


#目录授权

chmod -R 755 /volume1/docker/mosquitto
chmod -R 777 /volume1/docker/mosquitto/log #日志目录要最大权限


#安装MQTT服务

docker run -d --name="mosquitto" --restart=always \
  -p 1883:1883 -p 9001:9001 \
  -v /volume1/docker/mosquitto/config:/mosquitto/config \
  -v /volume1/docker/mosquitto/data:/mosquitto/data \
  -v /volume1/docker/mosquitto/log:/mosquitto/log \
  eclipse-mosquitto:latest

#配置权限

vi /volume1/docker//mosquitto/config/mosquitto.conf

配置文件添加以下配置

  # 关闭匿名模式
allow_anonymous false
# 指定密码文件
password_file /mosquitto/config/pwfile.conf

#进入容器

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
558ed1ba9516 eclipse-mosquitto:latest "/docker-entrypoint.…" 16 minutes ago Up 3 minutes 0.0.0.0:1883->1883/tcp mosquitto
e758621522e4 esphome/esphome:latest "/entrypoint.sh dash…" 40 minutes ago Up 40 minutes 0.0.0.0:6052->6052/tcp esphome
eada3b37a350 homeassistant/home-assistant:latest "/init" About an hour ago Up 47 minutes 0.0.0.0:8123->8123/tcp homeassistant

docker exec -it 558ed1ba9516 sh

#对于passworf_file文件 自行创建一个空文件

touch /mosquitto/config/pwfile.conf

#chmod -R 755 /mosquitto/config/pwfile.conf

使用mosquitto_passwd命令创建用户,第一个test是用户名,第二个testpwd是密码

mosquitto_passwd -b /mosquitto/config/pwfile.conf test testpwd

#退出

exit

#重启

docker restart 558ed1ba9516  

三:ESPHome服务
#建立esphome配置目录

<div style="line-height: 19px;"><div style="">mkdir -p /volume1/docker/esphome</div></div>

#安装mariadb

docker run --rm --net=host -v /volume1/docker/esphome:/config -it esphome/esphome

四:Mariadb数据库服务
#建立Mariadb配置目录

mkdir -p /volume1/docker/mariadb/data

复制代码

#安装mariadb

docker run --name mariadb --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=输数据库root用户的密码 -v /data/mariadb/data:/var/lib/mysql -d mariadb

#进入容器

ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81b19fa50268 mariadb "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:3306->3306/tcp mariadb
558ed1ba9516 eclipse-mosquitto:latest "/docker-entrypoint.…" 4 hours ago Up 2 hours 0.0.0.0:1883->1883/tcp, 0.0.0.0:9001->9001/tcp mosquitto
e758621522e4 esphome/esphome:latest "/entrypoint.sh dash…" 5 hours ago Up 2 hours 0.0.0.0:6052->6052/tcp esphome
eada3b37a350 homeassistant/home-assistant:latest "/init" 5 hours ago Up 2 hours 0.0.0.0:8123->8123/tcp homeassistant

docker exec -it 81b19fa50268 bash

#进入SQL root账户

mysql -u root -p

输入刚刚设置的密码
#MariaDB数据库创建用户

create user homeassistant@'%' identified by 'hassos-mariadb';

#MariaDB数据库给用户授权

grant all on *.* to homeassistant@'%';
flush privileges;

复制代码

#MariaDB数据库创建用户并授权的命令

grant all on *.* to homeassistant@'%' identified by 'homeassistant';
flush privileges;

#新建数据库

CREATE DATABASE homeassistant;

#HA中设置路径

db_url: mysql://homeassistant:hassos-mariadb@你的数据库IP地址/homeassistant?charset=utf8
0

评论区