Step 3: Install Home assistant and PostgreSQL

Step 3: Install Home assistant and PostgreSQL

In this docker compose file below it contains two services. The first one is home assistant and the second one is postgres. If you do not want to have postgres, you can comment it out or delete it. After downloading the file you can copy the file to Raspberry pi with Cyberduck, filezile or something similar.

After copying to your Pi, log into by ssh and navigate to the docker compose file and execute following command.

docker-compose up -d

Now you should be apple to go to your browser and call your home assistant like 192.168.1.5:8123. By sure the IP address match your Raspberry pi.

💡
Check if the /config volume is correctly mapped by checking if there are home assistant files like configuration.yaml

Change db_url of the configuration.yaml of home assistant with your postgres credentials (something like postgresql://yourPostgresUser:yourPostgresPassword@192.168.1.4:5432/homeassistant)

💡
Check if home assistant can connect to the database, if not, maybe you should create the database table first. Maybe you can use pgAdmin for creating the database table.

The docker compose description with home assistant and PostgreSQL.

version: "3"
services:
  homeassistant:
    container_name: home-assistant
    image: homeassistant/home-assistant:2024.2
    ports:
      - "8123:8123"
    links:
      - "postgres"
    volumes:
      - ./hassio:/config
    restart: unless-stopped
    depends_on:
      - postgres

  postgres:
    image: postgres:12.13-alpine3.17
    restart: unless-stopped
    ports:
      - 5432:5432
    volumes:
      - ./postgres:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_DB=homeassistant
      - POSTGRES_USER=yourPostgresUser
      - POSTGRES_PASSWORD=yourPostgresPassword