DrkPxl Logo

Home Assistant, Cloudflared, Portainer Setup

Assuming you have Raspberry Pi 4 or newer..

1. Flash the latest 64 bit Raspberry Pi OS image.. As of this documenting it was:

wget https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2021-11-08/

Use Ctrl + Shift + X to get in the super secret config screen to set up SSH and other settings.

Secret Pi Menu

2. Get the latest updates

sudo apt-get update && sudo apt-get upgrade -y

Install needed software: App Armor, Network Manager, jq

sudo apt-get install jq wget curl avahi-daemon udisks2 libglib2.0-bin network-manager dbus apparmor -y
sudo apt --fix-broken install # Fix missing dependencies if needed

Download Cloudflared and unpack

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb
sudo dpkg -i cloudflared-linux-arm64.deb
cloudflared -v # Verify Working

Reboot with sudo reboot

3. Install Home Assistant

It's important to do these steps before configuring or setting up anything else. Home Assistant really really really wants to be on its own and doesn't like other software to get its way.

Install docker and setup

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker pi # add Pi as docker user, change if you are using differ username
docker --version # check that docker is installed and exists.

Download Agent and Supervisor for Home Assistant and unpackage

wget https://github.com/home-assistant/os-agent/releases/download/1.2.2/os-agent_1.2.2_linux_aarch64.deb
sudo dpkg -i os-agent_1.2.2_linux_aarch64.deb
gdbus introspect --system --dest io.hass.os --object-path /io/hass/os  # verify installation
wget https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb
sudo dpkg -i homeassistant-supervised.deb
Architecture Selection

At this point you may need to wait a few beats so everything can get setup. Be patient.

You can watch the progress of the setup 2 ways..

  1. Going to port 4357 of your Raspberry Pi's IP. In my case: http://192.168.0.119:4357/
Home Assistant Observer
  1. Reading the logs: sudo ha supervisor logs

Once those complete you should be able to view your sucessful home assistant install at the Raspberry Pi's IP address and port 8123. In my case: http://192.168.0.119:8123/onboarding.html

From here you can either setup up new (which there are many many good guides out there), or restore from backup. I had an old non-containerized install on Home Assistant OS so I restored from backup.. Be warned it can take some time and the web interface looks like it's broken. Just upload the backup and wait 10-15 minutes if you have a very custom HA setup like I do. You can check the progress of the backup restore in the logs using; sudo ha supervisor logs

At this point you should have a fully set-up and usable Home Assistant setup. Now lets keep going...

4. Install Portainer to manage our Docker images

sudo docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:linux-arm64

With that Portainer should be up and running on port 9000. In my case: http://192.168.0.119:9000/#!/init/admin

Set up password and login.. Voila there is portainer running alongside Home Assistant. You can see that Portainer picks up the Home Assistant Supervisor created Docker containers.

Portainer

5. Now Back to Cloudflare

Now that we are all setup and have Home Assistant running along with some other apps like Whoogle we can get the Cloudflare tunnel up and running. I am going to already assume you have a domain on Cloudflare. To that there are a few easy steps:

  1. Login with: cloudflared login
  2. Create a new tunnel with the name of your choice with: cloudflared tunnel create <NAME>
  3. Save the ID you get back somewhere for later
  4. Create a new configuation file here: sudo nano ~/.cloudflared/config.yml
  5. Edit it with information such as the following:
tunnel: XXX-XXX-XXX-XX
credentials-file: /root/.cloudflared/XXXXX-XXX-XX_X-XX.json

ingress:
  - hostname: portainer.yournewdomainname.com
    service: http://localhost:9000
  - hostname: pihole.yournewdomainname.com
    service: http://localhost:80
  - hostname: search.yournewdomainname.com
    service: http://localhost:5000
  - service: http_status:404

  1. Create new DNS records in Cloudflare from the command line:
cloudflared tunnel route dns XXx-XXX-XXX-XX portainer
cloudflared tunnel route dns XXx-XXX-XXX-XX pihole
cloudflared tunnel route dns XXx-XXX-XXX-XX search
  1. Double check config and start her up:
cloudflared tunnel ingress validate
cloudflared tunnel run XXx-XXX-XXX-XX
  1. Set up Cloudflare to run as service
sudo mv /home/pi/.cloudflared/config.yml /etc/cloudflared/
sudo cloudflared service install 

If you ever need to restart use: sudo systemctl restart cloudflared.service

How to Install Home Assistant Hassio in Docker in Ubuntu Cloudflare Tunnels on Pi

Some Installs I use

Heimdall - Bookmark Manager
Whoogle - Self hosted search backed by Google but without the tracking.
Omada Controller - Controller for my Load Balancing Router

Use Ctrl + Shift + X to get in the super secret config screen to set up SSH and other settings.