Home Assistant on Raspbian Lite with Mosquitto (and NMap)
Download the Raspbian Light image and write it onto an SD
Add an empty ssh
file to the boot
partition
SSH into the Pi
Update the system:
sudo apt-get update
sudo apt-get upgrade
Install the dependencies: sudo apt-get install python3 python3-venv python3-pip
Add an account for Home Assistant: sudo useradd -rm homeassistant
Create a directory for the installation of Home Assistant and change the owner to the homeassistant
account:
cd /srv
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant
create and change to a virtual environment for Home Assistant:
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
python3 -m venv homeassistant_venv
source /srv/homeassistant/homeassistant_venv/bin/activate
Install Python Wheels: python3 -m pip install wheel
Install Home Assistant: pip3 install homeassistant
Optionally do a test drive: hass
exit
Optionally: Connect to remote MySQL/MariaDB server
Edit the config file: nano /home/homeassistant/.homeassistant/configuration.yaml
Before History:
add
recorder:
db_url: mysql://user:password@SERVER_IP/DB_NAME?charset=utf8
If the no module named mysqldb
error pops up during restart, install the mysqlclient
module inside the virtual env: pip3 install mysqlclient
Optionally: Install Mosquitto (MQTT server)
Install Mosquitto: sudo apt-get install mosquitto
Create a password file: sudo mosquitto_passwd -c /etc/mosquitto/pwfile owntracks
(change owntracks
to any username you want)
Add the password file to the configuration: sudo nano /etc/mosquitto/mosquitto.conf
, add:
connection_messages true
allow_anonymous false
password_file /etc/mosquitto/pwfile
Empty the cache: /sbin/ldconfig
Install nmap: sudo apt-get install net-tools nmap
Create a new service file: sudo nano /etc/systemd/system/home-assistant@pi.service
, add:
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=homeassistant
#make sure the virtualenv python binary is used
Environment=VIRTUAL_ENV="/srv/homeassistant/homeassistant_venv"
Environment=PATH="$VIRTUAL_ENV/bin:$PATH"
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"
[Install]
WantedBy=multi-user.target
Make the daemon aware of the new configuration: sudo systemctl --system daemon-reload
Enable the service: sudo systemctl enable home-assistant@pi
Start Home Assistant: sudo systemctl start home-assistant@pi
(will start automaticly on boot)