From b782e249f519f25d1f537ac2b8397f26ce511114 Mon Sep 17 00:00:00 2001 From: Joshua King Date: Tue, 8 Sep 2026 10:01:04 -0400 Subject: [PATCH] Refactor ESP32 camera configuration and add dynamic controls for brightness, contrast, and AE level tuning --- esphome/esp32-h2c-camera.yaml | 71 +++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/esphome/esp32-h2c-camera.yaml b/esphome/esp32-h2c-camera.yaml index 565c8d4..8b7a896 100644 --- a/esphome/esp32-h2c-camera.yaml +++ b/esphome/esp32-h2c-camera.yaml @@ -56,34 +56,42 @@ mdns: web_server: port: 80 -i2c: - - id: camera_i2c - sda: GPIO8 - scl: GPIO9 - scan: false - esp32_camera: name: "${friendly_name}" external_clock: pin: GPIO5 frequency: 20MHz - i2c_id: camera_i2c + i2c_pins: + sda: GPIO8 + scl: GPIO9 data_pins: [GPIO16, GPIO18, GPIO21, GPIO17, GPIO14, GPIO7, GPIO6, GPIO4] vsync_pin: GPIO1 href_pin: GPIO2 pixel_clock_pin: GPIO15 - # Start conservative for reliability; increase later if stable. - resolution: 800X600 - jpeg_quality: 15 + # Resolution & quality (ESP32-S3 with Octal PSRAM handles XGA easily) + resolution: 1024X768 + jpeg_quality: 10 max_framerate: 20 fps idle_framerate: 0.2 fps - frame_buffer_count: 1 + frame_buffer_count: 2 - # Common orientation defaults for this module. + # Orientation vertical_flip: true horizontal_mirror: false + + # Image tuning for chamber monitoring through tinted door brightness: 1 + contrast: -1 + saturation: 0 + + # Auto-Exposure & Gain tuning (AEC2 + AE Level lift shadows away from bright LEDs) + aec_mode: auto + aec2: true + ae_level: 1 + agc_mode: auto + agc_gain_ceiling: 8X + wb_mode: auto # Camera endpoints: # Stream: http://:8080 @@ -144,3 +152,42 @@ interval: - logger.log: "Wi-Fi not connected for 5 min, rebooting..." - delay: 10s - lambda: 'App.safe_reboot();' + +# Dynamic controls exposed to Home Assistant for real-time camera tuning +number: + - platform: template + name: "${friendly_name} Brightness" + min_value: -2 + max_value: 2 + step: 1 + initial_value: 1 + optimistic: true + set_action: + - lambda: |- + sensor_t *s = esp_camera_sensor_get(); + if (s) s->set_brightness(s, (int)x); + + - platform: template + name: "${friendly_name} Contrast" + min_value: -2 + max_value: 2 + step: 1 + initial_value: -1 + optimistic: true + set_action: + - lambda: |- + sensor_t *s = esp_camera_sensor_get(); + if (s) s->set_contrast(s, (int)x); + + - platform: template + name: "${friendly_name} AE Level" + min_value: -2 + max_value: 2 + step: 1 + initial_value: 1 + optimistic: true + set_action: + - lambda: |- + sensor_t *s = esp_camera_sensor_get(); + if (s) s->set_ae_level(s, (int)x); +