Skip to content

Instantly share code, notes, and snippets.

@1mike12
Last active December 23, 2024 04:00
Show Gist options
  • Save 1mike12/677beeac009978c5a1c02932ed4b78b9 to your computer and use it in GitHub Desktop.
Save 1mike12/677beeac009978c5a1c02932ed4b78b9 to your computer and use it in GitHub Desktop.
setup home assistant on ubuntu docker-compose

How to setup ubuntu, docker-compose and home assistant, with a zigbee dongle and portainer

Setting up docker on ubuntu

Install Docker and Docker Compose on Ubuntu

https://medium.com/@tomer.klein/step-by-step-tutorial-installing-docker-and-docker-compose-on-ubuntu-a98a1b7aaed0

1. Update System

sudo apt update
sudo apt upgrade -y

2. Install Dependencies

sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

3. Add Docker GPG Key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4. Add Docker Repository

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5. Install Docker

sudo apt update
sudo apt install docker-ce -y

6. Verify Docker Installation

sudo systemctl status docker

7. Add User to Docker Group (optional)

sudo usermod -aG docker $USER

Log out and log back in for the change to take effect.

8. Install Docker Compose

sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

9. Verify Docker Compose Installation

docker-compose --version

10. Enable Docker to Start on Boot

sudo systemctl enable docker

Creating the yml file

services:
  homeassistant:
    container_name: homeassistant
    # this specific image works for aqara fp2 which is broken on latest as of dec 22 2024
    image: "ghcr.io/home-assistant/home-assistant:2024.5.1"
    volumes:
      - /home/mike/Desktop/ha/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
      - /run/pulse:/run/pulse:ro
      - /dev/snd:/dev/snd
    devices:
      - "/dev/serial/by-id/usb-Itead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_V2_f4a612428639ef119fb057f454516304-if00-port0:/dev/zigbee"
    restart: unless-stopped
    privileged: true
    network_mode: host
    logging:
      driver: "json-file"  # Use the default json-file driver
      options:
        max-size: "10m"    # Max size of each log file before it is rotated (10MB)
        max-file: "10"     # Max number of log files to keep

  portainer:
    container_name: portainer
    image: portainer/portainer-ce:latest
    restart: unless-stopped
    ports:
      - "8000:8000"  # Optional Portainer Edge agent port
      - "9000:9000"  # Main Portainer UI port
    network_mode: host
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data

volumes:
  portainer_data:

Autostart

1. Create the Systemd Unit File

Run:

sudo nano /etc/systemd/system/homeassistant.service

2. Add the Following Content

find your docker-compose path with which docker-compose

[Unit]
Description=Home Assistant Docker Compose Service
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/mike/Desktop/ha
ExecStart=${PATH} up -d
ExecStop=${PATH} down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

3. Reload Systemd

After saving the file, reload systemd to recognize the new service:

sudo systemctl daemon-reload

4. Enable the Service

Enable it to start on boot:

sudo systemctl enable homeassistant.service

5. Start the Service

Start the service now:

sudo systemctl start homeassistant.service

6. Verify the Service

Check the status to ensure it’s working as expected:

sudo systemctl status homeassistant.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment