To add RPis to the Home Assistant, we are installing on each RPi a Python script as a daemon that sends data via MQTT messages to the MQTT Broker installed on the Home Assistant.
Unfortunately, if your Home Assistant is also running on an RPi but based on HAOSS, you can not use that approach. Later more to that.
First, install the MQTT Integration on the Home Assistant.
Just make sure that the automatic detection of MQTT devices is still enabled.
Then go to System / Add-Ons / Mosquitto Broker. Make sure it’s started while booting.
Under Configuration, add a username and a password. The YAML Code looks like this:
Now, let’s go to the RPi that we want to control. We need to install the script there. This includes the daemon that sends the MQTT messages to the Home Assistant.
You should also accompany this with backing up the files on at least two different physical devices, either via rsync or FTP or rclone, best running via a cron job.
Restore
There is no automated restore process to prevent accidental data loss. So if you need to restore a backup, you need to do this manually by following the steps below (assuming your backups are located at ./backup/ and your vaultwarden data is located at /var/lib/docker/volumes/vaultwarden/_data/)
# Delete any existing sqlite3 files
rm /var/lib/docker/volumes/vaultwarden/_data/db.sqlite3*
# Extract the archive
# You may need to install xz first
tar -xJvf ./backup/data.tar.xz -C /var/lib/docker/volumes/vaultwarden/_data/
Wow, how easy is it to set up a WireGuard VPN with the Raspberry Pi!
I can now cover the following use cases:
Access all the devices of my local network (router, RPis, drives, etc.) from abroad
Access German streaming services like ARD, ZDF, … from abroad
Getting there was not so easy. First, I had the idea of using the FritzBox’s VPN. But it turned out that the FritzBox only supports IPSec, and Android bigger than V11 does not support that. So, I decided to go for another solution.
I also had an RPi4 lying around after I had upgraded my website to the RPi5.
So I installed the Raspberry PI OS (64-BIT) on the RPi4.
State-of-the-art installations are based on docker.
After setting up the docker containers for WordPress and the NGINX Proxy Manager I still had one open issue: Sending mail was not possible. So I was looking for a solution to set up mail for the WordPressDocker setup.
I had the following options in mind:
Setting up a separate docker container with an e-mail server. More or less I just needed a so-called Smarthost, that takes sent-out e-mails from any docker container and forwards them to my e-mail provider, Gmail. I struggled to find a proper, small image of a mail server running on an RPi for a long time. Then open the ports of the WordPress containers and send the e-mail from the WordPress containers to the container with the Smarthost Mail server. Nevertheless, you must install any kind of mailer within the container to handle the mail() call coming from WordPress.
Set up an email server on the host (I used exim4) and let all Docker containers send their e-mails to the host, which will then be forwarded to the real e-mail provider by exim4. Still, you must install any kind of mailer within the container to handle the mail() call coming from WordPress. There were the following sub steps necessary:
Add also the local Home Assistant server/Port as the target
Reconfigure the port forwarding of the router to the NPM
Shutdown the old RPi4
So, let’s dive a little bit deeper into the different steps.
Configure the new RPi5 hardware and software
OK, let’s get the first new hardware, which means the new high-performance RPi5.
It took some time to be available on the market and the announced performance numbers looked promising.
As the power supply is quite strong I attached directly a SSD drive to the USB3 port.
So no need anymore for a USB hub!
Installing the latest Rasbian operating system on the SSD was pretty easy using the Raspian Imager.
I also configured the SSH access for it, of course.
So, how are we going further?
Install docker on the RPi5
As I wanted to run a WordPress life system and a WordPress staging system in my local network, I thought it would be a good idea to go with:
Docker to run multiple images/containers
Nginx Reverse Proxy to manage/route the traffic to/from these containers to the outside world
Install the docker containers
Setup a docker network manually
docker network create dockerwp
Create a directory for wp_prod, wp_staging, nginx
Define a file for common parameters used as anonymized volumes in the docker containers
Create docker-compose.yml for the Nginx Proxy
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
container_name: nginx-proxy
restart: unless-stopped
ports:
# These ports are in format <host-port>:<container-port>
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
# Add any other Stream port you want to expose
# - '21:21' # FTP
# Uncomment the next line if you uncomment anything in the section
# environment:
# Uncomment this if you want to change the location of
# the SQLite DB file within the container
# DB_SQLITE_FILE: "/data/database.sqlite"
# Uncomment this if IPv6 is not enabled on your host
# DISABLE_IPV6: 'true'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
networks:
dockerwp:
external: true
Create docker-compose.yml for the MariaDB and the WordPress container (one for the staging and one for the production system)
As I backed up the WordPress blog site with updraft, we are restoring the backup to the new WordPress staging and WordPress production system, respectively.
Configure the Sub-Domains
Go to your DNS provider and configure the new Sub-domains with a CNAME entry.
If you have a dynamic IP address, route the Sub-Domain entries to the same Dynamic DNS entry of your DynDNS Provider.
Configure the NPM
Define the target of the routing for all the Sub-Domains, e.g. the Ports of your WordPress containers.
Let the Sub-Domain for the Home Assistant point to the separate HA RPi3.
Add the SSL certificates from Let’s Encrypt.
Additional configuration for the Home Assistant
We must add the following configuration steps to make the Home Assistant run with an external Sub Domain, based on ademalidurmus.
1.) At the NPM, enter the following entry in the advanced config for the Home Assistant Host.