Home Assistant Installation - bapowell/bapowell.github.io GitHub Wiki

References

https://www.home-assistant.io/

Prerequisites (Debian-Stretch | Debian-Buster | Raspbian-Buster)

MQTT server (mosquitto)

See: Mosquitto Installation (section: Debian buster)

Other packages

  • Note: python3 may already be installed, however a newer version may need to be installed (see Upgrade section below).

$ sudo apt-get install python3 python3-dev python3-pip python3-venv libffi-dev libssl-dev libjpeg-dev libopenjp2-7 libtiff5 zlib1g-dev autoconf build-essential

Installation

Method: "Alternative/manual install using venv (as another user)"

Initial Install

  • Add a "homeassistant" user account (used only for running Home Assistant):

    • $ sudo useradd -rm homeassistant -G dialout,gpio,i2c
    • Notes:
      • -r : create a system account
      • -m : create home directory for the account
      • dialout : required for certain controllers, e.g. Z-Wave, Zigbee
      • gpio : not required if not installing on a Raspberry Pi (used for accessing the Pi's GPIO pins)
      • i2c : not required if not installing on a Raspberry Pi
  • Create install folder, assigning ownership to the homeassistant account:

    • $ cd /srv
    • $ sudo mkdir homeassistant
    • $ sudo chown homeassistant:homeassistant homeassistant
  • Switch to the homeassistant user:

    • $ sudo -u homeassistant -H -s
    • Notes:
      • -H : set HOME env variable
      • -s : run the shell specified by the SHELL env variable or...
  • Create a python virtual env for Home Assistant, and activate (change into) it:

    • $ cd /srv/homeassistant
    • $ python3 -m venv .
    • $ source bin/activate
      • Note: To deactivate it later, type deactivate<enter> at the command prompt.
  • Ensure using latest version of pip:

    • (homeassistant) $ python3 -m pip install pip --upgrade
  • Install other prerequisite packages:

    • (homeassistant) $ python3 -m pip install wheel
  • (optional) Update outdated packages:

    • (homeassistant) $ python3 -m pip list --outdated
    • examples:
      • (homeassistant) $ python3 -m pip install --upgrade pip setuptools
  • Install Home Assistant

    • (homeassistant) $ python3 -m pip install homeassistant
    • Install a specific version:
      • (homeassistant) $ python3 -m pip install homeassistant==0.113.1

Updating

  • See: https://www.home-assistant.io/common-tasks/core/
  • Stop existing instance, if currently running.
  • $ sudo -u homeassistant -H -s
  • $ source /srv/homeassistant/bin/activate
  • Ensure pip and related core packages are up to date:
    • (homeassistant) $ python3 -m pip install --upgrade pip setuptools wheel
  • Update homeassistant:
    • (homeassistant) $ python3 -m pip install --upgrade homeassistant
    • might also try: (homeassistant) $ python3 -m pip install --upgrade --upgrade-strategy only-if-needed homeassistant
  • Frontend:
    • Manually updating the frontend, as shown below, typically isn't necessary; hass itself, upon startup, will attempt to pip install the latest appropriate home-assistant-frontend package. You can see this in the hass log.
    • (homeassistant) $ python3 -m pip install --upgrade home-assistant-frontend
      • might also try: (homeassistant) $ python3 -m pip install --upgrade --upgrade-strategy only-if-needed home-assistant-frontend
      • install a specific version: (homeassistant) $ python3 -m pip install home-assistant-frontend==20190626.0

Starting

  • $ sudo -u homeassistant -H -s
  • $ source /srv/homeassistant/bin/activate
  • (homeassistant) $ hass
    • Note: When run the first time after installation it will complete the installation, automatically creating the .homeassistant configuration directory in the /home/homeassistant directory.
  • Open browser tab and go to http://ipaddress:8123.

Autostart / Service (using systemd, e.g. on Ubuntu)

[Unit]
Description=Home Assistant
# Uncomment the following to wait for network to be up before starting:
After=network-online.target
# If running Mosquitto service on same server, then start after mosquitto:
#After=network.target mosquitto.service 
# If running MySensors Gateway service on same server, then start after it:
#After=network.target mysgw.service

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"
# If want to restart the service automatically after a crash, uncomment the following two lines:
#Restart=on-failure
#RestartSec=5s

[Install]
WantedBy=multi-user.target

Upgrade

Maybe need to update to a newer version of python

Example repeated here:

  • Installation (note that this takes quite some time, especially on a Raspberry Pi):

    • $ sudo apt install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
    • $ cd /tmp
    • $ mkdir python39
    • $ cd python39
    • $ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
    • $ tar xvf Python-3.9.1.tgz
    • $ cd Python-3.9.1/
    • $ ./configure --enable-optimizations --with-ensurepip=install
    • $ make -j 4
    • $ sudo make altinstall # note: on Raspbian-buster this installed the python3.9 binary to /usr/local/bin
  • Run it:

    • $ python3.9
  • Create a virtual env:

    • $ python3.9 -m venv venvtest
    • $ source venvtest/bin/activate

Issues

"Unable to install package pillow==7.2.0"

  • Log showed that error message after upgrading to Python 3.9.x and HA v2020.12.2.
  • After googling, did the following:
    • $ sudo apt install libjpeg-dev zlib1g-dev
      • Shouldn't have been necessary, since already done at initial install, but it did seem to pull in more packages.
    • $ (homeassistant) python -m pip install pillow==7.2.0
      • Make sure you're in the HA venv.
⚠️ **GitHub.com Fallback** ⚠️