Karl SvenssonBlogLinkedIn

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

  1. Download a Hassios image relevant for your platform from the Home Assistant website.
  2. Open Balena Etcher.
  3. Flash the downloaded image to the SD card using Balena Etcher.
  4. Eject the SD card and insert it to the Raspberry Pi.

Configure the WiFi Settings

  1. Insert a USB drive.
  2. 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.

  3. 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
  4. Create the directory CONFIG/network.
  5. 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
  6. Eject the USB drive and insert it to the Raspberry Pi.

First boot!

  1. [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.
  2. Power on the Raspberry Pi.
  3. 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

  1. Open a web browser.
  2. Navigate to http://homeassistant.local:8123.
  3. Go through the setup guide.
  4. 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

  1. Navigate to Supervisor -> Add-on Store.
  2. 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.
  3. In the same manner, install the following Add-ons:

Setup remote access

Create a Duck DNS account

  1. Navigate to the external site Duck DNS.
  2. Sign in using one of the supported methods.
  3. Add a custom domain such as: my-domain.
  4. Copy the token. It should be something like ryr*****-****-****-****-**********67.

Install and Configure the Add-on

  1. Install the add-on Duck DNS.
  2. Click on the tab Configuration.
  3. Modify the configuration with your domain and token.
  4. Change accept_terms from false to true. 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
  5. Navigate to the tab Info.
  6. Click START and wait while it starts.
  7. Navigate to the tab Log.
  8. Verify that no errors are reported.

Set up Port Forwarding

  1. Identify the IP of the Raspberry Pi running Home Assistant, e.g. by using the free app Fing.
  2. In your router, forward port 8123 to port 8123 for the IP of the Raspberry Pi running Home Assistant.

Configure https access in configuration.yaml

  1. In the left side menu in Home Assistant, click on File editor, click the icon looking like a folder, then open configuration.yaml.
  2. Erase any entries starting with http:.
  3. Add the following entry to the bottom:

    http:
      ssl_certificate: /ssl/fullchain.pem
      ssl_key: /ssl/privkey.pem

Restart Home Assistant

  1. Navigate to Configuration -> Server Management. Click RESTART and confirm in the pop-op which appears.

Re-open using SSL

  1. Notice that you can no longer access Home Assistant via http://homeassistant.local:8123.
  2. Verify that you can access Home Assistant via https://homeassistant.local:8123.
  3. Verify that you also can access Home Assistant via https://my-domain.duckdns.org:8123.

Setup deCONZ

Install

  1. Install the plugin deCONZ from the Add-on store
  2. Navigate to Supervisor -> System -> Host system -> Hardware.
  3. 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.
  4. Modify the configuration for the plugin such that it has the following format:

    device: /dev/ttyUSB0
  5. Start the Add-on.

Change the duration of open

  1. Click on OPEN UI.
  2. Choose "Phoscon".
  3. Set a new password.
  4. In Phoscon, navigate to Settings -> Gateway -> Advanced -> Search for new lights duration and set the value to 60.

Add IKEA Trådfri Switch

  1. Unscrew the backside of the switch.
  2. In Phoscon, navigate to Devices -> Switches.
  3. Click the button "Add new switch" and select "Other" in the pop-up.
  4. 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.
  5. Place the switch next to the ConBee stick.
  6. Wait until the text "Compound was prepared" is shown.
  7. Click "Ready".
  8. Re-assemble the switch.

© 2024