Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(homeassistant): Add Mosquitto MQTT broker #113

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
!README.md
!docker-compose.yml
!backup.env.example
!mosquitto.env.example
!mosquitto/config/mosquitto.conf
15 changes: 15 additions & 0 deletions homeassistant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ 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`.

Copy the Mosquitto environment file to `mosquitto.env` and fill the username and password:
`cp mosquitto.env.exmple mosquitto.env`.

Start the container, create a user in mosquitto with the following command and the credentials defined in the `mosquitto.env` file:

`docker compose exec mosquitto mosquitto_passwd -b /mosquitto/config/pwfile <username> <password>`

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 in the `mosquitto.env` file.

## Backup

### Enable Backups in HomeAssistant
Expand Down
23 changes: 23 additions & 0 deletions homeassistant/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ 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}
env_file:
- ${CONFIG_ROOT:-.}/homeassistant/mosquitto.env
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", "-u", "$$MOSQUITTO_USERNAME", "-P", "$$MOSQUITTO_PASSWORD", "-h", "localhost", "-t", "$$SYS/broker/uptime", "-i", "docker_health_check", "-C", "1" ]
interval: 1m
timeout: 10s
retries: 3
profiles:
- mqtt
homeassistant-backup:
image: adrienpoupa/rclone-backup:latest
container_name: homeassistant-backup
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/mosquitto.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MOSQUITTO_USERNAME=
MOSQUITTO_PASSWORD=
9 changes: 9 additions & 0 deletions homeassistant/mosquitto/config/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
persistence true
persistence_location /mosquitto/data/

password_file /mosquitto/config/pwfile
allow_anonymous false

log_dest file /mosquitto/log/mosquitto.log

listener 1883
Loading