packages: esphome.esp_web_tools_example: github://esphome/firmware/esp-web-tools/esp32c3.yaml@v2 esphome: name: clock name_add_mac_suffix: true logger: level: INFO esp32: board: esp32-c3-devkitm-1 variant: ESP32C3 wifi: ssid: !secret wifi_ssid password: !secret wifi_password api: encryption: key: !secret encryption_key uart: tx_pin: GPIO20 rx_pin: GPIO21 baud_rate: 9600 i2c: sda: GPIO8 scl: GPIO9 frequency: 800kHz font: - file: "gfonts://Roboto" id: roboto25 size: 25 - file: "gfonts://Roboto" id: roboto14 size: 14 globals: - id: current_time type: esphome::ESPTime restore_value: no gps: latitude: id: lat longitude: id: lon altitude: id: alt satellites: id: satellites speed: id: speed time: - platform: sntp id: sntp_time - platform: gps id: gps_time script: - id: check_time_source then: - lambda: |- if (id(sntp_time).now().is_valid()) { id(current_time) = id(sntp_time).now(); } else if (id(gps_time).now().is_valid()) { id(current_time) = id(gps_time).now(); } interval: - interval: 0.5s then: - script.execute: check_time_source display: - platform: ssd1306_i2c id: oled model: "SSD1306 128x32" lambda: |- auto now = id(current_time); if (now.hour >= 18 || now.hour < 6) id(oled).set_contrast(.25); else id(oled).set_contrast(1); it.strftime(0, -5, id(roboto25), "%H:%M", now); it.strftime(64, -2, id(roboto14), "%S", now); it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", now); it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", now); it.draw_pixel_at(now.second+1, 30, COLOR_ON); it.line(0,27,61,27); it.draw_pixel_at(0,28,COLOR_ON); it.draw_pixel_at(61,28,COLOR_ON);