Using an ESP32-C3 connected to HomeAssistant via ESPHome, control 12v yard path lights including configuring automations to turn lights on/off at sunset/sunrise and dimming.
This short guide will show you how to use HomeAssistant, and the ESPHome app for it, to control LED dimming. In this case I'm using this for low voltage yard path lights, but could be used for anything.
If you have HomeKit integrated with HomeAssistant than you can also control/dim your LEDs from your iPhone!
- ESP32-C3 $1.81/e (can really be any ESP-type device that has wifi)
- 12v power supply $14-22/e
- IRLB8721 MOSFET for dimming the 12v supply via PWM - $0.85/e (datasheet)
- 5v step-down buck converter (to give the ESP32 5v from the 12v supply) $1.92/e
- setup a new ESP32-C3 (or equivalent) device in ESPHome via HomeAssistant (you can flash the ESP via the ESPhome web interface, just make sure to setup wifi)
- edit the device in ESPHome in HomeAssistant and place the below code
- go to new device and set to location/give it a name, etc
- in HA, configure automations as needed (e.g. turn on a sunset, turn off at dawn)
esphome:
name: path-lights
platform: ESP32
board: esp32dev
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true # optional
logger:
api:
ota:
output:
- platform: ledc
pin: GPIO5 # Change to your actual GPIO
id: pwm_led
frequency: 1000Hz # Adjust if flickering occurs
light:
- platform: monochromatic
name: "Path Lights"
output: pwm_led
default_transition_length: 1s
Make sure to set the above wifi secrets in ESPHome
- MOSFET Gate (via 220Ω resistor) → ESP32 GPIO
- MOSFET Drain → Negative (−) of LED string
- MOSFET Source → Ground (GND)
- 12V Power Supply + → Positive (+) of LED string
- 12V Power Supply - → GND (common ground with ESP32)