This repository contains two separate implementations of a 4-digit, 7-segment style clock using an ESP32 microcontroller and WS2812B addressable LED strips.
The reference hardware uses custom PCBs with WS2812 LEDs in series, but regular LED strips can be used to form the digits as well.
Choose the implementation that best fits your needs:
- Location:
src/main.cpp
- Platform: PlatformIO with Arduino framework
- Features: Basic WiFi clock with automatic failover to random number mode
- Dependencies: No Home Assistant required
- Setup: Simple WiFiManager configuration via captive portal
- Location:
esphome/rgb-clock.yaml
- Platform: ESPHome
- Features: Full Home Assistant integration with advanced color/brightness controls
- Dependencies: Requires Home Assistant and ESPHome
- Setup: YAML configuration with OTA updates
Required Components:
- ESP32 Development Board (tested: ESP32 DevKit, Seeed XIAO ESP32S3)
- WS2812B Addressable LED Strip (84 LEDs total: 4 digits Γ 7 segments Γ 3 LEDs per segment)
- 5V Power Supply (adequate for ESP32 and LED strip)
- Jumper wires for connections
Optional Components:
- BH1750 Ambient Light Sensor (I2C) - for automatic brightness adjustment
Wiring:
- LED Strip Data Pin β ESP32 GPIO 5 (configurable in platformio.ini)
- LED Strip 5V β Power Supply 5V
- LED Strip GND β Power Supply GND and ESP32 GND
- ESP32 VIN β Power Supply 5V (if using 5V supply)
- BH1750 SDA β ESP32 GPIO 21 (if using light sensor)
- BH1750 SCL β ESP32 GPIO 22 (if using light sensor)
- BH1750 VCC β ESP32 3.3V
- BH1750 GND β ESP32 GND
The standalone firmware provides a simple, reliable clock implementation:
Core Features:
- WiFi Time Sync: Connects to WiFi and syncs time via NTP
- Automatic Failover: If WiFi fails, displays random colorful numbers (0000-9999)
- Colorful Display: Each digit shows in different colors with smooth animations
- Easy Setup: Uses WiFiManager for simple WiFi configuration via captive portal
- Auto-Reconnect: Attempts to reconnect to WiFi every 60 seconds when in random mode
- Visual Feedback: LED animations during time sync and connection attempts
Optional Features (compile-time enabled):
- BH1750 Light Sensor: Automatic brightness adjustment based on ambient light
- Night Mode: Automatic dimming in low light conditions
- Install PlatformIO IDE or PlatformIO Core
git clone <repository-url>
cd mini-clock-rgb
pio run -t upload
- After flashing, the ESP32 will create a WiFi access point named "Mini Clock RGB"
- Connect to this AP with your phone/computer
- A captive portal will open automatically (or go to 192.168.4.1)
- Select your WiFi network and enter the password
- The clock will connect and start displaying time
To enable the BH1750 light sensor support:
Method A: Edit src/main.cpp
and change:
#define BH1750_ENABLED 0
to:
#define BH1750_ENABLED 1
Method B: Add to platformio.ini
build flags:
build_flags = -D BH1750_ENABLED=1
The firmware is tested on:
- ESP32 DevKit V1 (default)
- Seeed XIAO ESP32S3
To switch boards, use:
pio run -e seeed_xiao_esp32s3 -t upload
Clock shows random numbers instead of time:
- WiFi connection failed or was lost
- Check WiFi credentials via the captive portal
- Wait for automatic reconnection (attempts every 60 seconds)
No display at all:
- Check power supply (5V with adequate current)
- Verify LED strip data pin connection (default: GPIO 5)
- Check LED strip ground connection
Dim display:
- If using BH1750 sensor, check sensor wiring
- Sensor may be reading low light levels
For even cooler clocks with Home Assistant integration, check out SolidDifference and the open source clock firmware it is based on. (disclaimer: I'm part of that collective βΊ)
The ESPHome version provides advanced features through Home Assistant integration:
Advanced Features:
- Full HA Integration: Native Home Assistant device with multiple entities
- Advanced Color Control: RGB color picker with HSV support
- Intelligent Brightness: BH1750 sensor with smoothing filter for automatic adjustment
- Day/Night Modes: Configurable brightness thresholds and targets
- Manual Override: Switch to disable automatic brightness adjustment
- Fade Effects: Smooth fade-in/fade-out when toggling the display
- Digital Dimming: Ultra-low brightness levels (1-3) for night use
- Real-time Monitoring: Live brightness and night mode status reporting
- OTA Updates: Over-the-air firmware updates via Home Assistant
- Home Assistant Automations: Color changes throughout the day via included scripts
- ESPHome (Add-on or standalone)
- Home Assistant with ESPHome integration
git clone <repository-url>
cd mini-clock-rgb
- Navigate to the
esphome
directory - Rename
secrets-example.yaml
tosecrets.yaml
- Edit
secrets.yaml
with your specific settings:- WiFi credentials
- Home Assistant API key
- OTA password
- Timezone (see comments in file)
Open esphome/rgb-clock.yaml
and review the substitutions:
section:
led_pin
: LED strip data pin (default: GPIO 5)i2c_sda_pin
: I2C SDA pin for BH1750 (default: GPIO 21)i2c_scl_pin
: I2C SCL pin for BH1750 (default: GPIO 22)bh1750_address
: I2C address of BH1750 sensor (default: 0x23)leds_per_segment
: LEDs per segment line (default: 3)
leds_per_segment
, update num_leds
using: num_leds = 4 Γ 7 Γ leds_per_segment
Using ESPHome (command line or HA Add-on):
esphome run esphome/rgb-clock.yaml
- First upload requires USB connection
- Subsequent updates use OTA
- Home Assistant should auto-discover the device
- Manual integration: Settings β Devices & Services β Add Integration β ESPHome
- Enter device name (
mini-clock-rgb
) or IP address
Once integrated, the clock exposes these entities:
π¨ Light Control:
light.clock_color
- RGB color picker and master brightness control- Color selection for clock digits
- ON/OFF triggers fade-in/fade-out effects
- Brightness slider scales ambient-adjusted brightness
π Brightness Management:
switch.night_mode_enabled
- Enable/disable automatic night modenumber.day_max_brightness
- Maximum brightness (1-255) for day modenumber.night_target_brightness
- Target brightness (1-255) for night modenumber.lux_night_threshold
- Ambient light threshold (lux) for night mode
π Monitoring:
sensor.ambient_light
- Current BH1750 sensor reading (filtered)sensor.clock_actual_brightness
- Final calculated LED brightness (0-255)binary_sensor.clock_night_mode_active
- Night mode status indicator
The repository includes example automations in the homeassistant/
directory:
clock_automation.yaml
- Changes clock color throughout the daycalculate_clock_color_script.yaml
- Script for color calculations based on time
To use these:
- Copy the files to your Home Assistant configuration directory
- Create a text helper entity for storing HSV values
- Restart Home Assistant to load the automations
- Security: Never commit
secrets.yaml
to public repositories - Brightness Logic: Final brightness combines ambient sensor, HA brightness slider, and day/night settings
- Digital Dimming: Very low brightness values (1-3) use special digital dimming for ultra-dim display
- Fade Effects: Toggling the light entity ON/OFF triggers smooth transitions
For even cooler clocks with Home Assistant integration, check out SolidDifference and the open source clock firmware it is based on. (disclaimer: I'm part of that collective βΊ)
This project is open source. Feel free to contribute improvements, bug fixes, or additional features via pull requests.