A simple method to set up Home Assistant in a Raspberry Pi is by using Hassbian which is a Raspberry Pi image that has Home Assistant already built-in. The image can be installed and ran not just from a Micro SD card but also from a USB drive. So if you had previously enabled the Raspberry Pi to boot from a USB connection, you could install Hassbian on a flash drive and boot it from there.
How to set up Hassbian
OK, so the first thing that you need to do is download the latest version of Hassbian. Then use Etcher to flash the image to a Micro SD card. Insert the SD card into the computer, open Etcher, click on Select Image, search and select the Hassbian image. Then, click on Select Drive and choose the Micro SD card. Lastly, click on Flash and give it a few minutes to copy everything.
Once the process finishes, remove the SD card from the computer and put it into the Raspberry Pi. Also, connect an Ethernet cable from the Raspberry Pi to the router so once the Pi boots for the first time, it can download and install the latest version of Home Assistant. This process can take a few minutes, but when finished, you can open the browser and navigate to http://hassbian.local:8123.
Now if the page is not reachable using this link, then you will need to verify what IP address the Raspberry Pi is getting from the router so you can access the web interface using the IP. To do this, you can use a network application called Fing which will display all the connected devices to the home network. After you verify what IP address the Raspberry Pi is getting, type it in your browser and at the end type: 8123 which is the port for Home Assistant. Press Enter and you should now be able to reach the web interface.
SSH to the Raspberry Pi and change default Password
The next step that you want to do is SSH to the Raspberry Pi using PuTTy so you can change the default password for the Pi, the timezone and also set up Samba. Samba is going to allow you to access the Home Assistant configuration files from another computer.
Ok, so let’s open PuTTy and under Host Name type the Raspberry Pi’s IP address. Then press Enter or click Open. Sign in to the Pi using the default username which is pi and the password which is raspberry.
Now to change the Raspberry Pi’s default password, type the command, sudo raspi-config
. Then click on Change User Password and enter a new password. After that, go into Localisation Options and select Change Timezone so you can set up your location. Last, click Finish and reboot the Raspberry Pi. After a minute, restart the SSH session and sign back using the new password.
Set up WiFi connectivity
To set up the WiFi connection, run the command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Then, paste the following information and replace Your_WiFi_name with your network name and Your_WiFi_password with your wireless password.
network={ ssid="Your_WiFi_name" psk="Your_WiFi_password" }
When done, press Ctrl+X to exit the configuration, then Y and Enter to save the changes. Then, restart the Raspberry Pi with the command, sudo reboot
. Unplug the Ethernet cable from the Pi, and it should now connect via WiFi. Give it a minute and then restart the session. If the session does not reconnect, use Fing to check if the Raspberry Pi is getting a different IP address. If the IP address changed, close the session and start a new one using the new IP.
Set up Samba
Before you install and configure Samba, update all the packages in the Raspberry Pi using the command sudo apt-get update && sudo apt-get upgrade -y
Then, to install Samba, run the command sudo apt-get install samba samba-common-bin
Now, access the Samba configuration file using the command sudo nano /etc/samba/smb.conf
The Samba configuration file it is well documented, but instead of going over each option, remove everything by pressing and holding Ctrl+K. Then paste the following information:
[global] netbios name = hassbian server string = The Pi File Center workgroup = WORKGROUP hosts allow = remote announce = remote browse sync = [HOME ASSISTANT] path = /home/homeassistant/.homeassistant comment = No comment browsable = yes read only = no valid users = writable = yes guest ok = no public = yes create mask = 0777 directory mask = 0777 force user = root force create mode = 0777 force directory mode = 0777 hosts allow =
To explain this a little bit, we are specifying the NetBIOS Name which is hassbian, the Workgroup which by default is set up to WORKGROUP but if you changed it in your computer, you want to enter the same Work Group here. We are also specifying the path for the Home Assistant configuration files, and the rest is just stating that a user can read, write and execute from this folder. Ok now to exit and save the changes, press Ctrl+X then Y and Enter.
To protect access to the Samba shared folder, you want to set up a password, so run the following command, sudo smbpasswd -a pi
and enter a new password. Now, restart Samba to apply the changes, so run the command, sudo service smbd restart
. Then open your File Explorer, go to Network and now the Hassbian shared folder should come up as a new device.
If for some reason the shared folder does not come up, then you can manually remap the folder by right-clicking on Network and select Map Network Drive. Choose whatever drive letter you would like for the shared folder, then under the Folder field type, \\Hassbian\home assistant and then click Finish. Now, the Home Assistant shared folder will be available as a new network drive.
Set up a password for the Home Assistant web interface
All right, last but not least, you want to set up a password for the Home assistant web interface, so open the Home Assistant shared folder and open the configuration.yaml file using an application like Atom or Notepad++.
The configuration.yaml file might look a little bit intimidating, but it is quite simple. I will be showing you guys how to understand the configuration.yaml file on a future tutorial but for now, the only thing that we are going to edit here is the password.
Under HTTP, you have the line #api_password: Password. The Hash “#” at the beginning means that the line is a comment, so it is not an active command so remove the Hash “#” to activate the command and then type whatever password you would like. Now save the file, and restart Home Assistant to apply the changes. Open the Home Assistant web interface and go to Services, select homeassistant.restart and then click on Call Service. Give it a minute and then refresh the page and you should now be prompted to enter the password.