April 05, 2024

Home Assistant core install, Raspberry Pi and Python 3.12

The best way to start with Home Assistant(HA), and Raspberry Pi(RPi), is off course to use the ”Raspberry Pi imager” and in the menu select "Other specific-purpose OS => Home Assistant and home automation => Home Assistant". This will install the HA operating system.

It works very well and here are the install instructions

On the other hand if you want to add HA to a RPi which you already have up and running, without Docker, you need to install something which is called "Home Assistant Core".

Please check the "Remarks" below before you start.


Intro
The first obstacle is that the latest HA, version 2024.4.0, demands Python 3.12 !! This Python version is not so easy to install even if you are running the latest Bookworm OS. Using "sudo apt install python3......." will install 3.11.

So after extensive Googling I found this amazing post where Pascal really makes it easy. This is absolutly the preferred method since it will not interfere with the default Python installation. Ask me I have tested a lot of ways. 😉

Here you find the official "Home Assistant Core" install documentation.

This installation is done on a RPi 3 with Bookworm Lite 64 bit and the hostname "test"

Installation
Install commands
With the following two commands you will add Pascals repository where we can find the Python 3.12 packages.

pi@test:~ $ wget  https://pascalroeleven.nl/deb-pascalroeleven.gpg && sudo mv deb-pascalroeleven.gpg /etc/apt/keyrings/

pi@test:~ $ cat <<EOF | sudo tee /etc/apt/sources.list.d/pascalroeleven.sources
Types: deb
URIs: http://deb.pascalroeleven.nl/python3.12
Suites: bookworm-backports
Components: main
Signed-By: /etc/apt/keyrings/deb-pascalroeleven.gpg
EOF

Then using "sudo apt update" will update your systems package list.

Install the dependencies


pi@test:~ $ sudo apt-get install -y python3.12 python3.12-dev python3.12-venv

pi@test:~ $ sudo apt-get install -y python3-pip bluez libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff6 libturbojpeg0-dev tzdata ffmpeg liblapack3 liblapack-dev libatlas-base-dev


add the user "homeassistant" and create the virtual evironment

pi@test:~ $ sudo useradd -rm homeassistant -G dialout,gpio,i2c
pi@test:~ $ sudo mkdir /srv/homeassistant
pi@test:~ $ sudo chown homeassistant:homeassistant /srv/homeassistant
pi@test:~ $ sudo -u homeassistant -H -s
homeassistant@test:/home/pi $ cd /srv/homeassistant
homeassistant@test:/srv/homeassistant $ python3.12 -m venv .
(homeassistant) homeassistant@test:/srv/homeassistant $ source bin/activate
(homeassistant) homeassistant@test:/srv/homeassistant $ python3.12 -m pip install wheel

and then HA

(homeassistant) homeassistant@test:/srv/homeassistant $ pip3.12 install homeassistant==2024.4.0

Start HA, which will take some time the first time starting up

(homeassistant) homeassistant@test:/srv/homeassistant $ hass

and then go to the URL below and set up HA

http://test.local:8123/

Autostart at boot and failure
Starting up HA as above will just work as long as the terminal session is active. Stop it with Ctrl+C and set up systemd

Create a file 

pi@test:~ $ sudo nano /etc/systemd/system/HA.service

and add the following

[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"
RestartForceExitStatus=100
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

start the service with

pi@test:~ $ sudo systemctl daemon-reload && sudo systemctl enable HA && sudo systemctl start HA

The service can be checked with 

pi@test:~ $ sudo systemctl status HA

Remarks
Config
The config is found here /home/homeassistant/.homeassistant/configuration.yaml

Add-ons
!! Please note that the application "Settings => Add-ons" isn't available when you have done a "core" install but there are often work arounds to get the wanted "Add-on" anyway. As an example check below how to install the add on HACS.

Discovery
The discovery function works a lot better connected via ethernet cable.(No WiFi)

Upgrade
Here you find how to + some other "nice to know". But use, "pip3.12" as below to upgrade.
(homeassistant) homeassistant@test:/home/pi $ pip3.12 install --upgrade homeassistant

HACS
Check HACS download help and choose the "Core" variant. Open a terminal and set the password for user "homeassistant", change user and then run the install script.

pi@test:~$ sudo passwd homeassistant

pi@test:~$ su - homeassistant

homeassistant@test:~$ wget -O - https://get.hacs.xyz | bash -


then continue with the "Initial Configuration".

NodeRed(NR)
With HA core upp and running install NodeRed. In NR install the node "node-red-contrib-home-assistant-websocket". The first test could be using the HA node "current state". Here is getting started and setting upp the server part. To get the "Entity ID" go to HA "Settings => Devices and services => Entities". Probably the weather with  ID "weather.forecast_home" are there to test with. 

2 comments:

  1. hey, thanks for the write up. I think you forgot "source bin/activate" step

    ReplyDelete
    Replies
    1. Hi, and thank you for your commitment. It's added but I wonder if I really used it ? Will check.

      Delete

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !