Setting up Home Assistant on a Raspberry Pi, from scratch
Written 2020-09-06 by Kalle
5 min read | 995 words
Hardware used
- MacBook Pro running macOS Catalina, for flashing SD-card, configuration, etc.
- Raspberry Pi 3 Model B+.
- Apple 12W USB Power Adapter.
- Samsung Pro Endurance 32 GB microSDHC UHS-I Card.
- Old USB drive for wifi configuration during setup.
Flash the SD card
- Download a Hassios image relevant for your platform from the Home Assistant website.
- Open Balena Etcher.
- Flash the downloaded image to the SD card using Balena Etcher.
- Eject the SD card and insert it to the Raspberry Pi.
Configure the WiFi Settings
- Insert a USB drive.
-
Detect the mounting point of the USB drive by running
diskutil list
in a Terminal window. Manually look for the entry corresponding to the USB drive. The easiest identification method is to compare the capacity of each entry with the known capacity of the USB drive. The identified entry will look something like this:/dev/disk3 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *2.0 GB disk3 1: Microsoft Basic Data USB 2.0 GB disk3s1
Write down the path of the USB drive, i.e.
/dev/disk3
in the example above. -
Re-format the USB drive as FAT32 and name it
CONFIG
by running the following command in a Terminal window, where the last parameter is the path written down in the previous step.sudo diskutil eraseDisk FAT32 CONFIG /dev/disk3
- Create the directory
CONFIG/network
. -
Create a text file with the following content, replacing the marked lines with relevant content. Save it as
CONFIG/network/my-network
. For the UUID4, use an online generator such as uuidgenerator.net.[connection] id=my-network uuid=<UUID4 ID> <-- REPLACE type=802-11-wireless [802-11-wireless] mode=infrastructure ssid=<MY SSID> <-- REPLACE # Uncomment below if your SSID is not broadcasted #hidden=true [802-11-wireless-security] auth-alg=open key-mgmt=wpa-psk psk=<MY PASSWORD> <-- REPLACE [ipv4] method=auto [ipv6] addr-gen-mode=stable-privacy method=auto
- Eject the USB drive and insert it to the Raspberry Pi.
First boot!
- [OPTIONAL] connect the Raspberry Pi to a monitor via HDMI. This allows you to monitor the printout of the Raspberry during the initial boot to detect any errors.
- Power on the Raspberry Pi.
-
Wait for a few minutes, depending on the speed of your internet connection. In my case, 9 minutes and 30 seconds. On the monitor connected to the Raspberry, the final two lines were:
udevd[186]: starting version 3.2.9 udevd[187]: starting eudev-3.2.9
Configuration through Web Interface
Enable Advanced mode
- Open a web browser.
- Navigate to
http://homeassistant.local:8123
. - Go through the setup guide.
- In the left side menu in Home Assistant, click on your user name, then scroll down and toggle "Advanced mode" to ON.
Install the File editor
- Navigate to
Supervisor -> Add-on Store
. - Search for "File editor" and install it by clicking on the card, then clicking on INSTALL. When the button START appears, click it to start the add-on.
- In the same manner, install the following Add-ons:
Setup remote access
Create a Duck DNS account
- Navigate to the external site Duck DNS.
- Sign in using one of the supported methods.
- Add a custom domain such as:
my-domain
. - Copy the token. It should be something like
ryr*****-****-****-****-**********67
.
Install and Configure the Add-on
- Install the add-on Duck DNS.
- Click on the tab Configuration.
- Modify the configuration with your domain and token.
-
Change
accept_terms
fromfalse
totrue
. This way, you accept the Let's Encrypt Subscriber Agreement.lets_encrypt: accept_terms: true certfile: fullchain.pem keyfile: privkey.pem token: ryr*****-****-****-****-**********67 domains: - my-domain.duckdns.org aliases: [] seconds: 300
- Navigate to the tab Info.
- Click START and wait while it starts.
- Navigate to the tab Log.
- Verify that no errors are reported.
Set up Port Forwarding
- Identify the IP of the Raspberry Pi running Home Assistant, e.g. by using the free app Fing.
- In your router, forward port
8123
to port8123
for the IP of the Raspberry Pi running Home Assistant.
Configure https access in configuration.yaml
- In the left side menu in Home Assistant, click on File editor, click the icon looking like a folder, then open
configuration.yaml
. - Erase any entries starting with
http:
. -
Add the following entry to the bottom:
http: ssl_certificate: /ssl/fullchain.pem ssl_key: /ssl/privkey.pem
Restart Home Assistant
- Navigate to
Configuration -> Server Management
. Click RESTART and confirm in the pop-op which appears.
Re-open using SSL
- Notice that you can no longer access Home Assistant via
http://homeassistant.local:8123
. - Verify that you can access Home Assistant via
https://homeassistant.local:8123
. - Verify that you also can access Home Assistant via
https://my-domain.duckdns.org:8123
.
Setup deCONZ
Install
- Install the plugin deCONZ from the Add-on store
- Navigate to
Supervisor -> System -> Host system -> Hardware
. - Locate the path of the deCONZ stick by comparing the values before and after inserting the deCONZ stick. It should be something like:
/dev/ttyUSB0
. Copy the path. -
Modify the configuration for the plugin such that it has the following format:
device: /dev/ttyUSB0
- Start the Add-on.
Change the duration of open
- Click on OPEN UI.
- Choose "Phoscon".
- Set a new password.
- In Phoscon, navigate to
Settings -> Gateway -> Advanced -> Search for new lights duration
and set the value to60
.
Add IKEA Trådfri Switch
- Unscrew the backside of the switch.
- In Phoscon, navigate to
Devices -> Switches.
- Click the button "Add new switch" and select "Other" in the pop-up.
- On the back of the switch, press the Reset button five times in quick succession. A faint red light to the left of the "O" (with the switch oriented with the "O" down and the "I" up) starts blinking slowly.
- Place the switch next to the ConBee stick.
- Wait until the text "Compound was prepared" is shown.
- Click "Ready".
- Re-assemble the switch.