# Project: Home Assistant ## Preparing the host <s>I'll be using a [Raspberry Pi Zero W](https://www.raspberrypi.org/products/raspberry-pi-zero-w/). To get started, I followed the standard headless-ssh procedure: ### Headless ssh 1. Download the [Raspberry OS image](https://www.raspberrypi.org/software/operating-systems/) 2. Flash using for example [Rufus](https://rufus.ie/) or [balenaEtcher](https://www.balena.io/etcher/) 3. Add a `ssh` file to the boot partition to enable ssh on boot (as per [raspberrypi.org](https://www.raspberrypi.org/documentation/remote-access/ssh/)) 4. Idem for `wpa_supplicant.conf` ([docs](https://www.raspberrypi.org/documentation/configuration/wireless/headless.md)) </s> I wasn't able to get Home Assistant working on the Zero W (ARMv6) and so I switched to a [MinnowBoard Turbot B](https://store.netgate.com/Turbot4.aspx). ![](https://i.imgur.com/uzVvCIq.jpg) ### Installing debian I installed debian using the netinstaller from https://www.debian.org/CD/netinst/ After installation I updated and upgraded the system and installed the openssh-server: ``` sudo apt update sudo apt upgrade sudo apt install openssh-server ``` Afterwards I added my public key and disable password authentication. ## Docker To install docker I ran: ``` sudo apt install \ apt-transport-https \ ca-certificates \ curl gnupg-agent \ software-properties-common curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - # Check fingerprint: sudo apt-key fingerprint 0EBFCD88 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian \ $(lsb_release -cs) \ stable" sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io ``` ## Home Assistant To install Home Assistant I created a simple docker-compose file as per https://www.home-assistant.io/docs/installation/docker/: ```yaml= version: '3' services: homeassistant: container_name: home-assistant image: homeassistant/amd64-homeassistant:stable volumes: - /home/skippy/hass/config:/config environment: - TZ=Europe/Brussels restart: always network_mode: host ``` To run this on system startup I used a systemd unit: ``` [Unit] Description=Home Assistant After=docker.service Requires=docker.service [Service] TimeoutStartSec=10s Restart=no WorkingDirectory=/home/skippy/hass ExecStart=/usr/local/bin/docker-compose [Install] WantedBy=multi-user.target ``` On first startup I created a user and I was greated by an empty dashboard: ![](https://i.imgur.com/KWDovgC.png) ## MQTT As the central message broker I chose [Mosquitto](https://mosquitto.org/). To install it, I simply ran: ``` apt install mosquitto ``` And to create the user database and add the relevant users: ``` mosquitto_passwd -c /etc/mosquitto/passwd hass mosquitto_passwd /etc/mosquitto/passwd esp_relays mosquitto_passwd /etc/mosquitto/passwd esp_photoresistor ``` After registering the MQTT broker with all devices (see below), the topics in a client look something like this: ![](https://i.imgur.com/oRCI3VO.png) ## Adding some integrations To add integrations (services Home Assistant can talk to), go to `Configuration > Integrations`: ![](https://i.imgur.com/ZgYUOxF.png) ## ESPHome Similar to [Tasmota](https://tasmota.github.io/docs/), [ESPHome](https://esphome.io/) is a mini operating system-like firmware for the family of [Arduino](https://www.arduino.cc/), WiFi enabled devices, like the ESP8266 and ESP32. ESPHome uses a python script to craft a custom firmware bin for each of your devices, starting from a yaml config file. Tasmota on the other hand is more of an all-in-one solution. I used ESPHome for this project and created two config files: `relays.yaml` for an all-in-one relay board: ```yaml= esphome: name: relays platform: ESP32 board: nodemcu-32s wifi: ssid: "<SSID>" password: "<PASS>" ap: ssid: "Desk Fallback Hotspot" password: "<PASS>" captive_portal: # Enable logging logger: mqtt: broker: 192.168.1.70 username: esp_relays password: <PASS> ota: password: "<PASS>" switch: - platform: gpio name: "Relay 1" pin: 33 - platform: gpio name: "Relay 2" pin: 25 - platform: gpio name: "Relay 3" pin: 26 - platform: gpio name: "Relay 4" pin: 27 ``` ![](https://i.imgur.com/MlIHMUu.jpg) And `photoresistor.yaml` for an ESP8266 dev board with a photoresistor circuit: ```yaml= esphome: name: dimmer platform: ESP8266 board: thingdev wifi: ssid: "<SSID>" password: "<PASS>" ap: ssid: "Dimmer Fallback Hotspot" password: "<PASS>" captive_portal: # Enable logging logger: mqtt: broker: 192.168.1.70 username: esp_photoresistor password: <PASS> ota: password: "<PASS>" i2c: ttp229_lsf: sensor: - platform: resistance sensor: source_sensor configuration: UPSTREAM resistor: 32kOhm reference_voltage: 1V name: Resistance Sensor # Example source sensor: - platform: adc id: source_sensor pin: A0 ``` ![](https://i.imgur.com/iG7NdPt.jpg) I then, after installing ESPHome using pip, uploaded the firmware using: ``` esphome ... .yaml run ``` ## Dashboard After adding cards for all the integrations my final [Lovelace dashboard](https://www.home-assistant.io/lovelace/) looks like this: ![](https://i.imgur.com/x775ngj.png)