Touch pad dimmer with ESP32 & ESPHome

Recently I’ve been toying a lot with ESPHome in combination with Home Assistant. In this post I’ll show how I made a touch-pad LED dimmer.

My goal was to have touch control over one or more LED strips. My requirements for the system:

  • A single tap should toggle the LED strip. This toggling should use the default transition. In other words, if the the dimming behaviour needs different transitions, this shouldn’t interfere with the normal toggles.
  • Holding the touch pad should smoothly increase or decrease the brightness the LED strip. This stops when the LED is either fully on or fully off.
  • Releasing and then holding the touch pad should change the direction, i.e. if the light was getting dimmer, release & hold should start making it brighter.

From a coding standpoint, I had two more wishes:

  • To add another touch pad + LED strip, it should require as little code copying as possible.
  • The amount of lambda in the YAML file should be kept to a minimum.

This is what I came up with. The ingredients you need to make it work in the YAML file are:

  • A light with its output
  • A binary_sensor for the touch pad
  • An esp32_touch: section to enable touch support
  • And finally the touch_dimmer.zip file you can download at the bottom of this post.

Here is a minimal example YAML file:

esphome:
  name: name-of-your-device

# Add a light and its output:
output:
  - platform: ledc
    id: the_output
    pin: GPIO17

light:
  - platform: monochromatic
    id: the_light
    output: the_output
    name: The LED

# Add a binary touch sensor:
esp32_touch:

binary_sensor:
  - platform: esp32_touch
    id: the_touch_sensor
    pin: GPIO13
    threshold: 550

# Add the touch dimmer itself:
touch_dimmer:
  - id: the_touch_dimmer
    light_id: the_light
    touch_id: the_touch_sensor

# The touch dimming code needs the ESPHome scripting
# component. If your YAML file has no scripts yet,
# just add this dummy.
script:
  - id: dummy
    mode: single
    then:

Finally, download touch_dimmer.zip and extract it next to your YAML file. This should give you this directory structure:

your_project.yaml
touch_dimmer_example.yaml
custom_components/touch_dimmer/__init__.py
custom_components/touch_dimmer/touch_dimmer.h

Download touch_dimmer.zip

Last updated for ESPHome version 2025.10.1.

dr. Sybren A. Stüvel
dr. Sybren A. Stüvel
Open Source software developer, photographer, drummer, and electronics tinkerer

Related