ESPHome – Connect ESP32 with Sensors to HomeAssistant
esphome.io
esphome.io
The most used esphome is the one I have installed with a relay to my garage opener. I'm able to automatically conjure siri using 'hey siri' on my airpods and tell her to open my garage, while being on my motorcycle. The response time of my garage opening from having finished my sentence to siri is less than half a second! I drive right in, and I have a timer set on home assistant to hit the relay again after a minute so the garage closes automatically. Also have 5 esphomes with motion/temperature sensors.
All my automations are programmed using node-red. Everything is run using docker-compose.
Keep in mind, my home assistant or esphome is NOT open to the internet, and only controllable by apple devices from outside the network.
Sounds like they’re network connected to me!
In short your phone kindly asks an Apple TV (within your local network) to execute a device command on its behalf, via iCloud.
If you trust Apple to get their device-to-device auth and crypto right (which is the same stuff that power iCloud Keychain), then you can trust HomeKit to not expose your home devices to randos on the internet.
I would rather host a Wireguard VPN on my home network...
I’m not saying it’s likely you’ll be targeted, I’m just saying the actual security offered by this setup is not very good.
On a surprising note: The language recognition had become really good for Slovenian!
I have used ESPHome to create a wireless ambient light sensor that my Mac app (https://lunar.fyi/#sensor) can use to adapt monitor brightness automatically.
Even non-technical users are now doing their own sensor with the tutorial I wrote: https://lunar.fyi/sensor
I also like to use ESPHome for standalone devices like dimmable LED strings and IR remotes, but I always wished there was a simple app to control them. My HomeAssistant dashboard became too complex and slow and is annoying to wait for it when I just want to adjust brightness or volume.
So I created another app for that called Volum: https://lowtechguys.com/volum
Below is a demo video of how I use it to control:
1. A battery powered LED string
2. An Ambilight-like SK6812 RGBW LED strip behind my monitor
3. An ESP8266 with an IR LED to control volume of an Edifier speaker
Demo video: https://youtu.be/nzz-xrEon7g- 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.
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.
It 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.
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_relayThe 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_relayBack 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!
- Expose IR commands for turning our bedroom fan on/off along with some battery-powered candles
- Flashed it to a Sonoff S31 to detect if our electric fireplace is on/off based on power usage.
- Secondary ESP32 that controls said fireplace with IR commands and has an attached dfplayer MP3 module to play a loop of fireplace sounds
- Wired up some photoresistors to an ESP32 that are spaced to match the status lights on our washing machine. The same ESP32 has an accelerometer attached to our dryer that changes its state depending on vibrations of the dryer.
- There's an ESP32 in our garage that has two VL53L0X time-of-flight range sensors to detect whether the garbage or recycling bin is out. In my automations I check if it's garbage or recycling day and send a notification if the bins haven't been taken out.
All of my automations are written in C#/.NET using NetDaemon.
In winter mode Home Assistant automatically checks if the bedrooms are cooler than the room with the fire, and pushes warm air if so.
ESP chips are great, and ESPHome makes programming them very easy.
ESP-MQTT allows more custom stuff, and I’ve done that via Arduino.
I’m sure someone skilled could make something very tidy, mine all all botch jobs, but 3 years later it’s still working fine without maintenance.
Why? A D1 Mini has 8 Digital I/O ports that could drive a 3.3.v relay module.
Still looks like you could redefine RX to a GPIO and still have 8 if you didn't need serial input. I vaguely remember running into this issue with some load cell AMPs.
A Shift Register or IO Expander seem like the more interesting and less frustrating route. I'd probably end up using an ESP01 and i2c IO Expander because I'm a masochist and love trying to squeeze as much as I can out of the ESP01.
I recently got rtlsdr to read my water meter so I can detect leaks, which is pretty cool
as long as you don't run several at once, can power from old wall wart with a few amps rating. I'm using a meanwell PSU so I can power a few other things - IR lights mostly
Take a look at the Spec for a valve from Rainbird:
https://www.rainbird.com/sites/default/files/media/documents...
Electrical Specifications:
• Power: 24 VAC 50/60 Hz (cycles/second) GBS25 Solenoid
• Inrush Current: 0.41 A (9.84 VA)
• Holding Current: 0.20 A (4.80 VA) at 60 Hz, 0.23 A (5.40 VA) at 50 Hz
If you have a sprinkler system, you can replace the on/off valve with a solenoid valve and then you're able to control the system electronically using a 24 VAC power supply and a switch. The OP replaced the switch with a relay, which is a switch that can be actuated by the lower voltage from something like a microcontroller.
> $20 in parts
With how much ESPs go for right now I kinda doubt that, what's the whole BOM?
The cost of an irrigation system is making it user friendly for a customer.
Example: https://www.amazon.com/Hunter-Sprinkler-XC400-4-Station-Cont...
Like the OP's solution, it is a microcontroller hooked up to a relay array, but it also has:
* AC/DC Transformer
* Real-Time-Clock
* Battery backup
* User Interface
* Secure, weather proof housing
* Printed Instructions
And it costs less than $90. They're making a profit on them, so the BOM is probably closer to $20-30.
The solution is completely plug-n-play compared to building from scratch, setting up a home automation system, and programming a microcontroller.
D1 Minis are like $1.50 and ESP01s are $0.95.
The 01s are cheap for a reason - they're useless for most projects, hell I'm always running out of pins even on the esp32-cams.
8 pins, half of those gnd, vin, reset, and something else. 4 are usable I think.
You can get those in bulk for less than a dollar each and are my most used microcontroller. They're so easy to deploy and ear easily powered of USB wall warts with a regulator.
If you really need more GPIO you can get an I2C based IO Expander to add 10 more GPIO.
I suppose in this case you could do it in that roundabout way by stacking two of those for relay control since it's as basic as it gets.
Anyone know any good tutorials or resources that work from "you've got everything connected, flashed, and working, here's how to polish it"?
There is a lot of great retail hardware with ESP chips out in the market. The above site is a collection of ESPHome configurations for a lot of that hardware.
Want to use a time of flight distance sensor to trigger something in an exact spot instead of a handwavey pir motion sensor going off anytime there’s motion in the room? ESPhome can do that.
It's become the glue for so many non-connected and re-connected devices.
$4usd esp8266 adds WiFi to anything. $8 esp32 adds BT and WiFi to anything.
OR reuse/take over any of thousand of existing devices that already use ESPs. IOT Light bulbs, wall switches, air quality devices... It's amazing how many new devices/sensors get added to each version.
My favorite project is adding wifi and temp/humid sensing to the IKEA $10 air sensor. We have them in every room.
Thank you ESPHome devs!!!!
Really the only downside, and it's likely something I could handle with more digging, is the task switching granularity of the main loop causes the desk to overshoot and then have to correct when going for a height. My desk control loop reads from the UART interface of the desk display, and activates the up and down buttons. If there's too much time in between loops, it'll have traveled too far. Worst case, I could just get a cheap dedicated controller like an attiny85 to handle controlling it with better real-time constraints.
This is a bit misleading, a single HASS developer requested their packages not get repackaged because they didn't want the support burden of users who think the software is broken when its actually due to packaging.
Originally on HN here: https://news.ycombinator.com/item?id=27505277
Both the GitHub issues have since been closed and settled.
It's useful and important to note that Home-Assistant's turnkey ease-of-use is partly because its acting as a package manager of sorts. When integrations and components are added by the user, their package requirements are downloaded immediately from the Internet and installed. This is quite contrary to the intended operation of NixOS and its immutable and reproducible package installation concept.
This is where the concerns of Frank came in, as a user of HASS on NixOS will likely have a sub-par experience and the documentation on the Internet for HASS will not work correctly for them in many cases. On the other-hand, I'm sure a decent amount NixOS users are probably aware of this (as I was when I was using NixOS daily).
My suggestion (and supported by the HASS founder) was that NixOS repackage HASS and call it something else, like how the code behind Firefox is repackaged without the Firefox name. This way at least NixOS users of it will get more appropriate Google results when searching for an issue related to their install, and are unlikely to burden HASS developers with support issues that are likely related to the install approach and not a HASS issue.
This was back in July of 2021, and I haven't followed up on it since, so I don't know if NixOS is doing this yet, or what the current state is there. But if you're running NixOS and want that turnkey experience, you're not going to get it.
If you want a full turnkey setup I'd highly suggest using HASS OS, whether on a small dedicated device, or in a KVM (https://www.home-assistant.io/installation/).