From 558a758e40ab8ec320a7f1c15c0de3cbaa3b36b6 Mon Sep 17 00:00:00 2001 From: Adrien Poupa Date: Sun, 5 Jan 2025 00:06:31 -0500 Subject: [PATCH] feat(homeassistant): Add Mosquitto MQTT broker --- .env.example | 2 +- .gitignore | 2 +- homeassistant/.gitignore | 2 ++ homeassistant/README.md | 12 +++++++++++ homeassistant/docker-compose.yml | 21 +++++++++++++++++++ homeassistant/mosquitto/config/mosquitto.conf | 12 +++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 homeassistant/mosquitto/config/mosquitto.conf diff --git a/.env.example b/.env.example index 1aac38d..02c1fbb 100644 --- a/.env.example +++ b/.env.example @@ -46,4 +46,4 @@ HOMEPAGE_VAR_WEATHER_LONG= HOMEPAGE_VAR_WEATHER_UNIT=metric IMMICH_DB_PASSWORD=postgres CALIBRE_USERNAME=admin -CALIBRE_PASSWORD=admin123 \ No newline at end of file +CALIBRE_PASSWORD=admin123 diff --git a/.gitignore b/.gitignore index f780410..fa2394e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.env +*.env .idea docker-compose.override.yml /homepage/logs diff --git a/homeassistant/.gitignore b/homeassistant/.gitignore index 3c2994b..138fb88 100644 --- a/homeassistant/.gitignore +++ b/homeassistant/.gitignore @@ -2,3 +2,5 @@ !README.md !docker-compose.yml !backup.env.example +!mosquitto.env.example +!mosquitto/config/mosquitto.conf \ No newline at end of file diff --git a/homeassistant/README.md b/homeassistant/README.md index e5d1aa5..1c5726d 100644 --- a/homeassistant/README.md +++ b/homeassistant/README.md @@ -21,6 +21,18 @@ http: Set the `HOMEASSISTANT_ACCESS_TOKEN` for homepage support. +## MQTT + +If you need to use MQTT, you can enable it by setting `COMPOSE_PROFILES=homeassistant,mqtt`. + +Start the container, create a user in mosquitto with the following command and the credentials defined previously: + +`docker compose exec mosquitto mosquitto_passwd -b /mosquitto/config/pwfile ` + +Restart the Mosquitto container to apply the changes. + +In HomeAssistant, add the MQTT integration with hostname `localhost`, port 1883 and the username and password defined above. + ## Backup ### Enable Backups in HomeAssistant diff --git a/homeassistant/docker-compose.yml b/homeassistant/docker-compose.yml index ce82a42..41e3a78 100644 --- a/homeassistant/docker-compose.yml +++ b/homeassistant/docker-compose.yml @@ -34,6 +34,27 @@ services: - homepage.widget.key=${HOMEASSISTANT_ACCESS_TOKEN} profiles: - homeassistant + mosquitto: + container_name: mosquitto + image: eclipse-mosquitto + restart: always + user: ${USER_ID}:${GROUP_ID} + environment: + - PUID=${USER_ID} + - PGID=${GROUP_ID} + volumes: + - ${CONFIG_ROOT:-.}/homeassistant/mosquitto/config:/mosquitto/config + - ${CONFIG_ROOT:-.}/homeassistant/mosquitto/data:/mosquitto/data + - ${CONFIG_ROOT:-.}/homeassistant/mosquitto/log:/mosquitto/log + ports: + - "1883:1883" + healthcheck: + test: [ "CMD", "mosquitto_sub", "-p", "1880", "-t", "$$SYS/#", "-C", "1", "-i", "healthcheck", "-W", "3" ] + interval: 1m + timeout: 10s + retries: 3 + profiles: + - mqtt homeassistant-backup: image: adrienpoupa/rclone-backup:latest container_name: homeassistant-backup diff --git a/homeassistant/mosquitto/config/mosquitto.conf b/homeassistant/mosquitto/config/mosquitto.conf new file mode 100755 index 0000000..71dda1c --- /dev/null +++ b/homeassistant/mosquitto/config/mosquitto.conf @@ -0,0 +1,12 @@ +persistence true +persistence_location /mosquitto/data + +password_file /mosquitto/config/pwfile +allow_anonymous false + +log_dest file /mosquitto/log/mosquitto.log + +listener 1883 + +listener 1880 127.0.0.1 +allow_anonymous true \ No newline at end of file