Skip to content

Commit 8afd7db

Browse files
committed
homeassistant: add docs for https reverse proxy setup
1 parent a81de7b commit 8afd7db

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/Containers/Home-Assistant.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,63 @@ $ cd ~/IOTstack
222222
$ docker-compose up -d
223223
```
224224

225+
## Adding https access to your Home Assistant
226+
227+
Some HA integration (e.g google assistant) require your HA to be accessible
228+
through https. This tells you how to use a [linuxserver swag container](https://docs.linuxserver.io/general/swag) ([Docker hub docs](https://hub.docker.com/r/linuxserver/swag)) to automatically generate a SSL-certificate and setup a reverse proxy.
229+
230+
1. First test your HA is working correctly: `http://raspberrypi.local:8123/` (assuming
231+
your RPi hostname is raspberrypi)
232+
2. Make sure you have duckdns working.
233+
3. On your internet router, forward public port 443 to the RPi port 443
234+
4. Add swag to ~/IOTstack/docker-compose.yml beneath the `services:`-line:
235+
```
236+
swag:
237+
image: ghcr.io/linuxserver/swag
238+
cap_add:
239+
- NET_ADMIN
240+
environment:
241+
- PUID=1000
242+
- PGID=1000
243+
- TZ=Etc/UTC
244+
- URL=<yourdomain>.duckdns.org
245+
- SUBDOMAINS=wildcard
246+
- VALIDATION=duckdns
247+
- DUCKDNSTOKEN=<token>
248+
- CERTPROVIDER=zerossl
249+
- EMAIL=<e-mail> # required when using zerossl
250+
volumes:
251+
- ./volumes/swag/config:/config
252+
ports:
253+
- 443:443
254+
restart: unless-stopped
255+
```
256+
5. Start the swag container (creates the file to be edited in the next step): `cd ~/IOTstack && docker-compose up -d` and check it started OK `docker-compose logs -f swag`
257+
6. Rename the file volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf.sample to remove .sample from the filename.
258+
7. Enable reverse proxy to `raspberrypi.local` and fix homeassistant container name:
259+
```
260+
sed -i -e 's/server_name/server_name *.local/' \
261+
-e 's/upstream_app homeassistant/upstream_app home_assistant/' \
262+
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
263+
```
264+
8. Add password protection:
265+
```
266+
sed -i 's/#auth_basic/auth_basic/' volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
267+
docker-compose exec -it swag htpasswd -c /config/nginx/.htpasswd anyusername
268+
```
269+
8. Add `use_x_forwarded_for` and `trusted_proxies` to your homeassistant [http config](https://www.home-assistant.io/integrations/http). For a default install the result will be:
270+
```
271+
http:
272+
use_x_forwarded_for: true
273+
trusted_proxies:
274+
- 172.16.0.0/12
275+
- 10.77.0.0/16
276+
```
277+
9. Refresh the stack: `cd ~/IOTstack && docker-compose stop && docker-compose up -d`
278+
10. Test homeassistant is still working correctly: `http://raspberrypi.local:8123/` (assuming your RPi hostname is raspberrypi)
279+
11. Test the reverse proxy is working correctly: `https://raspberrypi.local/` (note: https)
280+
12. And finally test your router forwards correctly by accessing it from outside your LAN(e.g. using a mobile phone): `https://homeassistant.<yourdomain>.duckdns.org/`
281+
225282
## <a name="deactivateHassio"> Deactivating Hass.io </a>
226283
227284
Because Hass.io is independent of IOTstack, you can't deactivate it with any of the commands you normally use for IOTstack.

0 commit comments

Comments
 (0)