Skip to content

Commit b29d361

Browse files
committed
20220327 Home Assistant documentation
Repairs broken internal hyperlinks by restoring internal anchors. Restored anchors converted to null-anchor form. Fixes some spacing and alignment errors (apparent in MacDown authoring tool). Prefers multi-line command syntax over `&&` form which can be confusing to new users (quasi standard followed in other IOTstack documentation). Prefers `$ ` prompt form for commands users should execute. This is another quasi-standard. Explicitly sets `cd ~/IOTstack` where its omission might produce unexpected results. Adds code-fence rendering hints where appropriate. Signed-off-by: Phill Kelley <[email protected]>
1 parent 9cc8533 commit b29d361

File tree

1 file changed

+74
-57
lines changed

1 file changed

+74
-57
lines changed

docs/Containers/Home-Assistant.md

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Home Assistant is a home automation platform. It is able to track and control all devices at your home and offer a platform for automating control.
44

5-
## References
5+
## <a name="references"></a>References
66

77
- [Home Assistant home page](https://www.home-assistant.io/)
88

@@ -13,7 +13,7 @@ Home Assistant is a home automation platform. It is able to track and control al
1313
- [DockerHub](https://hub.docker.com/r/homeassistant/home-assistant/)
1414

1515

16-
## Home Assistant: two versions
16+
## <a name="twoVersions"></a>Home Assistant: two versions
1717

1818
There are two versions of Home Assistant:
1919

@@ -31,7 +31,7 @@ Technically, both versions of Home Assistant can be installed on your Raspberry
3131

3232
IOTstack used to offer a menu entry leading to a convenience script that could install Supervised Home Assistant but that stopped working when Home Assistant changed their approach. Now, the only method supported by IOTstack is Home Assistant Container.
3333

34-
### Installing Home Assistant Container
34+
### <a name="installHAContainer"></a>Installing Home Assistant Container
3535

3636
Home Assistant (Container) can be found in the `Build Stack` menu. Selecting it in this menu results in a service definition being added to:
3737

@@ -56,7 +56,7 @@ $ cd ~/IOTstack
5656
$ docker-compose up -d
5757
```
5858

59-
### Installing Supervised Home Assistant
59+
### <a name="installHASupervised"></a>Installing Supervised Home Assistant
6060

6161
The direction being taken by the Home Assistant folks is to supply a ready-to-run image for your Raspberry Pi. That effectively dedicates your Raspberry Pi to Home Assistant and precludes the possibility of running alongside IOTstack and containers like Mosquitto, InfluxDB, Node-RED, Grafana, PiHole and WireGuard.
6262

@@ -106,12 +106,12 @@ The first time you use PiBuilder, the process boils down to:
106106

107107
where «name» is the name you give to your Raspberry Pi (eg "iot-hub").
108108

109-
After step 9, Supervised Home Assistant will be running. The `04_setup.sh` script also deals with the [random MACs](#why-random-macs-are-such-a-hassle) problem. After step 11, you'll be able to either:
109+
After step 9, Supervised Home Assistant will be running. The `04_setup.sh` script also deals with the [random MACs](#aboutRandomMACs) problem. After step 11, you'll be able to either:
110110

111111
1. Restore a backup; or
112112
2. Run the IOTstack menu and choose your containers.
113113

114-
## Why random MACs are such a hassle
114+
## <a name="aboutRandomMACs"></a>Why random MACs are such a hassle
115115

116116
> This material was originally posted as part of [Issue 312](https://github.com/SensorsIot/IOTstack/issues/312). It was moved here following a suggestion by [lole-elol](https://github.com/lole-elol).
117117
@@ -171,7 +171,8 @@ Random MACs are not a problem for a **client** device like a phone, tablet or la
171171
172172
It is not just configuration-time SSH sessions that break. If you decide to leave Raspberry Pi random Wifi MAC active **and** you have other clients (eq IoT devices) communicating with the Pi over WiFi, you will wrong-foot those clients each time the Raspberry Pi reboots. Data communications services from those clients will be impacted until those client devices time-out and catch up.
173173

174-
## Using bluetooth from the container
174+
## <a name="usingBluetooth"></a>Using bluetooth from the container
175+
175176
In order to be able to use BT & BLE devices from HA integrations, make sure that bluetooth is enabled and powered on at the start of the (Rpi) host by editing `/etc/bluetooth/main.conf`:
176177

177178
```conf
@@ -190,7 +191,7 @@ UP
190191
```
191192
ref: https://scribles.net/auto-power-on-bluetooth-adapter-on-boot-up/
192193

193-
## HTTPS with a valid SSL certificate
194+
## <a name="httpsWithSSLcert"></a>HTTPS with a valid SSL certificate
194195

195196
Some HA integrations (e.g google assistant) require your HA API to be
196197
accessible via https with a valid certificate. You can configure HA to do this:
@@ -209,77 +210,91 @@ your RPi hostname is raspberrypi)
209210
2. Make sure you have duckdns working.
210211
3. On your internet router, forward public port 443 to the RPi port 443
211212
4. Add swag to ~/IOTstack/docker-compose.yml beneath the `services:`-line:
212-
```
213-
swag:
214-
image: ghcr.io/linuxserver/swag
215-
cap_add:
216-
- NET_ADMIN
217-
environment:
218-
- PUID=1000
219-
- PGID=1000
220-
- TZ=Etc/UTC
221-
- URL=<yourdomain>.duckdns.org
222-
- SUBDOMAINS=wildcard
223-
- VALIDATION=duckdns
224-
- DUCKDNSTOKEN=<token>
225-
- CERTPROVIDER=zerossl
226-
- EMAIL=<e-mail> # required when using zerossl
227-
volumes:
228-
- ./volumes/swag/config:/config
229-
ports:
230-
- 443:443
231-
restart: unless-stopped
232-
```
233-
Replace the bracketed values. Do NOT use any "-characters to enclose the values.
213+
214+
```yaml
215+
swag:
216+
image: ghcr.io/linuxserver/swag
217+
cap_add:
218+
- NET_ADMIN
219+
environment:
220+
- PUID=1000
221+
- PGID=1000
222+
- TZ=Etc/UTC
223+
- URL=<yourdomain>.duckdns.org
224+
- SUBDOMAINS=wildcard
225+
- VALIDATION=duckdns
226+
- DUCKDNSTOKEN=<token>
227+
- CERTPROVIDER=zerossl
228+
- EMAIL=<e-mail> # required when using zerossl
229+
volumes:
230+
- ./volumes/swag/config:/config
231+
ports:
232+
- 443:443
233+
restart: unless-stopped
234+
```
235+
236+
Replace the bracketed values. Do NOT use any "-characters to enclose the values.
234237

235238
5. Start the swag container, this creates the file to be edited in the next step:
236-
```
237-
cd ~/IOTstack && docker-compose up -d
238-
```
239239

240-
Check it starts up OK: `docker-compose logs -f swag`. It will take a minute or two before it finally logs "Server ready".
240+
```bash
241+
$ cd ~/IOTstack
242+
$ docker-compose up -d
243+
```
244+
245+
Check it starts up OK: `docker-compose logs -f swag`. It will take a minute or two before it finally logs "Server ready".
241246

242247
6. Enable reverse proxy for `raspberrypi.local`. `homassistant.*` is already by default. and fix homeassistant container name ("upstream_app"):
243-
```
244-
sed -e 's/server_name/server_name *.local/' \
245-
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf.sample \
246-
> volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
247-
```
248+
249+
```bash
250+
$ cd ~/IOTstack
251+
$ sed -e 's/server_name/server_name *.local/' \
252+
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf.sample \
253+
> volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
254+
```
248255

249256
7. Forward to correct IP when target is a container running in "network_mode:
250257
host" (like Home Assistant does):
251-
```
252-
cat << 'EOF' | sudo tee volumes/swag/config/custom-cont-init.d/add-host.docker.internal.sh
253-
#!/bin/sh
254-
DOCKER_GW=$(ip route | awk 'NR==1 {print $3}')
255-
256-
sed -i -e "s/upstream_app .*/upstream_app ${DOCKER_GW};/" \
257-
/config/nginx/proxy-confs/homeassistant.subdomain.conf
258-
EOF
259-
sudo chmod u+x volumes/swag/config/custom-cont-init.d/add-host.docker.internal.sh
260-
```
258+
259+
```bash
260+
cd ~/IOTstack
261+
cat << 'EOF' | sudo tee volumes/swag/config/custom-cont-init.d/add-host.docker.internal.sh
262+
#!/bin/sh
263+
DOCKER_GW=$(ip route | awk 'NR==1 {print $3}')
264+
265+
sed -i -e "s/upstream_app .*/upstream_app ${DOCKER_GW};/" \
266+
/config/nginx/proxy-confs/homeassistant.subdomain.conf
267+
EOF
268+
sudo chmod u+x volumes/swag/config/custom-cont-init.d/add-host.docker.internal.sh
269+
```
270+
261271
(This needs to be copy-pasted/entered as-is, ignore any "> "-prefixes printed
262272
by bash)
263273

264274
8. (optional) Add reverse proxy password protection if you don't want to rely
265275
on the HA login for security, doesn't affect API-access:
266-
```
267-
sed -i -e 's/#auth_basic/auth_basic/' \
268-
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
269-
docker-compose exec swag htpasswd -c /config/nginx/.htpasswd anyusername
270-
```
276+
277+
```bash
278+
$ cd ~/IOTstack
279+
$ sed -i -e 's/#auth_basic/auth_basic/' \
280+
volumes/swag/config/nginx/proxy-confs/homeassistant.subdomain.conf
281+
$ docker-compose exec swag htpasswd -c /config/nginx/.htpasswd anyusername
282+
```
283+
271284
9. Add `use_x_forwarded_for` and `trusted_proxies` to your homeassistant [http
272285
config](https://www.home-assistant.io/integrations/http). The configuration
273286
file is at `volumes/home_assistant/configuration.yaml` For a default install
274287
the resulting http-section should be:
275-
```
288+
289+
```yaml
276290
http:
277291
use_x_forwarded_for: true
278292
trusted_proxies:
279293
- 192.168.0.0/16
280294
- 172.16.0.0/12
281295
- 10.77.0.0/16
282296
```
297+
283298
10. Refresh the stack: `cd ~/IOTstack && docker-compose stop && docker-compose
284299
up -d` (again may take 1-3 minutes for swag to start if it recreates
285300
certificates)
@@ -292,10 +307,12 @@ your RPi hostname is raspberrypi)
292307
are just testing)
293308

294309
Or from the command line in the RPi:
295-
```
296-
curl --resolve homeassistant.<yourdomain>.duckdns.org:443:127.0.0.1 \
310+
311+
```bash
312+
$ curl --resolve homeassistant.<yourdomain>.duckdns.org:443:127.0.0.1 \
297313
https://homeassistant.<yourdomain>.duckdns.org/
298314
```
315+
299316
(output should end in `if (!window.latestJS) { }</script></body></html>`)
300317

301318
13. And finally test your router forwards correctly by accessing it from

0 commit comments

Comments
 (0)