Last active
March 11, 2025 23:53
-
-
Save DavesCodeMusings/3b9cfd61965011f5088c94c35fb0500a to your computer and use it in GitHub Desktop.
Easily create a Home Assistant install using Docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Create initial directories and files for home automation stack. | |
BASE_DIR=$(pwd) | |
ESPHOME_DIR=$BASE_DIR/esphome | |
HASS_DIR=$BASE_DIR/hass | |
MOSQUITTO_DIR=$BASE_DIR/mosquitto | |
NODE_RED_DIR=$BASE_DIR/node-red | |
echo "Creating directory structure." | |
install -d -o0 -g0 -m755 $ESPHOME_DIR/config | |
install -d -o0 -g0 -m755 $HASS_DIR/config | |
install -d -o1883 -g1883 -m755 $MOSQUITTO_DIR/config | |
install -d -o1883 -g1883 -m755 $MOSQUITTO_DIR/data | |
install -d -o1883 -g1883 -m755 $MOSQUITTO_DIR/log | |
install -d -o1000 -g1000 -m755 $NODE_RED_DIR/data | |
echo "Creating mosquitto.conf." | |
cat <<EOF > $MOSQUITTO_DIR/config/mosquitto.conf | |
persistence true | |
persistence_location /mosquitto/data/ | |
log_dest file /mosquitto/log/mosquitto.log | |
EOF | |
chown 1883:1883 $MOSQUITTO_DIR/config/mosquitto.conf | |
echo "Creating compose.yml." | |
cat <<EOF >$BASE_DIR/compose.yml | |
services: | |
esphome: | |
container_name: esphome | |
hostname: esphome | |
image: esphome/esphome:latest | |
ports: | |
- "6052:6052" | |
- "6123:6123" | |
volumes: | |
- /etc/localtime:/etc/localtime:ro | |
- /etc/timezone:/etc/timezone:ro | |
- $ESPHOME_DIR/config:/config:rw | |
network_mode: host | |
restart: unless-stopped | |
homeassistant: | |
container_name: homeassistant | |
hostname: hass | |
image: lscr.io/linuxserver/homeassistant:latest | |
volumes: | |
- /etc/localtime:/etc/localtime:ro | |
- /etc/timezone:/etc/timezone:ro | |
- $HASS_DIR/config:/config | |
network_mode: host | |
depends_on: | |
- mosquitto | |
- node-red | |
restart: unless-stopped | |
mosquitto: | |
container_name: mosquitto | |
hostname: mosquitto | |
image: eclipse-mosquitto | |
volumes: | |
- /etc/localtime:/etc/localtime:ro | |
- /etc/timezone:/etc/timezone:ro | |
- $MOSQUITTO_DIR/config:/mosquitto/config | |
- $MOSQUITTO_DIR/data:/mosquitto/data | |
- $MOSQUITTO_DIR/log:/mosquitto/log | |
ports: | |
- "1883:1883" | |
restart: unless-stopped | |
node-red: | |
container_name: node-red | |
hostname: node-red | |
image: nodered/node-red | |
ports: | |
- "1880:1880" | |
volumes: | |
- /etc/localtime:/etc/localtime:ro | |
- /etc/timezone:/etc/timezone:ro | |
- $NODE_RED_DIR/data:/data | |
depends_on: | |
- mosquitto | |
restart: unless-stopped | |
EOF | |
echo | |
echo "To start home automation stack, use: docker-compose up -d" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment