ESPHome Projects

Lately I’ve been trying out a few more projects that use ESPHome. I still have so much to learn, but I wanted to share the code for two projects I showed in this recent video.

Affiliate Disclosure: This page has affiliate links, which earn us commission at no cost to you.

Knob

The first device I’m using is this knob with an ESP32 inside. There are examples from the manufacturer for ESPHome. But if you want to add volume control like I did, here is the code I pieced together from examples online.

# Board: ESP32-S3 DevKitC-1 (Espressif)
# Definition: definitions/boards/esp32-s3-devkitc-1/manifest.yaml

substitutions:
  media_player_entity: media_player.shop_stereo

esphome:
  name: knob
  friendly_name: Knob
  platformio_options:
    build_flags: '-DBOARD_HAS_PSRAM'
    board_build.esp-idf.memory_type: qio_opi
    board_build.flash_mode: dio
  on_boot:
    then:
      - output.turn_off: gpio40_power_indicator_led
      - output.turn_on: gpio3_backlight_pwm
      - output.turn_on: gpio1_screen
      - light.turn_on:
          id: back_light
          brightness: 1

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

psram:
  mode: octal
  speed: 80MHz

logger:
  level: DEBUG
  #baud_rate: 0

api:

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

spi:
  mosi_pin: GPIO11
  clk_pin: GPIO10
  interface: hardware

i2c:
  - id: i2c_touchscreen
    sda: GPIO6
    scl: GPIO7
    scan: false

  - id: i2c_sensor
    sda: GPIO38
    scl: GPIO39
    scan: false

output:
  - platform: ledc
    pin: GPIO46
    id: gpio3_backlight_pwm

  - platform: gpio
    inverted: true
    id: gpio40_power_indicator_led
    pin: GPIO40

  - platform: gpio
    id: gpio1_screen
    pin: GPIO1

light:
  - platform: monochromatic
    name: Backlight
    id: back_light
    output: 
    restore_mode: ALWAYS_ON

  - platform: esp32_rmt_led_strip
    name: Status Indicator LED
    id: status_indicator_led
    rgb_order: GRB
    pin: GPIO48
    num_leds: 5
    chipset: ws2811

binary_sensor:
  - platform: gpio
    name: Button Press
    id: btn_01
    pin:
      number: GPIO41
      inverted: true
      mode:
        input: true
        pullup: true
    filters:
      - delayed_on: 15ms
      - delayed_off: 15ms

sensor:
  - platform: rotary_encoder
    id: knob
    name: 'Rotary Encoder'
    pin_a:
      number: GPIO45
      mode:
        input: true
        pullup: true
    pin_b:
      number: GPIO42
      mode:
        input: true
        pullup: true
    resolution: 1
    filters:
      - debounce: 20ms

    max_value: 100
    min_value: 0
    publish_initial_value: true
  - platform: homeassistant
    id: ha_volume_level
    entity_id: ${media_player_entity}
    attribute: volume_level
    on_value:
      then:
        - lambda: |-
            id(media_volume) = (int) round(x * 100.0f);
        - lvgl.arc.update:
            id: arc_volume
            value: !lambda return id(media_volume);
        - lvgl.label.update:
            id: display_volume
            text: 
              format: "%.0f"
              args: [ 'round(x * 100)' ]
touchscreen:
  id: touchscreen_id
  platform: cst816
  i2c_id: i2c_touchscreen
  address: 21
  interrupt_pin: GPIO5
  reset_pin: GPIO13
  skip_probe: true

globals:
  - id: media_volume
    type: int
    restore_value: false
    initial_value: "50"

display:
  id: display_id
  platform: mipi_spi
  model: GC9A01A
  cs_pin: GPIO9
  dc_pin: GPIO3
  reset_pin: GPIO14
  data_rate: 80MHz
  invert_colors: true
  show_test_card: false
  rotation: 0
  update_interval: never
  auto_clear_enabled: false

lvgl:
  displays:
    - display_id

  touchscreens:
    - touchscreen_id

  encoders:
    sensor: knob
    enter_button: btn_01
  pages:
    - id: volume_page
      bg_color: 0x000000
      widgets:
        - obj:
            id: bg_volume
            align: TOP_LEFT
            x: 0
            y: 0
            width: 240
            height: 240
            bg_color: 0x000000
            border_width: 0
        - arc:
            id: arc_volume
            align: CENTER
            y: -4
            width: 160
            height: 160
            min_value: 0
            max_value: 100
            value: 50
            adjustable: false
            start_angle: 135
            end_angle: 45
            arc_color: 0x2C2C2C
            arc_width: 14
            arc_rounded: true
            indicator:
              arc_color: 0x00D2FF
              arc_width: 14
              arc_rounded: true
        - label:
            id: display_volume
            align: CENTER
            gesture_bubble: true
            y: 0
            text_font: montserrat_44
            text: "50"
            text_color: 0xFFFFFF
        - label:
            align: CENTER
            gesture_bubble: true
            y: 88
            text_font: montserrat_14
            text: "Volume"
            text_color: 0xFFFFFF

Just make sure to add to the api, so that your connection is encrypted. You will also need to modify line 5 and swap it out with the media_player you want to control in Home Assistant.

E-Paper display

I also tried out a few E-Paper displays but I could only get one to work with ESPHome. It was this one I got on Amazon. Someone had used Claude to write code to get it to work with ESPHome.

The code below is just the same thing, but buried at the bottom of the description is a super important line missing from the demo. It’s “power_pin: GPIO7” and if I didn’t have that, then the display did not change for me.

# CrowPanel 5.79" E-Paper — Driver Demo
# Physical display: 792 × 272 px (landscape, no rotation)
# MENU button (GPIO2) cycles through 3 pages.
#
# Color convention in lambda mode (inverted):
#   Color::WHITE  →  black ink
#   Color::BLACK  →  white paper

substitutions:
  device_name: 579-e-paper

esphome:
  name: ${device_name}
  on_boot:
    priority: -100
    then:
      - component.update: my_display

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: "y"
      CONFIG_SPIRAM_RODATA: "y"

psram:
  mode: octal
  speed: 80MHz

external_components:
  - source: github://samperk1/esphome-crowpanel-579
    components: [crowpanel_579]

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

logger:
api:
  encryption:
    key: "8RJeJmyQhWZY5uwN+N4VADpYSPl2oak2VM6GOGXMOdI="
ota:
  - platform: esphome

spi:
  clk_pin: GPIO12
  mosi_pin: GPIO11

globals:
  - id: page_num
    type: int
    restore_value: false
    initial_value: '0'

font:
  - file: "gfonts://Roboto@700"
    id: font_h1
    size: 60
  - file: "gfonts://Roboto@700"
    id: font_h2
    size: 36
  - file: "gfonts://Roboto@700"
    id: font_h3
    size: 24
  - file: "gfonts://Roboto@400"
    id: font_body
    size: 18
  - file: "gfonts://Roboto@400"
    id: font_small
    size: 14
  - file: "gfonts://Roboto@700"
    id: font_label
    size: 20

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO2
      mode:
        input: true
        pullup: true
      inverted: true
    id: btn_menu
    name: "Menu"
    on_press:
      - lambda: id(page_num) = (id(page_num) + 1) % 3;
      - component.update: my_display
  - platform: gpio
    name: Exit button
    id: btn_exit
    pin:
      number: GPIO1
      mode:
        input: true
        pullup: true
      inverted: true
display:
  - platform: crowpanel_579
    id: my_display
    cs_pin: GPIO45
    dc_pin: GPIO46
    reset_pin: GPIO47
    power_pin: GPIO7
    busy_pin:
      number: GPIO48
      mode:
        input: true
        pulldown: true
    auto_clear_enabled: false
    lambda: |-
      it.fill(Color::BLACK);  // white paper background

      // ================================================================
      // PAGE 0 — BOOT SCREEN
      // ================================================================
      if (id(page_num) == 0) {

        // ESPHome house logo — centered at (170, 136), ~150px tall
        // Derived from ESPHome SVG (400×400): scale=0.636, center offset=(170,136)
        //   sx = 170 + (svgx - 200) * 0.636
        //   sy = 136 + (svgy - 196) * 0.636

        // House roof (peak y=65, base y=129, left x=91, right x=250)
        it.filled_triangle(170, 65, 91, 129, 250, 129, Color::WHITE);
        // House body (x=91..250, y=129..202)
        it.filled_rectangle(91, 129, 159, 73, Color::WHITE);

        // E letter inside the house
        // Step 1: erase a white box where the E will go (x=141..199, y=113..202)
        it.filled_rectangle(141, 113, 58, 89, Color::BLACK);
        // Step 2: E left vertical bar (full height)
        it.filled_rectangle(141, 113,  8, 89, Color::WHITE);
        // Step 3: E top bar (full width)
        it.filled_rectangle(141, 113, 58,  8, Color::WHITE);
        // Step 4: E middle bar 1
        it.filled_rectangle(149, 129, 50, 22, Color::WHITE);
        // Step 5: E middle bar 2
        it.filled_rectangle(149, 158, 50, 23, Color::WHITE);
        // Step 6: E bottom bar (full width)
        it.filled_rectangle(141, 189, 58,  7, Color::WHITE);

        // Vertical divider between logo and text
        it.line(310, 25, 310, 247, Color::WHITE);

        // Text block (centered at x=550)
        it.printf(550,  77, id(font_h1),   Color::WHITE, display::TextAlign::TOP_CENTER, "ESPHome");
        it.printf(550, 150, id(font_h3),   Color::WHITE, display::TextAlign::TOP_CENTER, "CrowPanel 5.79\" E-Paper Driver");
        it.printf(550, 186, id(font_body), Color::WHITE, display::TextAlign::TOP_CENTER, "Dual SSD1683  |  792 x 272  |  ESP32-S3");

        // Page indicator
        it.printf(789, 255, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "Press MENU  ->  1 / 3");

      // ================================================================
      // PAGE 1 — GRAPHICS DEMO
      // ================================================================
      } else if (id(page_num) == 1) {

        it.printf(396, 6, id(font_label), Color::WHITE, display::TextAlign::TOP_CENTER, "GRAPHICS DEMO");

        // Section dividers
        it.line(264, 33, 264, 260, Color::WHITE);
        it.line(528, 33, 528, 260, Color::WHITE);

        // --- Section 1: Concentric circles (center 132, 144) ---
        it.circle(132, 144, 100, Color::WHITE);
        it.circle(132, 144,  78, Color::WHITE);
        it.circle(132, 144,  56, Color::WHITE);
        it.circle(132, 144,  34, Color::WHITE);
        it.circle(132, 144,  12, Color::WHITE);
        it.filled_circle(132, 144, 5, Color::WHITE);
        it.printf(132, 252, id(font_small), Color::WHITE, display::TextAlign::TOP_CENTER, "Circles");

        // --- Section 2: Nested rectangles (center 396, 144) ---
        it.rectangle(396-100, 144-80, 200, 160, Color::WHITE);
        it.rectangle(396- 78, 144-62, 156, 124, Color::WHITE);
        it.rectangle(396- 56, 144-44, 112,  88, Color::WHITE);
        it.rectangle(396- 34, 144-26,  68,  52, Color::WHITE);
        it.rectangle(396- 12, 144- 9,  24,  18, Color::WHITE);
        it.printf(396, 252, id(font_small), Color::WHITE, display::TextAlign::TOP_CENTER, "Rectangles");

        // --- Section 3: Star lines (center 660, 144) ---
        // 8 directions at 45° intervals — elliptical reach (rx=90, ry=70)
        it.line(660, 144, 750, 144);           // E
        it.line(660, 144, 724, 199);           // SE  (90*0.707=64, 70*0.707=49)
        it.line(660, 144, 660, 214);           // S
        it.line(660, 144, 596, 199);           // SW
        it.line(660, 144, 570, 144);           // W
        it.line(660, 144, 596,  89);           // NW
        it.line(660, 144, 660,  74);           // N
        it.line(660, 144, 724,  89);           // NE
        // Outer ellipse approximation (circle, close enough)
        it.circle(660, 144, 90, Color::WHITE);
        it.printf(660, 252, id(font_small), Color::WHITE, display::TextAlign::TOP_CENTER, "Lines");

        it.printf(789, 255, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "MENU  ->  2 / 3");

      // ================================================================
      // PAGE 2 — TYPOGRAPHY SHOWCASE
      // ================================================================
      } else if (id(page_num) == 2) {

        it.printf(396, 5, id(font_label), Color::WHITE, display::TextAlign::TOP_CENTER, "TYPOGRAPHY  —  Roboto");

        // Row 1: 60px bold
        it.printf(10, 32, id(font_h1), Color::WHITE, "Aa Bb 0123");
        it.printf(789, 50, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "Bold 60px");

        // Row 2: 36px bold
        it.printf(10, 98, id(font_h2), Color::WHITE, "Aa Bb Cc 0123456789");
        it.printf(789, 110, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "Bold 36px");

        // Row 3: 24px bold
        it.printf(10, 140, id(font_h3), Color::WHITE, "ABCDEFGHIJ abcdefghij 0123456789 !@#");
        it.printf(789, 149, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "Bold 24px");

        // Row 4: 18px regular
        it.printf(10, 170, id(font_body), Color::WHITE, "The quick brown fox jumps over the lazy dog. 0123456789");
        it.printf(789, 178, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "Regular 18px");

        // Row 5: 14px regular
        it.printf(10, 196, id(font_small), Color::WHITE, "The quick brown fox jumps over the lazy dog. Pack my box with five dozen liquor jugs.");

        it.printf(789, 255, id(font_small), Color::WHITE, display::TextAlign::TOP_RIGHT, "MENU  ->  3 / 3  (wraps to 1)");
      }

      id(my_display).display();

Hope this helps! Make sure you subscribe on YouTube for future content like this.