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: https://home-assistant.io/getting-started/installa...
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: https://home-assistant.io/getting-started/autostar...
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:
[Unit]
Description=Home Assistant After=network.target
[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"
[Install] WantedBy=multi-user.target
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
#introduction:
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)
switch:
- platform: rpi_gpio
ports:
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
Or
$ 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
https://home-assistant.io/getting-started/installa...
Autostarting with systemd https://home-assistant.io/getting-started/autosta...
GPIO Switch https://home-assistant.io/components/switch.rpi_g...
Please support my channel:
ICStation Affilate Link
http://www.shareasale.com/r.cfm?b=498665&u=1013844&m=48335&urllink=&afftrack=
Support the channel tip with bitcoins Address: 1MvcZHRbDm9czS8s776iutBBPJ39K4PEHh
Follow me on youtube: http://www.youtube.com/misperry
Follow me on Twitter http://www.twitter.com/misperryee
T-Shirts http://www.zazzle.com/misperry