This recipe drives a 128×64 monochrome OLED display to show the current time and one or more live temperature readings, all pulled from Home Assistant or a locally-attached sensor. ESPHome’s built-in TrueType font renderer and display lambda make it straightforward to build a clean, always-on information panel without any external libraries.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
Hardware needed
| Component | Notes |
|---|---|
| ESP8266 or ESP32 board | Any board with two free GPIO pins for I²C |
| SSD1306 or SH1106 128×64 OLED | 1.3 ” modules often use the SH1106 controller — check your datasheet |
| Four dupont wires | VCC, GND, SDA, SCL |
- VCC → 3.3 V (some modules also accept 5 V — check your display’s spec sheet)
- GND → GND
- SDA → any free GPIO (e.g. GPIO4 on ESP8266 / GPIO21 on ESP32)
- SCL → any free GPIO (e.g. GPIO5 on ESP8266 / GPIO22 on ESP32)
Font files
ESPHome renders text using TrueType fonts. You must place the.ttf files in the same /config/esphome/ directory as your YAML before running a build.
Good free choices:
- Silkscreen (
slkscr.ttf) — a crisp pixel font, great at small sizes - Bebas Neue (
BebasNeue-Regular.ttf) — tall, narrow digits that read well at large sizes - Arial (
arial.ttf) — familiar sans-serif for mid-size labels
gfonts:// scheme to let ESPHome download the font automatically at compile time:
Complete YAML configuration
The configuration below pulls time from Home Assistant, imports two temperature sensors (inside and outside), defines three font sizes, and renders the layout withprintf / strftime calls inside the display lambda.
Configuration walk-through
Time component
platform: homeassistant syncs the on-chip RTC from Home Assistant over
the native API. If your device is not always connected to HA, swap this
for platform: sntp and supply NTP server addresses — the rest of the
config stays identical.Sensor imports
platform: homeassistant sensors mirror any numeric entity from HA onto
the ESP without republishing it back. Setting internal: true keeps your
HA entity list clean. The has_state() guard in the display lambda
prevents the string nan from appearing on screen before the first value
arrives.Font definitions
Each
font entry compiles the glyphs you need into firmware at build time.
The id field is what you reference inside the display lambda — keep names
short and descriptive (font_small, font_medium, font_large).I²C bus
Set
sda and scl to your actual GPIO numbers. Run with scan: true
once (and check the ESPHome logs) to discover the I²C address of your
display if you are unsure whether it is 0x3C or 0x3D.Display lambda
The lambda runs every display refresh cycle.
it.printf works like C’s
printf; it.strftime uses standard strftime format codes. The second
and third arguments are the X/Y pixel coordinates. TextAlign constants
control which corner of the text bounding box sits at those coordinates —
BASELINE_LEFT pins the text baseline to the left edge, useful for
aligning digits that vary in width.