RPi Hub Notes - ThisSmartHouse/mobile-command GitHub Wiki

RPi Hub Notes

  • Buster Lite
  • RaspAp

General Setup

  • Flash Firmware
  • Install RaspAp
  • Edit dnsmasq.conf
conf-dir=/etc/dnsmasq.d

Then in `/etc/dnsmasq.d/rv.conf

server=/local/192.168.1.7 # Route .local to local DNS
local=/rv/ # Route *.rv to /etc/hosts

Important Note on AP - When configuring RaspAp you must use 2.4ghz connections for both the client connection and the AP. The AP requires it (as ESP8266 modules can't do 5ghz) and while RaspAP will merrily let you configure the AP to be 2.4ghz, the AP created will be 5ghz regardless if you aren't connected as a 2.4ghz client.

DNS entries

Local RV DNS entries live in /etc/hosts and so far we have:

10.2.1.1		ap.smart.rv
10.2.1.2		mitch.smart.rv
10.2.1.2		ota.smart.rv

Note: You must restart dnsmasq after modifying /etc/hosts for it to take effect

Install Home Assistant

https://www.home-assistant.io/docs/installation/raspberry-pi/

  • Add pi user to the homeassistant group so it can edit HA configs
sudo adduser pi homeassistant
sudo chmod -R 775 /home/homeassistant/.homeassistant
ln -s /home/homeassistant/.homeassistant /home/pi

Install Mosquitto MQTT

sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
  • Configure MQTT in Home Assistant

Create bridge between RV and home

This is an optional step to create a MQTT bridge between the RV's MQTT server and the house MQTT server. This lets us actually get data from the RV in the house Home Assistant (SARAH) when the RV is in range of the house's WiFi connection!

Create /etc/mosquitto/conf.d/home.conf with

connection home
address aristotle.coogle.local:1883

topic /rv/# out 0
topic /rv/# in 0

Install MariaDB/MySQL

(optional)

Used to store data for HASS, more flexible than SQLite files

Install MariaDB

First install MariaDB, create a database and create a HA user that has access to it.

https://pimylifeup.com/raspberry-pi-mysql/

Setup Home Assistant

https://www.home-assistant.io/components/recorder/

sudo apt-get install libmariadb-dev libmariadb-dev-compat
sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
pip3 install mysqlclient

Then create a URI for the connection in secrets.yaml

db_mysql: mysql://user:pass@localhost/ha?charset=utf8

Install HAProxy

HA Proxy is used to allow us to have nice URLs for various things, even if they exist on the same machine at different ports. For example, Home Assistant runs on port 8123 but we want to access it from mitch.smart.rv

sudo apt-get install haproxy

Change lighttpd port

Edit /etc/lighttpd/lighttpd.conf server.port to 8080

Add a /etc/lighttpd/conf-enabled/10-ota.conf file to setup the OTA path for the IoT devices

$SERVER["socket"] == ":8081" {
   server.document-root = "/var/www/ota"
}

Also add corresponding sub-dirs for the various IoT firmwares we have.. i.e. /var/www/ota/lights/, each will have a ota-manifest.json file.

Setup HaProxy routes

Add the following to the /etc/haproxy.conf file at the bottom:

Note: This config contains duplicates that aren't actually necessary. I.e. you really only need the *.smart.rv hosts and one backend for each. But I have two because I want to be able to access these services while connected to my home LAN as well.

frontend http-in
	bind *:80

	acl host_homeassistant hdr(host) -i mitch.smart.rv
	acl host_raspap hdr(host) -i ap.smart.rv
	acl host_homeassistant_2 hdr(host) -i mitch.coogle.local
	acl host_raspap_2 hdr(host) -i mitch-ap.coogle.local
	acl host_esp_ota hdr(host) -i ota.smart.rv
	acl host_esp_ota_2 hdr(host) -i mitch-ota.coogle.local

	use_backend ota if host_esp_ota
	use_backend ota if host_esp_ota_2

	use_backend homeassistant if host_homeassistant_2
	use_backend raspap if host_raspap_2
	use_backend homeassistant if host_homeassistant
	use_backend raspap if host_raspap

backend ota
	reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
        option forwardfor
        server ota1 192.168.50.1:8081

backend raspap
	reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
	option forwardfor
	server raspap1 192.168.50.1:8080

backend homeassistant
        reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
        option forwardfor
        server homeassistant1 192.168.50.1:8123
⚠️ **GitHub.com Fallback** ⚠️