RPi Hub Notes - ThisSmartHouse/mobile-command GitHub Wiki
- Buster Lite
- RaspAp
- 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.
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
https://www.home-assistant.io/docs/installation/raspberry-pi/
- Add
pi
user to thehomeassistant
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
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
- Configure MQTT in Home Assistant
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
(optional)
Used to store data for HASS, more flexible than SQLite files
First install MariaDB, create a database and create a HA user that has access to it.
https://pimylifeup.com/raspberry-pi-mysql/
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
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
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.
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