Skip to content

Commit 1c4400c

Browse files
committed
homeassistant: add docs for https reverse proxy setup
1 parent cab8b39 commit 1c4400c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/Containers/Home-Assistant.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,65 @@ $ 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+
networks:
256+
- iotstack_nw
257+
```
258+
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`
259+
6. Rename the file volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf.sample to remove .sample from the filename.
260+
7. Enable reverse proxy to `raspberrypi.local` and fix homeassistant container name:
261+
```
262+
sed -i -e 's/server_name/server_name *.local/' \
263+
-e 's/upstream_app homeassistant/upstream_app home_assistant/' \
264+
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
265+
```
266+
8. Add password protection:
267+
```
268+
sed -i 's/#auth_basic/auth_basic/' volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
269+
docker-compose exec -it swag htpasswd -c /config/nginx/.htpasswd anyusername
270+
```
271+
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:
272+
```
273+
http:
274+
use_x_forwarded_for: true
275+
trusted_proxies:
276+
- 172.16.0.0/12
277+
- 10.77.0.0/16
278+
```
279+
9. Refresh the stack: `cd ~/IOTstack && docker-compose stop && docker-compose up -d`
280+
10. Test homeassistant is still working correctly: `http://raspberrypi.local:8123/` (assuming your RPi hostname is raspberrypi)
281+
11. Test the reverse proxy is working correctly: `https://raspberrypi.local/` (note: https)
282+
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/`
283+
225284
## <a name="deactivateHassio"> Deactivating Hass.io </a>
226285
227286
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)