Skip to content

Instantly share code, notes, and snippets.

@jakzal
Last active March 8, 2025 14:16
Show Gist options
  • Select an option

  • Save jakzal/913295a03b67b1111b4dad0413189fc4 to your computer and use it in GitHub Desktop.

Select an option

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. Enable uart

This is RaspBee specific.

In /boot/firmware/config.txt:

enable_uart=1
dtparam=i2c_arm=on
dtparam=i2c_vc=on
#dtoverlay=miniuart-bt
dtoverlay=i2c-rtc,pcf85063
#force_turbo=1
#core_freq=250
#core_min_freq=250

Alternatively:

sudo raspi-config

Interface Options -> Serial Port:

  • Would you like a login shell accessible over serial? → No
  • Would you like the serial port hardware to be enabled? → Yes

It might be needed to disable the hciuart service:

sudo systemctl disable hciuart.service
  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.

See https://docs.docker.com/engine/install/debian/#install-using-the-repository

See https://docs.docker.com/engine/install/linux-postinstall/

Configure the journald logging driver in /etc/docker/daemon.json.

  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.7.2/os-agent_1.7.2_linux_aarch64.deb
sudo dpkg -i os-agent_1.7.2_linux_aarch64.deb
rm os-agent_1.7.2_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/firmware/cmdline.txt:

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

Update RaspBee II firmware

https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Update-deCONZ-manually#update-in-docker

Configure ZHA

Configure the deCONZ addon (alternatively to ZHA)

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 /var/lib/homeassistant/addons/data/core_deconz/ (previously /usr/share/hassio/addons/data/core_deconz/.local/share/dresden-elektronik/deCONZ).

Configure the cloudflared addon.

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

ddclient.service (optional)

/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment