Setup Home Assistant on Raspberry Pi

Introduction: Setup Home Assistant on Raspberry Pi

In this instructable we will be looking at how to configure the home assistant software for the raspberry pi.

Step 1: Setup of Equip

First you will need a raspberry pi with the latest image on it.

Currently I am using the Rasbian image version Jessie (pixel).

I suggest using a fairly fast microSD card so that it is nice and responsive. UHS-I or UHS-II

Step 2: Install the Software.

Now you will need to install the software. This information is taken from the site:

connect to your pie and enter the following to get the latest rasbian image:

$ sudo apt-get update

$ sudo apt-get upgrade -y

Install the dependencies that are needed for homeassistant:

$ sudo apt-get install python3 python3-venv python3-pip

Once done you will need to create the home assistant account and the virtual environment:

$ cd /srv

$ sudo mkdir homeassistant

$ sudo chown homeassistant:homeassistant homeassistant

$ sudo su -s /bin/bash homeassistant

$ cd /srv/homeassistant

$ python3 -m venv homeassistant_venv

$ source /srv/homeassistant/homeassistant_venv/bin/activate

$ exit

Step 3: Configure Your .bashrc for the Virtual Environment

For ease of switching to the virtual environment, which is where you will run testing for configuring the home assistant, I put the source command in my .bashrc of my homeassistant user to make it easier.

$ vi /home/homeassistant/.bashrc

copy and paste the following at the bottom of the file

source /srv/homeassistant/homeassistant_venv/bin/activate

Now save the file and to test it type the following:

$ exit

$ sudo su -s /bin/bash homeassistant

You should see the following:

(homeassistant_venv) homeassistant@raspberrypi:/home/pi $

Step 4: Install the Home Assistant Program

Now that you are in the home assistant virtual environment you will now install the program with the following commands:

(homeassistant_venv) homeassistant@raspberrypi:/home/pi $ cd /srv/homeassistant

(homeassistant_venv) homeassistant@raspberrypi:/srv/homeassistant/ $ pip3 install homeassistant

This will install the program. Be patient for it will take a while depending on the version of raspberry pi you have and what the speed of the microSD card you used.

Once finished you can manually run the program from the virtual environment by typing the following command:

(homeassistant_venv) homeassistant@raspberrypi:/home/pi $ hass

However, next step we will look at making it start when the pi starts up.

Step 5: Setup Home Assistant to Auto Start

Now we will need to setup the home assistant program to auto start on boot through the systemctl. This information taken from the following address:

Begin with creating the service file for this as starting as the pi user:

$ sudo su root

$ cd /etc/systemd/system/

$ vi home-assistant@pi.service

Now cut and paste the following:

Description=Home Assistant

[Service] Type=simple User=homeassistant #make sure the virtualenv python binary is used Environment=VIRTUAL_ENV="/srv/homeassistant/homeassistant_venv" Environment=PATH="$VIRTUAL_ENV/bin:$PATH"

ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"


Save this and exit out of editing the file and exit root to return to the pi user.

Now you will need to restart the systemctl and read the file with the following commands

$ sudo systemctl --system daemon-reload
$ sudo systemctl enable home-assistant@pi

$ sudo systemctl start home-assistant@pi

Now you should be able to start the service with the following command:

$ sudo systemctl start home-assistant@pi

You can view the log to see if it is starting properly with the command:

$ sudo systemctl status home-assistant@pi -l

Or if you would like to view a scrolling log you can issue the following command:

$ sudo journalctl -f -u home-assistant@pi

Step 6: Configuration File Setup GPIO

Now we have gotten it started we need to configure it for the gpio.

as the user pi you need to open the configuration file as follows:

$ cd /home/homeassistant/.homeassistant

$ vi configuration.yaml

Once in the configuration file you will disable the introduction component by commenting out the "introduction" line:

# Show links to resources in log and frontend

Now you will add the following to the file to activate the GPIO for the raspberry pi. (in this example I am using GPIO 11 and 12 for this)


- platform: rpi_gpio


11: TestLED1

12: TestLED2

Save this to the configuration file.

Step 7: Testing Your Changes and Restart Home Assistant

Now you will need to test your changes.

To test for errors in your configuration you will need to run the check_config command as follows:

from pi user:

$ sudo su -s /bin/bash homeassistant

(homeassistant_venv) homeassistant@raspberrypi:/home/pi $ hass --script check_config

If all goes well you should get no errors.

To restart with systemctl you type the following command as the pi user:

$ sudo systemctl stop home-assistant@pi

$ sudo systemctl start home-assistant@pi

Remember you can watch the start up with the following two commands:

$ sudo systemctl status home-assistant@pi -l


$ sudo journalctl -f -u home_assistant@pi

Once restarted you can go back to your home assistant web page http://<ip address>:8123

Now notice you two LED's are now accessible

Step 8: Final Thoughts

You should now have your home assistant setup to utilize your GPIO on your raspberry pi.

I have included a video describing all the steps you need to take to set it all up.

Enjoy and here are some helpful links!!

Manual Installation

Autostarting with systemd

GPIO Switch

Please support my channel:

ICStation Affilate Link

Support the channel tip with bitcoins Address: 1MvcZHRbDm9czS8s776iutBBPJ39K4PEHh

Follow me on youtube:

Follow me on Twitter


Be the First to Share


    • Make It Bridge

      Make It Bridge
    • For the Home Contest

      For the Home Contest
    • Big and Small Contest

      Big and Small Contest



    1 year ago

    On installation I got to the line (homeassistant_venv) homeassistant@raspberrypi:/home/pi $ cd /srv/homeassistant but it kept telling me 'syntax error near unexpected token homeassistant@raspberrypi :/home/pi ' .Please help if you can.


    2 years ago

    I was able to reproduce this steps, however once the homeassistant is started by systemd... or even after a reboot, it shows active (running) but never open the 8123 port on the host... the ERROR (MainThread) [homeassistant.components.updater] Error requesting Home Assistant update data: Cannot connect to host happen at least once, maybe cause startup script was up prior to the network... not sure... but now nothing happens...


    Question 2 years ago

    I got an error:
    "homeassistant requires Python '>=3.7.0' but the running Python is 3.6.0"
    I am running Python 3.7, but in the virtual environment when I type python --version, it say 3.6. Any idea how to correct it?
    I tried to edit pyvenv, using sudo nano. It asked for the homeassistant password. What is the homeassistant password?


    3 years ago

    chown: invalid user: ‘homeassistant:homeassistant’ on step 3 i got this error


    Reply 3 years ago

    sudo useradd -rm homeassistant -G dialout
    then inputting step 3 again worked for me for whatever reason.


    Reply 3 years ago

    We’ll not step 3, but with $ sudo chown homeassistant:homeassistant homeassistant


    Question 3 years ago

    Everything went smoothly until step 3. When I cut & paste vi /home/homeassistant/.bashrc into the command line, I think it's showing .bashrc but I can't figure out how to paste the line you've specified into it, and can't figure out how to open it with sudo nano either.


    5 years ago

    This is such a clear set of instructions I followed it, but I think it's a flawed approach. My install ended up fubar, I believe because of permission issues around running this service as user pi instead of the system user homeassistant. The link you provide to the manual install is more conventional and in my experience more stable -- I'd recommend users use that, skip steps 1-5, and start at step 6!