Skip to content

Instantly share code, notes, and snippets.

@jakzal
Last active November 22, 2023 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakzal/913295a03b67b1111b4dad0413189fc4 to your computer and use it in GitHub Desktop.
Save jakzal/913295a03b67b1111b4dad0413189fc4 to your computer and use it in GitHub Desktop.
Raspberry PI 4 / RaspBee II / Docker / Home Assistant

Raspberry Pi OS installation

Install Raspberry Pi OS Lite 64bit with the Raspberry Pi Imager.

Enable ssh with key authentication, change the host name, set the user password, the WiFi password. etc.

Configuration

  1. Boot the Pi.

  2. Disable MAC randomization

In order for the router to be able to assign Pi a static IP.

In /etc/NetworkManager/conf.d/100-disable-wifi-mac-randomization.conf:

[connection]
wifi.cloned-mac-address=preserve
[device]
wifi.scan-rand-mac-address=no
  1. Configure wifi with the NetworkManager

This needs to be done on a cable connection or with a keyboard/monitor pluggined in to your PI.

sudo service NetworkManager start
nmcli dev wifi list
sudo nmcli dev wifi connect "<network-ssid>" password "<password>"
nmcli device status

Enable the NetworkManager service:

sudo raspi-config

Advanced Options -> Network Config -> NetworkManager.

The rest of the setup can be done on wifi.

  1. Enable uart

This is RaspBee specific.

In /boot/config.txt:

enable_uart=1
#dtoverlay=miniuart-bt

Alternatively:

sudo raspi-config

Interfacing Options -> Serial:

  • Would you like a login shell accessible over serial? → No
  • Would you like the serial port hardware to be enabled? → Yes
  1. Update motd.
sudo vi /etc/motd
                _  _         _
  /\/\    __ _ | |(_) _ __  | | __  __ _
 /    \  / _` || || || '_ \ | |/ / / _` |
/ /\/\ \| (_| || || || | | ||   < | (_| |
\/    \/ \__,_||_||_||_| |_||_|\_\ \__,_|
  1. Reboot.

Install Home Assistant and Docker

  1. Install Home Assistant dependencies.
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install apparmor cifs-utils jq wget curl udisks2 libglib2.0-bin network-manager dbus systemd-journal-remote lsb-release nfs-common systemd-resolved -y
sudo apt --fix-broken install
sudo reboot
  1. Install docker.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker pi
rm get-docker.sh
  1. Install Home Assistant OS agent.

https://github.com/home-assistant/os-agent/releases/latest

wget https://github.com/home-assistant/os-agent/releases/download/1.6.0/os-agent_1.6.0_linux_aarch64.deb
sudo dpkg -i os-agent_1.6.0_linux_aarch64.deb
rm os-agent_1.6.0_linux_aarch64.deb

https://github.com/home-assistant/supervised-installer

wget https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb
sudo dpkg -i --ignore-depends=systemd-resolved homeassistant-supervised.deb
rm homeassistant-supervised.deb

Choose raspberrypi4-64 as a machine type, unless running a 32bit version of Raspberry Pi OS (in which case, select raspberrypi4).

  1. Enable apparmor in case it wasn't enabled.
sudo systemctl enable --now apparmor.service

Add the following parameters to the kernel boot parameters in /boot/cmdline.txt:

apparmor=1 security=apparmor systemd.unified_cgroup_hierarchy=0
  1. Reboot.

Configure the deCONZ addon

deCONZ can be installed as a Home Assistant addon via the UI. The addon needs to be configured to use /dev/ttyS0 (/dev/ttyAMA0 if miniuart-bt dtoverlay is enabled).

Any existing configuration needs to be put to /usr/share/hassio/addons/data/core_deconz/.local/share/dresden-elektronik/deCONZ.

Configure the cloudflared addon.

Configure ddclient.service

/lib/systemd/system/ddclient.service:

[Unit]
Description=DDClient
Requires=docker.service
After=network.target docker.service

[Service]
Restart=always
RestartSec=5s
ExecStart=/usr/bin/docker run -t --rm --name=ddclient -e PUID=1000 -e PGID=1000 -e TZ=Etc/UTC -v /etc/ddclient:/config lscr.io/linuxserver/ddclient:latest
ExecStop=-/usr/bin/docker stop ddclient

[Install]
WantedBy=multi-user.target

/etc/ddclient/ddclient.conf:

daemon=1200
syslog=yes
ssl=yes
use=web
web='https://cloudflare.com/cdn-cgi/trace'
web-skip='ip='
protocol=cloudflare
zone=example.com
ttl=1
password=api-token-value-here
example.com
sudo systemctl enable ddclient.service
sudo systemctl start ddclient.service

Resources

Alternative deCONZ installation

https://phoscon.de/en/raspbee2/install#docker https://github.com/marthoc/docker-deconz/blob/a2e273cb5f6da8c95f283db51816652afd57e21b/README.md

  1. Configure
mkdir -p ~/.local/share/dresden-elektronik/deCONZ
  1. Test run
docker run \
   --name=deconz \
   --net=host \
   --rm \
   -v /etc/localtime:/etc/localtime:ro \
   -v /home/pi/.local/share/dresden-elektronik/deCONZ:/root/.local/share/dresden-elektronik/deCONZ \
   --device=/dev/ttyS0 \
   -e DECONZ_DEVICE=/dev/ttyS0 \
   marthoc/deconz
  1. Startup script

/lib/systemd/system/deconz.service:

[Unit]
Description=deCONZ
Requires=docker.service
After=docker.service dbus.socket

[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStartPre=-/usr/bin/docker stop deconz
ExecStart=/usr/bin/docker run --rm --name=deconz --net=host -v /etc/localtime:/etc/localtime:ro -v /home/pi/.local/share/dresden-elektronik/deCONZ:/root/.local/share/dresden-elektronik/deCONZ --device=/dev/ttyS0 -e DECONZ_DEVICE=/dev/ttyS0 marthoc/deconz
ExecStop=-/usr/bin/docker stop deconz

[Install]
WantedBy=multi-user.target
systemctl enable deconz.service
systemctl start deconz.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment