180 lines
7.4 KiB
Plaintext
180 lines
7.4 KiB
Plaintext
Create user and group
|
|
---------------------
|
|
Credentials -> Local Users -> Add
|
|
Full Name: home-assistant
|
|
Username: hmeassist
|
|
Disable Password: <select>
|
|
Email: stuurmcp@telkomsa.net
|
|
UID: (note)
|
|
Create New Primary Group: <select>
|
|
Create Home Directory: <uncheck>
|
|
Samba Authentication: <uncheck>
|
|
Save
|
|
|
|
hmeassist UID: 3038
|
|
hmeassist GID: 3037
|
|
|
|
Create datasets
|
|
---------------
|
|
# In Truenas shell:
|
|
# list datasets
|
|
zfs list | grep -i "docker.*home-assistant"
|
|
# create following datasets if not present
|
|
zfs create SSD1/docker/data/home-assistant/config
|
|
zfs create SSD1/docker/data/home-assistant/pgbackups
|
|
zfs create SSD1/docker/data/home-assistant/pgdata
|
|
chown -R hmeassist:hmeassist /mnt/SSD1/docker/data/home-assistant
|
|
chown pguser:pguser /mnt/SSD1/docker/data/home-assistant/pgbackups
|
|
chown pguser:pguser /mnt/SSD1/docker/data/home-assistant/pgdata
|
|
|
|
Create folders
|
|
--------------
|
|
# In Truenas shell:
|
|
mkdir -p /mnt/SSD1/docker/stacks/home-assistant/secrets
|
|
|
|
Copy folder to docker stacks
|
|
----------------------------
|
|
# In Windows cmd shell in home-assistant folder, enter:
|
|
./cp2nas
|
|
# or
|
|
pscp -P 22 -r stacks/*.* root@192.168.2.2:/mnt/SSD1/docker/stacks/home-assistant/
|
|
# This should copy home-assistant stacks folder to /mnt/SSD1/docker/stacks/home-assistant
|
|
|
|
Create secrets
|
|
--------------
|
|
# In Truenas shell:
|
|
cd /mnt/SSD1/docker/stacks/home-assistant/secrets
|
|
echo -n 'your_db_name' > /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_database
|
|
echo -n 'your_db_user' > /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_username
|
|
openssl rand 36 | base64 -w 0 > /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_password
|
|
# restrict access
|
|
cd /mnt/SSD1/docker/stacks/home-assistant
|
|
chown -R hmeassist:hmeassist secrets/
|
|
chmod -R 400 secrets/
|
|
# read existing acl permissions, if any
|
|
getfacl /mnt/SSD1/docker/stacks/home-assistant/secrets
|
|
# set acl permissions
|
|
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/home-assistant/secrets
|
|
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_password
|
|
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_username
|
|
setfacl -m u:postgres:4 /mnt/SSD1/docker/stacks/home-assistant/secrets/home-assistant_postgresql_database
|
|
# NB! if you want to remove all acl entries from a folder recursively, use setfacl -b -R <foldername>
|
|
|
|
Backup home-assistant database
|
|
--------------------------
|
|
# In truenas shell:
|
|
mkdir /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
|
|
chown pgadmin:pgadmin /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
|
|
# Using browser, log in to pgAdmin on truenas
|
|
# Connect to servers; refer to "connecting to servers.txt", which also explains how to obtain db passwords
|
|
# To perform plain text backup:
|
|
# Navigate to Servers => home-assistant -> Databases -> home-assistant
|
|
# Right click on home-assistant database and select Backup...
|
|
# Enter the following on the different tabs of dialog box that opened:
|
|
General:
|
|
# Replace ##### with date in YYYY-MM-DD format when backup is being made
|
|
Filename: /#####/home-assistant-backup.sql (this maps to: /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/#####/home-assistant-backup.sql on truenas)
|
|
# Or click on folder icon and navigate to the folder that was created above. Enter home-assistant-backup.sql in Save As field, then click on Create
|
|
Format: Plain
|
|
Encoding: UTF8
|
|
Role name: home-assistant
|
|
Data Options:
|
|
Sections:
|
|
Pre-data: <select>
|
|
Data: <select>
|
|
Post-data: <select>
|
|
Objects:
|
|
Check public to select all objects
|
|
Click Backup
|
|
# After backup, verify presence of backup file:
|
|
ls -al /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I)
|
|
# copy backup file(s) to home-assistant backups folder, replacing $(date -I) with date when backup was made if not today
|
|
cp -vr /mnt/stpool1/apps/pgadmin/storage/stuurmcp_telkomsa.net/$(date -I) /mnt/SSD1/docker/data/home-assistant/pgbackups
|
|
|
|
Migrating config storage (not effective)
|
|
------------------------
|
|
# Stop home-assistant on truenas, in truenas shell
|
|
heavyscript app --stop home-assistant
|
|
# copy config storage to new install data folder
|
|
cp -pr /mnt/stpool1/apps/home-assistant/* /mnt/SSD1/docker/data/home-assistant/config/
|
|
chown -R hmeassist:hmeassist /mnt/SSD1/docker/data/home-assistant/config/
|
|
# edit configuration.yml to apply values for new app
|
|
nano /mnt/SSD1/docker/data/home-assistant/config/configuration.yaml
|
|
# under recorder heading, change db_url to reflect the following, replacing <db_password> with actual password:
|
|
db_url: "postgresql://<your_db_user>:<db_password>@home-assistant_postgresql:5432/<your_db_name>?client_encoding=utf8"
|
|
"postgresql://home-assistant:M1ykv2TSzPD4c7lq4ixyBIl/q9kf4NyVIziQ3Yzansst4kZx@home-assistant_postgresql:5432/home-assistant?client_encoding=utf8"
|
|
# change http.trusted_proxies to reflect the traefik network:
|
|
trusted_proxies:
|
|
- 10.255.224.0/20
|
|
|
|
Migrating database (not effective)
|
|
------------------
|
|
# In truenas shell
|
|
jlmkr shell docker
|
|
cd /opt/stacks/home-assistant
|
|
docker compose down
|
|
# remove all files/folders from pgdata; if any are already in this folder with data to be retained, move it to another folder before executing next command
|
|
rm -r /mnt/data/home-assistant/pgdata/*
|
|
docker compose up -d
|
|
# After successfull startup of home-assistant and postgres, stop home-assistant from docker cmd line
|
|
docker stop home-assistant
|
|
docker exec home-assistant_postgresql psql -U <your_db_user> -d postgres -c "DROP DATABASE \"<your_db_name>\";"
|
|
docker exec home-assistant_postgresql psql -U <your_db_user> -d postgres -c "CREATE DATABASE \"<your_db_name>\";"
|
|
docker exec home-assistant_postgresql psql -U <your_db_user> -d <your_db_name> -f /mnt/backups/$(date -I)/home-assistant-backup.sql # replace $(date -I) with the appropriate date
|
|
docker start home-assistant
|
|
|
|
Stop truenas home-assistant
|
|
---------------------------
|
|
# In truenas shell
|
|
heavyscript app --stop home-assistant
|
|
# NB: Do NOT stop home-assistant with truenas gui
|
|
|
|
Setup MQTT integration
|
|
----------------------
|
|
# on home-assistant browser tab
|
|
# go to Settings -> Devices & services
|
|
# Click on ADD INTEGRATION
|
|
# Select MQTT
|
|
# Enter mosquitto info as per mosquitto installation
|
|
|
|
|
|
# IF DO NOT HAVE FRIGATE RUNNING BY ITSELF, YOU CAN INSTALL WITH HOME-ASSISTANT
|
|
Installing HACS
|
|
---------------
|
|
docker exec -it home-assistant bash
|
|
cd ~
|
|
wget -O - https://get.hacs.xyz | bash -
|
|
exit
|
|
docker restart home-assistant
|
|
#
|
|
Setup HACS integration
|
|
----------------------
|
|
# https://hacs.xyz/docs/use/configuration/basic/#to-set-up-the-hacs-integration
|
|
# after downloading HACS and restarting home-assistant:
|
|
# on home-assistant browser tab, press ctrl-F5
|
|
# go to Settings -> Devices & services
|
|
# Click on ADD INTEGRATION
|
|
# Select HACS
|
|
# Acknowledge the statements and select Submit
|
|
# Copy the device code and select the link https://github.com/login/device
|
|
# if required, sign up or sign in to github to continue the setup
|
|
# Enter the device code you copied in the previous step and select Continue
|
|
# Select Authorize HACS
|
|
# Once you see the confirmation screen, you can close the tab and go back to Home Assistant
|
|
# Assign HACS to an area and select Finish.
|
|
#
|
|
Setup Frigate on home-assistant
|
|
-------------------------------
|
|
# open home-assistant and select HACS
|
|
# type frigate in search text box
|
|
# select Frigate Hass Integration
|
|
# download and configure
|
|
|
|
|
|
If you need to log into db
|
|
--------------------------
|
|
docker exec -it home-assistant_postgresql bash
|
|
psql -U <your_db_user> -d <your_db_name>
|
|
|
|
|