Setting up Home Assistant on a Raspberry Pi

Home Assistant is open-source software for smart-home design and control. This article is the first part of a multi-article series that will cover my Home Assistant set-up. As my platform to run the software, I will be using an inexpensive Raspberry Pi. I use Home Assistant to control smart plugs, lights, temperature, and a vacuum robot. My general rule is to buy the cheapest smart-home gear I can get my hand on and integrate it into the Home Assistant. Because of its popularity and its community’s effort, it can interact with almost all smart devices from different vendors. It is even possible to create automations between otherwise incompatible systems. I see this series as my contribution to the ecosystem by providing a set of comprehensive guides. A user following these guides will end up with a well-working smart-home system.

This post deals with the preparation of the system. We are going to install the Home Assistant Core on a Raspberry Pi. We do not use an image for the Raspberry Pi that already contains the Home Assistant, as I also use my Raspberry Pi for other tasks such as a print server. I recommend using a Raspberry Pi from generation 3 or later, as those have enough computational power. For completing this tutorial, you need to have a Raspberry Pi with a MicroSD-Card, a way to power it, and an ethernet cable to connect it to the router.

Preparing the Raspberry Pi

You can skip this step if you already have a Raspberry Pi with an installed Raspberry Pi OS and SSH access.

  1. Download the latest Raspberry Pi Imager and run it.
  2. Insert the MicroSD-Card into your computer.
  3. For Operating System, choose Other -> Raspberry Pi OS Lite (64-bit). For your SD-Card, choose the MicroSD-Card. Then click on Write. Wait for the computer to finish writing.
  4. Remove the SD-Card from the computer and reinsert it. There will be a partition called boot in the file manager. Open it and create a file named ssh on this partition.
  5. Remove the SD-Card from the computer and insert it into the Raspberry Pi. Connect the Raspberry Pi to the router with the ethernet cable. Connect the Raspberry Pi to the power source to turn it on.
  6. Log into your router and wait until the Raspberry Pi shows up on the connected device list. Write down its IP-Address. It should be of the form XXX.XXX.XXX.XXX.
  7. You need an SSH-Client for the next steps.
    1. For Windows, I recommend PuTTY. Insert the IP-Address, the username pi, and the password raspberry and connect. A terminal should open.
    2. For Linux users, open a terminal. Type ssh pi@XXX.XXX.XXX.XXX were XXX.XXX.XXX.XXX is the IP-Address. Insert the password raspberry once asked.
  8. Type sudo raspi-config.
  9. Select System Options. You can configure Wifi here. I don’t do this as I use my Pi wired.
  10. Change the Password of the pi user by choosing the third option.
  11. Select Localization Options. Select the correct locale, timezone, keyboard layout, and wifi country.
  12. Select Advanced Options -> Expand Filesystem.
  13. Close the raspi-config tool with Finish. Confirm to reboot.
  14. After one minute, log into the Raspberry Pi again (step 7). Use the new password you defined.
  15. Type sudo apt-get update && sudo apt-get dist-upgrade to update your software to the latest revision. Confirm by typing a y if you are asked for confirmation.

Installing Home Assistant Core

All steps are conducted in the SSH-terminal, see step 7 of the previous section.

  1. Install the dependencies of Home Assistant with sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0 tzdata
  2. Create a user that will run the Home Assistant with sudo useradd -rm homeassistant -G dialout,gpio,i2c
  3. Execute sudo mkdir /srv/homeassistant, then sudo chown homeassistant:homeassistant /srv/homeassistant.
  4. Execute the commands in order: sudo -u homeassistant -H -s, cd /srv/homeassistant, python3 -m venv ., source bin/activate.
  5. Install Home Assistant with pip install wheel homeassistant.
  6. Start Home Assistant the first time by executing hass. Wait 10 minutes (or longer). Confirm that you can reach your Home Assistant by typing http://XXX.XXX.XXX.XXX:8123 in a browser. XXX.XXX.XXX.XXX is the IP-Address of your Raspberry Pi.
  7. Create an account. If you plan to expose your Home Assistant to the cloud (Stay tuned for a later tutorial), don’t choose easy-to-guess credentials.
  8. Select your location and whether you prefer metric or imperial units.
  9. Finish the rest of the wizard. You should see an empty Home Assistant Dashboard.
  10. Kill the Home Assistant by pressing Ctrl+C in the terminal.
  11. Press Ctrl+D to switch back to the pi user.
  12. Execute sudo nano /etc/systemd/system/home-assistant@homeassistant.service.
  13. A file editor opens in the terminal. Paste the following code
[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
  1. Close the editor by pressing Ctrl+X and confirming with y.
  2. Execute sudo systemctl --system daemon-reload and sudo systemctl enable home-assistant@homeassistant.
  3. Reboot the Pi with sudo reboot. Your Home Assistant should now automatically launch with the system. Try to access it via your browser!

Updating Home Assistant

Your Home Assistant tells you when it is outdated with a binary sensor. Log into your terminal (step 7, first section) and execute the following commands.

  1. sudo -u homeassistant -H -s
  2. cd /srv/homeassistant
  3. source bin/activate
  4. pip install -U homeassistant
  5. sudo reboot

After this, your Raspberry Pi should reboot with the new version of Home Assistant.

Populating Home Assistant with Devices

The Home Assistant will automatically discover some devices on your network. Others will require some manual work. I will cover adding various devices I own to Home Assistant in future posts.

79 thoughts on “Setting up Home Assistant on a Raspberry Pi”

  1. Pingback: cialis dose
  2. Pingback: flagyl simili
  3. Pingback: zoloft for anxiety
  4. Pingback: flagyl 100ml
  5. Pingback: flexeril addictive
  6. Pingback: celecoxib wiki
  7. Pingback: buspar depression
  8. Pingback: repaglinide online
  9. Pingback: voltaren lactose
  10. Pingback: sildenafil walmart

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha loading...