HomeAssistant on Raspberry Pi


This are my notes to install home-assistant on a raspberry-pi 3. At the end, this is a multipart how-to for installing home-assistant and mosquitto (MQTT) with a NodeMCU and some magnetic contacts.

Copy Raspbian Lite to an SD Card on Mac OSX (use rdisk is faster):

sudo dd if=Downloads/2017-11-29-raspbian-stretch-lite.img of=/dev/rdisk4 bs=4m conv=sync

Enable SSH (create a file named ssh on the SD-Card):
touch /Volumes/boot/ssh

Put the SD-Card into your raspberry and boot it up.

Login and change password of user pi and root:
sudo passwd root

Configure WLAN:
wpa_passphrase “YourWLANSSID” “yourWLANPassword”
Configure WLAN in /etc/wpa_supplicant/wpa_supplicant.conf:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

#psk=”yourWLANPassword” <<<<<—– REMOVE THIS COMMENTED LINE!

You have a fixed IP? (preferred!)
Edit /etc/dhcpcd.conf and set the hostname inside this file.
Add config for your interface:
interface wlan0
static ip_address=192.168.0.XXX/24
static routers=192.168.0.XXX
static domain_name_servers=XXX.XXX.XXX.XXX, XXX.XXX.XXX.XXX
static domain_search=some.domain.com
static domain_name=some.domain.com

Use raspi-config to configure your raspberry hostname and partition then reboot.

sudo apt-get update
sudo apt-get upgrade

HomeAssistant Setup:
Follow the steps on https://home-assistant.io/docs/installation/raspberry-pi/

HomeAssistant as a Service:
Create File:

With content:

 Description=Home Assistant

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


Reload systemd: sudo systemctl --system daemon-reload
 Enable for autostart:
 sudo systemctl enable home-assistant@homeassistant


Create a SSL Certificate (as user pi):
mkdir certbot
cd certbot/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto certonly –standalone –preferred-challenges http-01 –email your@email.address -d your.domain.com

sudo chmod 755 /etc/letsencrypt/live/
sudo chmod 755 /etc/letsencrypt/archive/

Install Mosquitto for MQTT:

Run own MQTT Broker Mosquitto:
Install Repo:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
Install mosquitto:
sudo apt-get install mosquitto

Copy example from here /usr/share/doc/mosquitto/examples/mosquitto.conf.example

to here: /etc/mosquitto/

Change to your needs.
Generate /etc/mosquitto/pwfile:
mosquitto_passwd -c /etc/mosquitto/pwfile
mosquitto_passwd -b /etc/mosquitto/pwfile username password

Start mosquitto
sudo service mosquitto start

Leave a Reply