Back in the day HA was all about YAML. It's still there but mostly hidden behind the GUI but /config/configuration.yaml still does a lot of work.
ESPHome is simply amazing. I've got several ESP80266s with various lash ups all just working. For example, when my work computer room generator fires up a GPIO on a ESP8266 gets twitched from the power distribution board, another pin gives me mains power state from the perspective of the board. A few dozen lines of YAML - mostly copy n paste and I have a really decent sensor for less than £10 parts.
We test the system every few weeks by turning a key. The UPSs beep for a few seconds, and the genny fires up. After a while you turn the key back, the UPSs beep again and then the mains takes the load back. Meanwhile your phone goes off several times with notifications (SMS, Teams etc)
I particularly enjoy watching customer's expressions when I'm showing them around and I do a test there and then.
I'm just doing a link to our rather ancient building alarm to get notifications. This will be a ESP01-S thing to get it really small. I was quoted many £1000s for a "modern system" with an app etc. The existing sensors are fine and the alarm itself works fine. It now has a length of CAT5e connected to some of its terminals for an external sounder. It delivers 12V, earth and a 12V signal. I just have to turn the 12V into 3.3V via some Zeners and stabilize it with a capacitor to power the ESP and the signal down to 3.3V via some resistors. I think!
What would be a better option than YAML? The main advantages are ease of in-lining C++, and it's ubiquitous.
Having to use k8s at work also makes it not much of a context switch to use for me, and the secrets management is great using the `!include`s.
But yeah the killer feature here is the inlining of C++, and the use of platformio. You really can do anything without much work (maybe at most one or two external C++ header files for really custom stuff) inside ESPhome, and it's easy to see where your snippets go when you inspect the generated C++ code.
ESPHome just automates all the super tedious parts of working with esp32s (stuff like connecting to wifi, MQTT, OTA upgrades, logging to mqtt, etc), without sacrificing any power.
My only complaint is that because it uses arduino (I think?) you can't really do powersaving really well, but I don't think many people use battery powered esp32, but this basically eliminates that possibility, at least in my research.
I write my own firmware for all of my ESP devices and I can confirm, those definitely are the bulk of the work. The latest one (for a relay to power cycle my modem if the internet goes down) took less than an hour to write since I was able to copy-paste all of that boilerplate from a previous project.
I was doing that too for all of my projects. I was developing them as if they were products I could potentially sell. When I accepted that I wasn't ever going to do that, I gave ESPHome a try.
> took less than an hour to write since I was able to copy-paste all of that boilerplate from a previous project.
It would probably take 5 minutes to configure from scratch ESPHome, less time if you're copying from an existing config. In addition to that, you get automatic logging into Home Assistant and deep integration for free.
Using Hypfer's discovery[1] that you could read the raw values from Ikea's Vindriktning using an ESP, I wrote an ESPHome script for an ESP01 that pipes the data into Home Assistant. Now when I'm cooking and the air quality gets too bad my HVAC fan kicks on to clear the air. It took longer to solder everything up than it did to "code".
YAML:
esphome:
name: air-quality-sensor-1
esp8266:
board: esp01_1m
# Enable logging
logger:
# Disable logging
baud_rate: 0
# Enable Home Assistant API
api:
ota:
password: !secret aqs_ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Air-Quality-Sensor-1"
password: !secret aqs_hotspot_password
captive_portal:
# Setup Ikea Vindriktning PM2.5 sensor
uart:
rx_pin: GPIO3
baud_rate: 9600
sensor:
- platform: pm1006
pm_2_5:
name: "Ikea Vindriktning PM25"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 10
[1] https://github.com/Hypfer/esp8266-vindriktning-particle-sens... switch:
- platform: gpio
pin: 25
name: "Modem relay"
restore_state: ALWAYS_ON
id: modem_relay
interval:
- interval: 1min
if:
condition:
not:
wifi.connected
then:
- switch.turn_off: modem_relay
- delay: 1s
- switch.turn_on: modem_relayIt isn't a 1:1 alternative, but I've always thought that ESPhome would be much more accessible for the non-devs if they introduced a GUI similar to Home Assistant's automation GUI.
The yaml files in ESPHome aren't any different than yaml for Git Pipelines, Docker, or K8.
The don't contain much if any logic.
Here's my garage door based on a Malouf ESP Dev board (https://maloufelectronics.com/):
esphome:
name: garagedoor
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: !secret garagedoor_ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Garage Fallback Hotspot"
password: !secret garagedoor_hotspot_password
# Enable Captive Portal
captive_portal:
# Define Hall Effect Sensor
binary_sensor:
platform: gpio
pin:
number: GPIO16
inverted: true
name: "Garage Door Sensor"
device_class: garage_door
# Define Relay
switch:
- platform: gpio
name: "Garage Door Relay"
id: garage_door_relay
pin: GPIO14
restore_mode: ALWAYS_OFF
on_turn_on:
- delay: 1000ms
- switch.turn_off: garage_door_relay
- Users produce yaml describing a microcontroller connected to (sensors, inputs, outputs, networks, services, etc).
- A python layer type checks that yaml, and spits out autogenerated C++ code (which can be inspected if desired)
- C++ is compiled and installed onto the hardware
- future updates can be made OTA
- extensible by either writing (hopefully small amounts of) C++ inside yaml (lambdas), or including/referencing C++ code (external components)
I’m still not positive I like yaml for the DSL, but that might be a personal bias and I’m not sure what an obviously better solution would be.