Last active 1719118046

using ESPHome

aly's Avatar aly revised this gist 1719118046. Go to revision

1 file changed, 69 insertions, 51 deletions

esp32-clock.yaml

@@ -1,51 +1,30 @@
1 + packages:
2 + esphome.esp_web_tools_example: github://esphome/firmware/esp-web-tools/esp32c3.yaml@v2
3 + esphome:
4 + name: clock
5 + name_add_mac_suffix: true
6 + logger:
7 + level: INFO
1 8 esp32:
2 9 board: esp32-c3-devkitm-1
3 10 variant: ESP32C3
11 + wifi:
12 + ssid: !secret wifi_ssid
13 + password: !secret wifi_password
14 + api:
15 + encryption:
16 + key: !secret encryption_key
4 17
5 - i2c:
6 - sda: GPIO6
7 - scl: GPIO7
8 - frequency: 800kHz
9 18
10 - binary_sensor:
11 - - platform: gpio
12 - pin: GPIO9
13 - id: boot
14 - filters:
15 - - delayed_on: 10ms
16 - on_release:
17 - then:
18 - - switch.toggle: clock_active
19 - internal: True
19 + uart:
20 + tx_pin: GPIO20
21 + rx_pin: GPIO21
22 + baud_rate: 9600
20 23
21 - time:
22 - - platform: sntp
23 - id: sntp_time
24 - on_time:
25 - - cron: '/2 * * * * *'
26 - then:
27 - - if:
28 - condition:
29 - - switch.is_on: clock_active
30 - then:
31 - - delay: 500ms
32 - - switch.turn_on: relay
33 -
34 - switch:
35 - - platform: template
36 - id: clock_active
37 - name: "Clock active"
38 - optimistic: True
39 - restore_mode: ALWAYS_OFF
40 -
41 - - platform: gpio
42 - name: "Relay"
43 - id: relay
44 - pin: GPIO0
45 - inverted: True
46 - on_turn_on:
47 - - delay: 1s
48 - - switch.turn_off: relay
24 + i2c:
25 + sda: GPIO8
26 + scl: GPIO9
27 + frequency: 800kHz
49 28
50 29 font:
51 30 - file: "gfonts://Roboto"
@@ -55,19 +34,58 @@ font:
55 34 id: roboto14
56 35 size: 14
57 36
37 +
38 + globals:
39 + - id: current_time
40 + type: esphome::ESPTime
41 + restore_value: no
42 +
43 + gps:
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 +
55 + time:
56 + - platform: sntp
57 + id: sntp_time
58 + - platform: gps
59 + id: gps_time
60 +
61 + script:
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 +
71 + interval:
72 + - interval: 0.5s
73 + then:
74 + - script.execute: check_time_source
75 +
58 76 display:
59 77 - platform: ssd1306_i2c
78 + id: oled
60 79 model: "SSD1306 128x32"
61 - flip_y: False
62 - flip_x: False
63 80 lambda: |-
64 - it.strftime(0, -5, id(roboto25), "%H:%M", id(sntp_time).now());
65 - it.strftime(64, -2, id(roboto14), "%S", id(sntp_time).now());
66 - it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", id(sntp_time).now());
67 - it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", id(sntp_time).now());
68 - it.draw_pixel_at(id(sntp_time).now().second+1, 30, COLOR_ON);
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);
69 89 it.line(0,27,61,27);
70 90 it.draw_pixel_at(0,28,COLOR_ON);
71 91 it.draw_pixel_at(61,28,COLOR_ON);
72 - # it.printf(it.get_width(), 0, id(roboto14), TextAlign::TOP_RIGHT, "%.2f°C", id(temp).state);
73 - # it.printf(0, 0, id(roboto14), "%.5f", id(temp).state);

aly's Avatar aly revised this gist 1716479705. Go to revision

1 file changed, 44 insertions, 18 deletions

esp32-clock.yaml

@@ -7,10 +7,16 @@ i2c:
7 7 scl: GPIO7
8 8 frequency: 800kHz
9 9
10 - font:
11 - - file: "gfonts://Roboto"
12 - id: roboto
13 - size: 12
10 + binary_sensor:
11 + - platform: gpio
12 + pin: GPIO9
13 + id: boot
14 + filters:
15 + - delayed_on: 10ms
16 + on_release:
17 + then:
18 + - switch.toggle: clock_active
19 + internal: True
14 20
15 21 time:
16 22 - platform: sntp
@@ -20,28 +26,48 @@ time:
20 26 then:
21 27 - if:
22 28 condition:
23 - switch.is_on: clock_active
29 + - switch.is_on: clock_active
24 30 then:
25 - - switch.turn_off: relay
26 -
27 - display:
28 - - platform: ssd1306_i2c
29 - model: "SSD1306 128x32"
30 - lambda: |-
31 - it.strftime(0, 0, id(roboto), "%Y-%m-%d", id(sntp_time).now());
32 - it.strftime(0, 16, id(roboto), "%H:%M %a", id(sntp_time).now());
31 + - delay: 500ms
32 + - switch.turn_on: relay
33 33
34 34 switch:
35 35 - platform: template
36 36 id: clock_active
37 37 name: "Clock active"
38 38 optimistic: True
39 - restore_mode: ALWAYS_ON
39 + restore_mode: ALWAYS_OFF
40 +
40 41 - platform: gpio
41 42 name: "Relay"
42 43 id: relay
43 - pin: GPIO3
44 - inverted: False
45 - on_turn_off:
44 + pin: GPIO0
45 + inverted: True
46 + on_turn_on:
46 47 - delay: 1s
47 - - switch.turn_on: relay
48 + - switch.turn_off: relay
49 +
50 + font:
51 + - file: "gfonts://Roboto"
52 + id: roboto25
53 + size: 25
54 + - file: "gfonts://Roboto"
55 + id: roboto14
56 + size: 14
57 +
58 + display:
59 + - platform: ssd1306_i2c
60 + model: "SSD1306 128x32"
61 + flip_y: False
62 + flip_x: False
63 + lambda: |-
64 + it.strftime(0, -5, id(roboto25), "%H:%M", id(sntp_time).now());
65 + it.strftime(64, -2, id(roboto14), "%S", id(sntp_time).now());
66 + it.strftime(it.get_width(), -2, id(roboto14), TextAlign::TOP_RIGHT, "%a", id(sntp_time).now());
67 + it.strftime(it.get_width(), 15, id(roboto14), TextAlign::TOP_RIGHT, "%b %d", id(sntp_time).now());
68 + it.draw_pixel_at(id(sntp_time).now().second+1, 30, COLOR_ON);
69 + it.line(0,27,61,27);
70 + it.draw_pixel_at(0,28,COLOR_ON);
71 + it.draw_pixel_at(61,28,COLOR_ON);
72 + # it.printf(it.get_width(), 0, id(roboto14), TextAlign::TOP_RIGHT, "%.2f°C", id(temp).state);
73 + # it.printf(0, 0, id(roboto14), "%.5f", id(temp).state);

aly's Avatar aly revised this gist 1716372333. Go to revision

1 file changed, 10 insertions, 1 deletion

esp32-clock.yaml

@@ -18,7 +18,11 @@ time:
18 18 on_time:
19 19 - cron: '/2 * * * * *'
20 20 then:
21 - - switch.turn_off: relay
21 + - if:
22 + condition:
23 + switch.is_on: clock_active
24 + then:
25 + - switch.turn_off: relay
22 26
23 27 display:
24 28 - platform: ssd1306_i2c
@@ -28,6 +32,11 @@ display:
28 32 it.strftime(0, 16, id(roboto), "%H:%M %a", id(sntp_time).now());
29 33
30 34 switch:
35 + - platform: template
36 + id: clock_active
37 + name: "Clock active"
38 + optimistic: True
39 + restore_mode: ALWAYS_ON
31 40 - platform: gpio
32 41 name: "Relay"
33 42 id: relay

aly's Avatar aly revised this gist 1716369537. Go to revision

No changes

aly's Avatar aly revised this gist 1716369503. Go to revision

1 file changed, 38 insertions

esp32-clock.yaml(file created)

@@ -0,0 +1,38 @@
1 + esp32:
2 + board: esp32-c3-devkitm-1
3 + variant: ESP32C3
4 +
5 + i2c:
6 + sda: GPIO6
7 + scl: GPIO7
8 + frequency: 800kHz
9 +
10 + font:
11 + - file: "gfonts://Roboto"
12 + id: roboto
13 + size: 12
14 +
15 + time:
16 + - platform: sntp
17 + id: sntp_time
18 + on_time:
19 + - cron: '/2 * * * * *'
20 + then:
21 + - switch.turn_off: relay
22 +
23 + display:
24 + - platform: ssd1306_i2c
25 + model: "SSD1306 128x32"
26 + lambda: |-
27 + it.strftime(0, 0, id(roboto), "%Y-%m-%d", id(sntp_time).now());
28 + it.strftime(0, 16, id(roboto), "%H:%M %a", id(sntp_time).now());
29 +
30 + switch:
31 + - platform: gpio
32 + name: "Relay"
33 + id: relay
34 + pin: GPIO3
35 + inverted: False
36 + on_turn_off:
37 + - delay: 1s
38 + - switch.turn_on: relay
Newer Older