-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp32-clock-template.yaml
197 lines (172 loc) · 4.55 KB
/
esp32-clock-template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
esphome:
name: esphome-clock
friendly_name: ESPHome Clock
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
logs:
sensor: INFO
# Enable Home Assistant API
api:
reboot_timeout: 0s
encryption:
key: ""
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "ESP32Clock"
password: "fallBackPass"
captive_portal:
web_server:
local: true
external_components:
- source:
type: local
path: components
time:
- platform: sntp
id: sntp_time
timezone: Europe/Berlin
spi:
- id: quad_spi_bus
interface: spi3
clk_pin: 18
data_pins:
- 23
- 19
- 22
- 21
sensor:
- platform: uptime
id: runtime
update_interval: 100ms
globals:
- id: countdown_end
type: time_t
- id: uptime_start
type: time_t
number:
- platform: template
name: "Countdown set H"
id: cd_set_h
initial_value: 0
min_value: 0
max_value: 99
step: 1
optimistic: true
mode: box
- platform: template
name: "Countdown set M"
id: cd_set_m
initial_value: 0
min_value: 0
max_value: 59
step: 1
optimistic: true
mode: box
- platform: template
name: "Countdown set S"
id: cd_set_s
initial_value: 0
min_value: 0
max_value: 59
step: 1
optimistic: true
mode: box
button:
- platform: template
name: "Countdown set"
on_press:
- lambda: |-
id(countdown_end) =
id(sntp_time).timestamp_now()
+ uint32_t(id(cd_set_h).state)*3600
+ uint32_t(id(cd_set_m).state)*60
+ uint32_t(id(cd_set_s).state);
- platform: template
name: "Countdown Minutes 1m"
on_press:
- lambda: |-
id(countdown_end) = id(sntp_time).timestamp_now() + 60;
- platform: template
name: "Countdown Minutes 5m"
on_press:
- lambda: |-
id(countdown_end) = id(sntp_time).timestamp_now() + 300;
- platform: template
name: "Countdown Minutes 10m"
on_press:
- lambda: |-
id(countdown_end) = id(sntp_time).timestamp_now() + 600;
- platform: template
name: "Countdown Hours 1h"
on_press:
- lambda: |-
id(countdown_end) = id(sntp_time).timestamp_now() + 3600;
- platform: template
name: "Countdown Hours 2h"
on_press:
- lambda: |-
id(countdown_end) = id(sntp_time).timestamp_now() + 7200;
- platform: template
name: "Runtime Reset"
on_press:
- lambda: |-
id(uptime_start) = id(runtime).state;
display:
- platform: qspi_74hc595_4x_display
cs_pin: GPIO5
data_rate: 10MHz
update_interval: 10ms
spi_id: quad_spi_bus
lambda: |-
static uint32_t last_micros=0;
static uint32_t clock_frames=0;
static uint32_t old_clock=0;
if(id(sntp_time).now().second!=old_clock){
last_micros = micros();
old_clock=id(sntp_time).now().second;
} else {
clock_frames = (micros()-last_micros)/10000;
}
/////////// first display
it.printf(0, ".*`,_+'-");
/////////// second display
it.strftime(8, "%H%M%S", id(sntp_time).now());
it.printf(14, "%02d", clock_frames%100);
/////////// third display
{
double delta = id(runtime).state - id(uptime_start);
uint32_t hours = delta/3600;
delta -= hours*3600;
uint32_t minutes = delta/60;
delta -= minutes*60;
uint32_t seconds = delta;
uint32_t frames = (100*delta) - (100*seconds);
it.printf(16, "%02d%02d%02d%02d", hours, minutes, seconds, frames);
}
/////////// fourth display
if (id(countdown_end) > id(sntp_time).timestamp_now()) {
time_t delta=difftime(id(countdown_end), id(sntp_time).timestamp_now());
time_t hours = delta/3600;
delta -= hours*3600;
time_t minutes = (delta)/60;
delta -= minutes*60;
time_t seconds = delta;
it.printf(24, "%02ld%02ld%02ld%02d", hours, minutes, seconds, (99-clock_frames%100));
}
# the first display should display a test string to figure out the digit and segment map:
# digit 0: >.< character (dot segment on)
# digit 1: >*< character (A upper segment on)
# digit 2: >`< character (B upper right segment on)
# digit 3: >,< character (C lower right segment on)
# digit 4: >_< character (D lower segment on)
# digit 5: >+< character (E lower left segment on)
# digit 6: >'< character (F upper left segment on)
# digit 7: >-< character (G middle segment on)