Activeweb appsJavaScript

Homedashboard Test

ESP32 home assistant dashboard

40 viewsAdded 1mo ago

Verified AI-Agent Built

Tier 1
Claude Code
Signals: claude-code-topic

README

ESP32 Home Assistant Display

Real-time solar and battery monitoring dashboard on an ESP32 with 3.5" touchscreen. Displays Home Assistant sensor data with 6-hour history charts using LVGL.

ESP-IDF LVGL PlatformIO

Features

  • 3-page touchscreen UI with left/right navigation
    • Home: 6-hour history charts for battery SOC and power (load + PV)
    • Debug: WiFi, heap, uptime, build info, HA status
    • Values: Large-font sensor readings (SOC, load, PV, grid, battery power)
  • Streaming history parser -- handles any response size, no buffer limits
  • 270-point charts (1 pixel per data point) with per-bin averaging
  • Auto-reconnecting WiFi with SNTP time sync
  • Screenshot capture over TCP or serial for remote debugging
  • Static analysis with clang-tidy (./scripts/lint.sh)

Hardware

  • ESP32 3.5" TFT Development Board (LCD Wiki)
  • Display: 480x320 ST7796 TFT LCD (SPI, landscape)
  • Touch: XPT2046 resistive touchscreen (shared SPI bus)
  • Power: USB (500mA+)

No additional wiring needed -- display and touch are integrated on the board.

Pin Configuration

Display (ST7796, SPI2_HOST @ 40MHz):
  CS=15  DC=2  MOSI=13  SCLK=14  MISO=12  BL=27

Touch (XPT2046, shared SPI2_HOST @ 2.5MHz):
  CS=33  IRQ=36 (unused -- pressure detection via SPI)

Quick Start

1. Install PlatformIO

pip install platformio

2. Configure Credentials

cp include/secrets.h.example include/secrets.h

Edit include/secrets.h with your:

  • WiFi SSID and password (2.4GHz only)
  • Home Assistant server URL and long-lived access token
  • Entity IDs for battery SOC, load power, PV power, grid power, battery power

3. Build and Flash

pio run -e usb --target upload    # USB upload
pio device monitor                # Serial monitor (115200 baud)

4. OTA Upload (after initial USB flash)

pio run -e ota --target upload

UI Pages

Home -- Charts

Two 6-hour history charts with current values:

Home page

Debug -- System Info

WiFi status (IP, RSSI, MAC), heap usage, uptime, loop/flush counts, ESP-IDF version, HA fetch status.

Debug page

Values -- Large Readings

Battery SOC (color-coded), load power, PV power, grid power, battery power in large font for at-a-glance reading.

Values page

Configuration

Entity IDs (secrets.h)

#define HA_ENTITY_BATTERY_SOC   "sensor.your_battery_soc"
#define HA_ENTITY_LOAD_POWER    "sensor.your_load_power"
#define HA_ENTITY_PV_POWER      "sensor.your_pv_power"
#define HA_ENTITY_GRID_POWER    "sensor.your_grid_power"
#define HA_ENTITY_BATTERY_POWER "sensor.your_battery_power"

Update Intervals (config.h)

SettingDefaultDescription
HA_UPDATE_INTERVAL10sCurrent sensor values
HISTORY_UPDATE_INTERVAL60s6-hour chart data
INFLUX_UPDATE_INTERVAL15sInfluxDB (placeholder)

History Charts

  • Duration: 6 hours (HISTORY_HOURS)
  • Resolution: 270 bins = 1 per chart pixel (~80 seconds each)
  • Method: Streaming parse with per-bin averaging -- handles thousands of data points without buffer limits
  • Fill: Zero-order hold (forward + backward) for gap-free rendering

Screenshots

Capture what the display shows remotely:

# TCP (fast, requires WiFi)
python3 scripts/screenshot.py tcp <ESP32_IP>
python3 scripts/screenshot.py tcp <ESP32_IP> --watch 5    # every 5s

# Serial (works before WiFi, slower)
python3 scripts/screenshot.py serial /dev/ttyUSB0

Software Architecture

Stack

LayerTechnology
FrameworkESP-IDF (native, not Arduino)
GraphicsLVGL v8.3
DisplayCustom ST7796 SPI driver
TouchCustom XPT2046 SPI driver
HTTPesp_http_client
JSONcJSON (entity state) / manual parse (history stream)
WiFiesp_wifi + esp_event (event-driven, auto-reconnect)
TimeSNTP via esp_sntp
BuildPlatformIO with ccache

File Structure

src/
  main.cpp              Entry point, LVGL UI, main loop
  display_driver.c/h    ST7796 SPI driver
  touch_driver.c/h      XPT2046 touch driver
  wifi_manager.c/h      WiFi with auto-reconnect, RSSI, MAC
  http_client.c/h       HA API client with streaming history parser
  screenshot_server.c/h BMP capture over TCP/serial
include/
  config.h              Pins, intervals, chart layout constants
  secrets.h             Credentials (not in git)
  secrets.h.example     Credentials template
  lv_conf.h             LVGL configuration
scripts/
  lint.sh               clang-tidy static analysis
  screenshot.py         Remote screenshot capture

Troubleshooting

ProblemFix
WiFi won't connectCheck SSID/password, ensure 2.4GHz network
"HA fetch failed"Verify token, URL (include http://), entity IDs
Display blankCheck USB power (500mA+), serial monitor for errors
Charts flat/emptyWait 60s for first history fetch; check SNTP sync in serial log
Touch unresponsiveTouch uses pressure detection, not IRQ; press firmly
Memory crashesCheck heap in Debug page; reduce LV_MEM_SIZE in lv_conf.h

Serial Monitor

pio device monitor    # 115200 baud

Log tags: main, display, touch, wifi, http. Look for History: N raw points streamed to verify chart data flow.

Resources

License

MIT License

Tags

built-with-claude-codejavascript

Similar Tools