Setup
I installed mosquitto (MQTT broker) and redis natively as it's simple enough to configure and manage them:
sudo apt install mosquitto redis
By default, they will only bind to localhost (127.0.0.1) ports 1883 and 6379 respectively, preventing LAN devices and docker containers from connecting.
To work around that, edit /etc/redis/redis.conf and find set the "bind" parameter to your liking (it's well documented withing the file) then either set "protected-mode" to no or set up authentication/security.
Then create a mosquitto conf file, e.g. sudo nano /etc/mosquitto/conf.d/myserver.conf, again set "bind_address" to your liking and either "allow_anonymous true" or set up authentication.
Restart both services: sudo systemctl restart mosquitto redis
And then you can simply run the docker image, in a container name "homeassistant":
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=Europe/London \
-v <A LOCAL CONFIG DIRECTORY>:/config \
-v /run/dbus:/run/dbus:ro \
--network=host \
ghcr.io/home-assistant/home-assistant:stable
and move straight to configuration at http://<host IP>:8000 (you can change the port later or remap it by replacing --network=host
with -p <yourport>:8000
).
It should be pretty straightforward to plug it into the reverse proxy like I did for Gitlab and everything else, but the idea of my house resources being that easily accessible still makes me a little uneasy :) The VPN tunnel works just fine so I'm going with it for now.
Back to topThird party "integrations"
Many manufacturers (if not all) provide their HA "integration" plugin, so you can register e.g. a smart light from Wiz and a smart switch by HiveHome and connect them to each other.
Go to Settings -> Devices and services. You can add new Integrations in the Integrations section, e.g. WiZ, to integrate your smart bulbs.
What will likely happen after that is the devices will automatically be detected and all you'll have to do is put them in a room, place them in your dahsboard and create whatever rule to have them hued or swiched on and off.
Most things are free, for something like Amazon Alexa integration, you'll have to create a Home Assistant cloud account and pay the required fee.
Back to top
ESPhome
A really neat solution to get things done cheaply with HomeAssistant is by using ExpressIf platforms/dongles such as the ESP32 flashed with the ESPHome firmware. This firmware allows to register the dongle as a HA "satellite" driving actuators and sending back sensor data.
It's all within the configuration file; just set the server coordinates, wifi SSID/password, declare your "entities" (sensors/actuators), assemble the hardware and switch it on. Home Assistant will display the entities under the MQTT "integration" and allow you to plug them into your house as you please.
The following shows an example YAML for an ESP32 dongle which relays data from a Xiaomi BLE temperature+humidity sensor, drives a switch GPIO23 and decodes button events on GPIO21:
# Device name as it will show in the MQTT integration. Nothing to do with your room arrangement in HA, which can later be assigned to individual entities
esphome:
name: living_room_x_y_z
# Device firmware/type, for compilation and flashing
esp32:
board: denky32
framework:
type: arduino
# Enable logging
logger:
# Wifi settings
wifi:
ssid: "<WIFI NAME>"
password: "<WIFI PASSWORD>"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "<ARBITRARY NAME>"
password: "<ARBITRARY PASSWORD>"
# MQTT server
mqtt:
broker: <SERVER IP>
# Switch driver
output:
- platform: gpio
pin: GPIO23
id: gpio_light
# "Light switch" definition for physical I/O driver
light:
- platform: binary
name: Sunroom light
output: gpio_light
# Button sensor (binary sensor)
binary_sensor:
- platform: gpio
pin:
number: GPIO21
inverted: true
name: "Sunroom button 2"
# Advanced event detection
on_multi_click:
- timing:
- ON for at most 0.5s
- OFF for at most 0.2s
- ON for at most 0.5s
- OFF for at least 0.2s
then:
- logger.log: "Double-Clicked"
- mqtt.publish:
topic: sunroom_buttons/binary_sensor/suroom_button_2/state
payload: "Double click"
- timing:
- ON for at most 0.5s
- OFF for at least 0.2s
then:
- logger.log: "Single-Clicked"
- mqtt.publish:
topic: sunroom_buttons/binary_sensor/suroom_button_2/state
payload: "Single click"
- timing:
- ON for 1s to 3s
- OFF for at least 0.2s
then:
- logger.log: "Long press"
- mqtt.publish:
topic: sunroom_buttons/binary_sensor/suroom_button_2/state
payload: "Long press"
Xiaomi temperature/humidity sensors
I bought a few cheap temp/humid sensors by Xiaomi, model LYWSD03MMC to monitor pantry, backyard and house temperature.
They are Bluetooth Low Energy and battery powered (CR2032), which lasts several months.
Normally you would use a smartphone app to read out the on-device ~1month history, but you'd have to be meters-close to do that.
With ESPHome and Home Assistant, the sensor data is retrieved and stored many times per minute and stored in the server so it can be accessed from the network, go as far back in time as one wants and/or used for automation.
I followed this procedure: https://esphome.io/components/sensor/xiaomi_ble.html#lywsd03mmc
The stock firmware worked well enough, all I had to do was read out the BindKey (TeLinkFlasher app https://atc1441.github.io/TelinkFlasher.html) and store it in the ESPhome config file:
# Enable Bluetooth scanning for this ESP32
esp32_ble_tracker:
# Xiaomi LYWSD03MMC sensors to relay. Details are made up, you'll have to find your own (all the details down in the next sub-section)
sensor:
- platform: xiaomi_lywsd03mmc
mac_address: "00:11:22:33:44:FF"
bindkey: "a84538257de4a196ada805c900dee75a"
temperature:
name: "Backyard Temperature"
humidity:
name: "Backyard Humidity"
battery_level:
name: "Backyard T/H Battery Level"
Back to top
Companion mobile app
I use the Home Asistant app (iOS, Android) on my phone to access the service over VPN, works just fine.
On Windows, I just browse to <server IP>:<HA container port> and use the web frontend.
Back to top
Comments