ESP32 + OLED Display: Display Weather from Home Assistant
ESP32 + OLED Display: Display Weather from Home Assistant
Ever wanted a sleek, always-on display showing the current weather right from your Home Assistant dashboard? I did—and after some tinkering, I built one using an ESP32 and a tiny OLED screen. In this guide, I’ll walk you through the process, sharing pitfalls I encountered (like why my first attempt showed gibberish instead of temperatures) and how to avoid them.
Why This Project?
I love having ambient displays around my home that show useful info without needing to open an app. An ESP32 paired with an OLED is perfect for this: it’s cheap, energy-efficient, and easy to customize. Plus, pulling data from Home Assistant means you can display anything—not just weather.
What You’ll Need
Here’s the hardware and software I used:
Hardware:
- ESP32 development board (any variant will work)
- 0.96" I2C OLED display
- Breadboard and jumper wires
- USB cable for power/flashing
Software:
- Home Assistant (already set up)
- ESPHome (for ESP32 firmware)
- Arduino IDE (optional, for troubleshooting)
Step 1: Wiring the ESP32 and OLED
The OLED uses I2C communication, so connect it to the ESP32 as follows:
OLED Pin | ESP32 Pin |
---|---|
GND | GND |
VCC | 3.3V |
SDA | GPIO 21 |
SCL | GPIO 22 |
Step 2: Setting Up ESPHome in Home Assistant
- Install ESPHome via Home Assistant’s Add-on Store if you haven’t already.
- Create a new ESPHome device for your ESP32. Here’s the base configuration (
esp32-weather-display.yaml
):
esphome:
name: esp32-weather-display
platform: ESP32
board: nodemcu-32s
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap: {}
api:
encryption:
key: !secret api_key
ota:
password: !secret ota_password
i2c:
sda: 21
scl: 22
scan: true
font:
- file: "gfonts://Roboto"
id: roboto
size: 12
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
lambda: |-
it.printf(0, 0, roboto, "Loading...");
- Flash the ESP32 via USB. If all goes well, it’ll connect to Wi-Fi and show “Loading…” on the OLED.
Step 3: Fetching Weather Data from Home Assistant
Now, let’s modify the ESPHome config to display weather data. Assuming you’re using Home Assistant’s built-in weather
integration:
sensor:
- platform: homeassistant
name: "Outside Temperature"
entity_id: weather.your_weather_entity
attribute: temperature
id: temp_outside
- platform: homeassistant
name: "Weather Condition"
entity_id: weather.your_weather_entity
attribute: condition
id: weather_condition
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
lambda: |-
it.printf(0, 10, roboto, "Temp: %.1f°C", id(temp_outside).state);
it.printf(0, 30, roboto, "Condition: %s", id(weather_condition).state.c_str());
Replace weather.your_weather_entity
with your actual weather entity (e.g., weather.openweathermap
).
Step 4: Customizing the Display
Want to make it prettier? Here’s how to add icons and dynamic formatting:
lambda: |-
// Display temperature
it.printf(0, 10, roboto, "🌡️ %.1f°C", id(temp_outside).state);
// Map weather conditions to icons
std::string condition = id(weather_condition).state;
if (condition == "sunny") {
it.printf(0, 30, roboto, "☀️ %s", condition.c_str());
} else if (condition == "rainy") {
it.printf(0, 30, roboto, "🌧️ %s", condition.c_str());
} // Add more conditions as needed
Troubleshooting
Problem: OLED stays blank after flashing.
Fix:
- Double-check I2C wiring (SDA/SCL).
- Run
i2c_scanner
in Arduino IDE to confirm the OLED address (often0x3C
or0x3D
).
Problem: Weather data doesn’t update.
Fix:
- Ensure the
entity_id
in ESPHome matches your Home Assistant weather entity. - Restart both Home Assistant and the ESP32.
Going Further
- Add indoor temperature/humidity using an AHT10 sensor (see my ESP32 temperature monitoring guide).
- Make it battery-powered for portable use.
- Use multiple screens to cycle through stats like air quality or calendar events.
FAQ
Q: Can I use a bigger OLED display?
A: Absolutely! Just adjust the model
in the ssd1306_i2c
config (e.g., SSD1306 128x32
).
Q: Why is my ESP32 overheating?
A: If you’re powering it via USB, overheating is rare. If using a battery, add a deep_sleep
interval to conserve power.
Q: Can I display other Home Assistant data?
A: Yes! Any sensor or attribute can be fetched. Try sensor.indoor_temperature
or binary_sensor.door_window
.
Built this project? Tag me @omarghader—I’d love to see your setup!