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:
passwd
sudo passwd root
Configure WLAN:
wpa_passphrase “YourWLANSSID” “yourWLANPassword”
Configure WLAN in /etc/wpa_supplicant/wpa_supplicant.conf:
country=CH
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=”YourWLANSSID”
#psk=”yourWLANPassword” <<<<<—– REMOVE THIS COMMENTED LINE!
psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
}
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.
Update:
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:
/etc/systemd/system/home-assistant@homeassistant.service
With content:
[Unit] Description=Home Assistant After=network-online.target [Service] Type=simple User=%i ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant" [Install] WantedBy=multi-user.target 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
Configure:
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