├── README.md └── docker-compose.yml /README.md: -------------------------------------------------------------------------------- 1 | # Home Assistant docker-compose 2 | 3 | This is my setup for home assistant using docker-compose. This is tested and runs fine on any Ubuntu distribution from 16.04 onwards. 4 | 5 | It contains the following components: 6 | - [Home Assistant](https://hub.docker.com/r/homeassistant/home-assistant/) (duh) 7 | - [Postgresql](https://hub.docker.com/_/postgres). The database Home Assistant should use 8 | - [InfluxDB](https://hub.docker.com/_/influxdb). The database Home Assistant writes sensory information to such that Grafana can read it 9 | - [Grafana](https://hub.docker.com/r/grafana/grafana). Dashboarding 10 | - [LetsEncrypt](https://hub.docker.com/r/linuxserver/letsencrypt). Service to setup and maintain SSL for Home Assistant 11 | - [Node Red](https://hub.docker.com/r/nodered/node-red-docker): Alternative for the yaml automations in Home Assistant 12 | 13 | A brief setup, requirements and list of quirks is compiled below per service. Most of these are a culmination of many forum posts of which is was unable to find all resources. 14 | Might you find the root post, please let me know and I will attribute it :). 15 | 16 | ## Home Assistant 17 | 18 | Doesn't require much setup. The home directory will be `/home//.homeassistant`. Change `` to your username. 19 | To leverage all components you must have at least the following in your `configuration.yaml`. 20 | 21 | ```yaml 22 | http: 23 | api_password: !secret http_password 24 | base_url: !secret base_url 25 | api: 26 | 27 | influxdb: 28 | host: localhost 29 | port: 8086 30 | database: homeassistant 31 | username: !secret influxdb_username 32 | password: !secret influxdb_password 33 | 34 | recorder: 35 | db_url: !secret postgres_url 36 | ``` 37 | 38 | The `postgres_url` should be in this format: 39 | ```bash 40 | postgresql://username:password@host/db 41 | ``` 42 | For example 43 | ```bash 44 | postgresql://homeassistant:mypass@localhost/home-assistant 45 | ``` 46 | 47 | ## Postgresql 48 | Should run without issues. Must be in `host` network mode for Home Assitant to be able to connect. You could setup a docker network, but this setup exposes Home Assistant to the outside world. 49 | The persistent directory will be `/home//.postgres`. Change `` to your username. 50 | 51 | ## InfluxDB 52 | Should run without issues. Must be in `host` network mode for Home Assitant to be able to connect 53 | The persistent directory will be `/home//.influxdb`. Change `` to your username. 54 | 55 | ## Grafana 56 | The persistent directory will be `/home//.grafana`. Change `` to your username. 57 | The grafana docker container runs on user:group `472:472`. The persistent volume must therefor be `chmod` as that user. Use `sudo chown -R 472:472 /home//.grafana` to achieve that. 58 | 59 | ## LetsEncrypt 60 | This is the most annoying one. It doesn't work out the box as described on their website 61 | The persistent directory will be `/home//.letsencrypt`. Change `` to your username. 62 | 63 | Also in the `docker-compose.yml` change `` and `` to your email address and your DNS name. Register one for free at [https://www.duckdns.org/](https://www.duckdns.org/) 64 | 65 | After starting the LetsEncrypt once you have to modify `/home//.letsencrypt/config/nginx/site-confs` to add this: 66 | 67 | ```yaml 68 | ### HOMEASSISTANT ############################################################## 69 | server { 70 | listen 443 ssl; 71 | 72 | root /config/www; 73 | index index.html index.htm index.php; 74 | 75 | server_name ; 76 | 77 | include /config/nginx/ssl.conf; 78 | 79 | client_max_body_size 0; 80 | 81 | location / { 82 | proxy_set_header Host $host; 83 | proxy_redirect http:// https://; 84 | proxy_http_version 1.1; 85 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 86 | proxy_set_header Upgrade $http_upgrade; 87 | proxy_set_header Connection "upgrade"; 88 | proxy_buffering off; 89 | proxy_ssl_verify off; 90 | proxy_pass http://:8123; 91 | } 92 | } 93 | ``` 94 | 95 | Without this nginx won't forward the DNS subdomain to Home Assistant. Replace `` and `` with your values. For every subdomain (perhaps you want to expose mqtt!?) you can add above configuration for each subdomain and add it to the SUBDOMAINS list, i.e.: 96 | ```yaml 97 | - SUBDOMAINS=hass,mqtt,other 98 | ``` 99 | 100 | Restart the container and if everything is right home assistant should be available on your own DNS address. 101 | 102 | ## Node Red 103 | Runs as user `1000` in the docker container. For some docker might run as `root`. The docker user for Node Red has therefor been configured as `root` such that Node Red has rights to read/write the persistent storage. 104 | The persistent directory will be `/home//.nodered`. Change `` to your username. 105 | 106 | After running the container, step into the container with `docker exec -it nodered bash` and run 107 | ```bash 108 | cd /data 109 | npm install node-red-contrib-home-assistant 110 | ``` 111 | 112 | exit the container and restart the container. 113 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | 4 | postgres: 5 | container_name: postgres 6 | image: postgres:11.1 7 | restart: always 8 | network_mode: host 9 | ports: 10 | - "5234:5234" 11 | environment: 12 | POSTGRES_USER: homeassistant 13 | POSTGRES_PASSWORD: 14 | volumes: 15 | - /home//.postgres:/var/lib/postgresql/data 16 | - /etc/localtime:/etc/localtime:ro 17 | 18 | influxdb: 19 | container_name: influxdb 20 | image: influxdb:1.7.1 21 | restart: unless-stopped 22 | network_mode: host 23 | ports: 24 | - "8086:8086" 25 | - "8083:8083" 26 | environment: 27 | INFLUXDB_DB: homeassistant 28 | INFLUXDB_USER: homeassistant 29 | INFLUXDB_USER_PASSWORD: 30 | volumes: 31 | - /home//.influxdb:/var/lib/influxdb 32 | - /etc/localtime:/etc/localtime:ro 33 | 34 | grafana: 35 | depends_on: 36 | - influxdb 37 | image: grafana/grafana:latest 38 | container_name: grafana 39 | network_mode: host 40 | ports: 41 | - "3000:3000" 42 | environment: 43 | - GF_INSTALL_PLUGINS=grafana-clock-panel,briangann-gauge-panel,natel-plotly-panel,grafana-simple-json-datasource 44 | volumes: 45 | - /home//.grafana:/var/lib/grafana 46 | 47 | homeassistant: 48 | depends_on: 49 | - postgres 50 | - influxdb 51 | container_name: home-assistant 52 | image: homeassistant/home-assistant:latest 53 | restart: always 54 | privileged: true 55 | command: [ "python", "-m", "homeassistant", "--config", "/config", "--log-rotate-days", '3' ] 56 | network_mode: host 57 | volumes: 58 | - /home//.homeassistant:/config 59 | - /etc/localtime:/etc/localtime:ro 60 | - /etc/timezone:/etc/timezone:ro 61 | ports: 62 | - "8123:8123" 63 | - "8943:8943" 64 | devices: 65 | - /dev/ttyUSB0 66 | - /dev/ttyUSB1 67 | - /dev/ttyACM0 68 | 69 | letsencrypt: 70 | container_name: lets-encrypt 71 | image: linuxserver/letsencrypt 72 | restart: always 73 | cap_add: 74 | - NET_ADMIN 75 | network_mode: host 76 | volumes: 77 | - /etc/timezone:/etc/timezone:ro 78 | - /home//.letsencrypt/config:/config 79 | ports: 80 | - "80:80" 81 | - "443:443" 82 | environment: 83 | - PGID=1000 84 | - PUID=1000 85 | - EMAIL= 86 | - URL= 87 | - SUBDOMAINS=hass 88 | - VALIDATION=http 89 | 90 | nodered: 91 | container_name: nodered 92 | image: nodered/node-red-docker:latest 93 | network_mode: host 94 | volumes: 95 | - /etc/timezone:/etc/timezone:ro 96 | - /home//.nodered/:/data 97 | ports: 98 | - "1880:1880" 99 | user: 'root' 100 | --------------------------------------------------------------------------------