Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BillyNate/9d8d2e2943bcca434e3bfd77d38b244f to your computer and use it in GitHub Desktop.
Save BillyNate/9d8d2e2943bcca434e3bfd77d38b244f to your computer and use it in GitHub Desktop.

Home Assistant on Raspbian Lite with Mosquitto (and NMap)

Setup

  1. Download the Raspbian Light image and write it onto an SD
  2. Add an empty ssh file to the boot partition
  3. SSH into the Pi
  4. Update the system:
  5. sudo apt-get update
  6. sudo apt-get upgrade

Install Home Assistant

  1. Install the dependencies: sudo apt-get install python3 python3-venv python3-pip
  2. Add an account for Home Assistant: sudo useradd -rm homeassistant
  3. 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
  1. 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
  1. Install Python Wheels: python3 -m pip install wheel
  2. Install Home Assistant: pip3 install homeassistant
  3. Optionally do a test drive: hass
  4. exit

Optionally: Connect to remote MySQL/MariaDB server

  1. Edit the config file: nano /home/homeassistant/.homeassistant/configuration.yaml
  2. Before History: add
recorder:
  db_url: mysql://user:password@SERVER_IP/DB_NAME?charset=utf8
  1. 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)

  1. Install Mosquitto: sudo apt-get install mosquitto
  2. Create a password file: sudo mosquitto_passwd -c /etc/mosquitto/pwfile owntracks (change owntracks to any username you want)
  3. 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
  1. Empty the cache: /sbin/ldconfig

Optionally: Install NMap

  1. Install nmap: sudo apt-get install net-tools nmap

Autostart

  1. 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
  1. Make the daemon aware of the new configuration: sudo systemctl --system daemon-reload
  2. Enable the service: sudo systemctl enable home-assistant@pi
  3. Start Home Assistant: sudo systemctl start home-assistant@pi (will start automaticly on boot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment