Installing Home Assistant Core with uv package manager

I’m running DietPi on an Orange Pi 3 LTS and tried installing Home Assistant Core using the DietPi installer. I noted the warnings about it could take hours. After several hours, looks like it crashed so I uninstalled it/cleaned it up.

I’d previously installed Home Assistant on Windows/WSL using uv with good success, so thought I’d try it with DietPi. I had it installed and running in minutes.

A note on Home Assistant Core deprecation: the software isn’t being deprecated, just the support and documentation (and the Admin in the Home Assistant forum even mentions that DietPi was never supported anyway).

So I think DietPi should retain Home Assistant setup, but switch from using pyenv to uv. On cheap arm hardware the setup process difference is from hours to minutes.

Here’s the script I used for a standalone setup on DietPi:

#!/bin/bash

# Install minimal system-level dependencies
sudo apt update
sudo apt install -y curl libffi-dev libssl-dev ffmpeg build-essential libturbojpeg0 libpcap0.8

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Ensure uv is in PATH
export PATH="$HOME/.local/bin:$PATH"
uv --version || { echo "uv installation failed"; exit 1; }

# Set up Home Assistant as dietpi user
sudo -u dietpi mkdir -p /home/dietpi/home-assistant
cd /home/dietpi/home-assistant
sudo -u dietpi /home/dietpi/.local/bin/uv init --python 3.13
sudo -u dietpi /home/dietpi/.local/bin/uv add homeassistant

# Update Home Assistant dependencies
sudo -u dietpi /home/dietpi/.local/bin/uv sync

# Ensure permissions
sudo chown -R dietpi:dietpi /home/dietpi/home-assistant
sudo usermod -aG netdev dietpi

# Create systemd service file
sudo bash -c 'cat << EOF > /etc/systemd/system/home-assistant.service
[Unit]
Description=Home Assistant
After=network-online.target
Requires=network-online.target

[Service]
Type=simple
User=dietpi
WorkingDirectory=/home/dietpi/home-assistant
ExecStart=/home/dietpi/home-assistant/.venv/bin/hass
Environment="HOME=/home/dietpi"
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF'

# Set permissions and enable service
sudo chmod 644 /etc/systemd/system/home-assistant.service
sudo systemctl daemon-reload
sudo systemctl enable home-assistant.service

# Open firewall port for Home Assistant (port 8123)
sudo ufw allow 8123 2>/dev/null || true

# Start the service
sudo systemctl start home-assistant.service

# Check service status
sudo systemctl status home-assistant.service

Note Home Assistant switched to using uv for their internal builds last year.

2 Likes

Right, same is true for 32-bit support. In that case, it means that it could break, in case HA starts to pull 64-bit only dependencies/versions, but Python has been quire resilient in these regards so far.

And yes, it makes sense for us to switch to uv. The idea came up here: Debian Trixie | Testing and migration script · Issue #7644 · MichaIng/DietPi · GitHub
Not sure whether pre-compiled Python is available for ARMv6 and RISC-V as well, but still better to skip the lengthy compilation at least for some architectures. And HA internally uses uv for its ondemand dependencies as well, so it would be an alignment in this regards as well.

Please do not use the dietpi user, as we plan to remove it. People tend to copy&paste, so better use the homeassistant system user that we use for our current implementation already, and will keep doing so after switching to uv as well.

Not sure whether I find time for this soon, so any PR is highly welcome.

2 Likes