Last active 1719118046

using ESPHome

esp32-clock.yaml Raw
1packages:
2 esphome.esp_web_tools_example: github://esphome/firmware/esp-web-tools/esp32c3.yaml@v2
3esphome:
4 name: clock
5 name_add_mac_suffix: true
6logger:
7 level: INFO
8esp32:
9 board: esp32-c3-devkitm-1
10 variant: ESP32C3
11wifi:
12 ssid: !secret wifi_ssid
13 password: !secret wifi_password
14api:
15 encryption:
16 key: !secret encryption_key
17
18
19uart:
20 tx_pin: GPIO20
21 rx_pin: GPIO21
22 baud_rate: 9600
23
24i2c:
25 sda: GPIO8
26 scl: GPIO9
27 frequency: 800kHz
28
29font:
30 - file: "gfonts://Roboto"
31 id: roboto25
32 size: 25
33 - file: "gfonts://Roboto"
34 id: roboto14
35 size: 14
36
37
38globals:
39 - id: current_time
40 type: esphome::ESPTime
41 restore_value: no
42
43gps:
44 latitude:
45 id: lat
46 longitude:
47 id: lon
48 altitude:
49 id: alt
50 satellites:
51 id: satellites
52 speed:
53 id: speed
54
55time:
56 - platform: sntp
57 id: sntp_time
58 - platform: gps
59 id: gps_time
60
61script:
62 - id: check_time_source
63 then:
64 - lambda: |-
65 if (id(sntp_time).now().is_valid()) {
66 id(current_time) = id(sntp_time).now();
67 } else if (id(gps_time).now().is_valid()) {
68 id(current_time) = id(gps_time).now();
69 }
70
71interval:
72 - interval: 0.5s
73 then:
74 - script.execute: check_time_source
75
76display:
77 - platform: ssd1306_i2c
78 id: oled
79 model: "SSD1306 128x32"
80 lambda: |-
81 auto now = id(current_time);
82 if (now.hour >= 18 || now.hour < 6) id(oled).set_contrast(.25);
83 else id(oled).set_contrast(1);
84 it.strftime(0, -5, id(roboto25), "%H:%M", now);
85 it.strftime(64, -2, id(roboto14), "%S", now);
86 it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", now);
87 it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", now);
88 it.draw_pixel_at(now.second+1, 30, COLOR_ON);
89 it.line(0,27,61,27);
90 it.draw_pixel_at(0,28,COLOR_ON);
91 it.draw_pixel_at(61,28,COLOR_ON);
92