-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification_light_with_display.yaml
355 lines (330 loc) · 9.03 KB
/
notification_light_with_display.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
substitutions:
#id_code: "unique" # for differentiating multiple devices
devicename: notification-light-${id_code}
# General Parameters
refresh_interval: 10s
light_effect_interval: 16ms
mqtt_topic_prefix: esphome/notification-light # /${id_code}/notify/${color} for each color
# GPIO Pins
led_pin: GPIO32
spi_mosi_pin: GPIO23
spi_clk_pin: GPIO18
display_reset_pin: GPIO26
display_cs_pin: GPIO5
display_dc_pin: GPIO19
display_on_off_pin: GPIO16
# Color Parameters
num_colors: "6"
color_values: |-
{
Color(255,0,0,0), // red
Color(0,255,0,0), // green
Color(0,0,255,0), // blue
Color(255,255,0,0), // yellow
Color(0,255,255,0), // cyan
Color(255,0,255,0) // magenta
}
color_names: '{ "red", "green", "blue", "yellow", "cyan", "magenta" }'
empty_array: "{ 0,0,0,0,0,0 }"
# Display parameters
text_x: "40"
text_y: "180"
image_x: "45"
image_y: "20"
# Button Parameter
debug_duration: "60" # (in seconds)
packages:
wifi: !include fragments/common/wifi.config.yaml
device_base: !include fragments/common/device_base.config.yaml
external_components:
- source: github://pr#3625
components: [ gc9a01 ]
esphome:
platform: ESP32
board: nodemcu-32s
on_boot:
priority: -200
then:
- display.page.show: page_default
- light.turn_on:
id: notification_light
effect: "Notification Effect"
time:
- platform: sntp
id: sntp_time
globals:
- id: page_current
type: uint8_t
initial_value: "${num_colors}"
- id: page_next
type: uint8_t
initial_value: ${num_colors}
- id: colors
type: Color[${num_colors}]
initial_value: ${color_values}
- id: pending_notifications
type: time_t[${num_colors}]
initial_value: ${empty_array}
- id: notification_received
type: time_t[${num_colors}]
initial_value: ${empty_array}
#text_sensor:
# - <<: !include fragments/text_status.config.yaml
interval:
- interval: ${refresh_interval}
id: the_interval
then:
- script.execute: clean_overdue_notifications
- script.execute: scroll_next_page
# - component.update: txt_notifications
script:
- <<: !include fragments/script_clean_overdue.config.yaml
- id: scroll_next_page
mode: single
then:
- globals.set:
id: page_next
value: !lambda |-
uint8_t len = sizeof(id(colors)) / sizeof(Color*);
uint8_t current_page = id(page_current);
time_t current_timestamp = 0;
uint8_t start_offset = 0;
if (current_page < len) {
current_timestamp = id(pending_notifications)[current_page];
start_offset++; // if we are at default page, adding 0 to the index gets us to the next page
}
time_t next_timestamp = 0;
uint8_t next_page = current_page;
// iterate over all notification classes
// starting after the current one
for (uint8_t i = start_offset; i < len; i++) {
next_page = (current_page + i) % len;
next_timestamp = id(pending_notifications)[next_page];
// if the page has a timestamp:
// return page
if (next_timestamp > 0) {
return next_page;
}
}
// no other notification class has been found
// check if current class is inactive
if (current_timestamp == 0) {
// if no class is active, show default page
return len;
} else {
// if current class is still active, do nothing
return current_page;
}
return current_page;
- logger.log:
level: DEBUG
tag: "scrollnextpage"
format: "current_page=%d, next_page=%d"
args: [ "id(page_current)", "id(page_next)" ]
- display.page.show: page_default
- repeat:
count: !lambda "return id(page_next)+1;"
then:
- display.page.show_next: notification_display
- globals.set:
id: page_current
value: !lambda return id(page_next);
- component.update: notification_display
mqtt:
topic_prefix: ${mqtt_topic_prefix}/${id_code}
on_message:
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 0
color: red
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 0
color: red
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 1
color: green
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 1
color: green
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 2
color: blue
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 2
color: blue
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 3
color: yellow
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 3
color: yellow
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 4
color: cyan
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 4
color: cyan
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: ${id_code}
index: 5
color: magenta
- <<: !include
file: fragments/mqttsub.config.yaml
vars:
topic: "*"
index: 5
color: magenta
button:
- platform: template
name: "$devicename Cycle display page"
on_press:
- script.execute: scroll_next_page
- <<: !include
file: fragments/button.config.yaml
vars:
color: red
- <<: !include
file: fragments/button.config.yaml
vars:
color: green
- <<: !include
file: fragments/button.config.yaml
vars:
color: blue
- <<: !include
file: fragments/button.config.yaml
vars:
color: yellow
- <<: !include
file: fragments/button.config.yaml
vars:
color: cyan
- <<: !include
file: fragments/button.config.yaml
vars:
color: magenta
font:
- file: "gfonts://Roboto"
id: roboto_32
size: 32
- file: "gfonts://Roboto@900"
id: roboto_big
size: 100
image:
- file: "resources/doorbell.png"
id: img_doorbell
resize: 160x160
type: TRANSPARENT_BINARY
- file: "resources/washing_machine.png"
id: img_washing_machine
resize: 160x160
type: TRANSPARENT_BINARY
- file: "resources/dishwasher.png"
id: img_dishwasher
resize: 160x160
type: TRANSPARENT_BINARY
- file: "resources/lightbulb.png"
id: img_lightbulb
resize: 160x160
type: TRANSPARENT_BINARY
- file: "resources/open_window.png"
id: img_window
resize: 160x160
type: TRANSPARENT_BINARY
- file: "resources/3dprinter.png"
id: img_3dprinter
resize: 160x160
type: TRANSPARENT_BINARY
spi:
mosi_pin: ${spi_mosi_pin}
clk_pin: ${spi_clk_pin}
display:
- platform: gc9a01
id: notification_display
reset_pin: ${display_reset_pin}
cs_pin: ${display_cs_pin}
dc_pin: ${display_dc_pin}
rotation: 270
update_interval: 1h
pages:
- id: page_default
lambda: |-
auto time = id(sntp_time).now();
if (time.is_valid()) {
it.strftime(60,15, id(roboto_big), "%H", time);
it.strftime(60,105, id(roboto_big), "%M", time);
} else {
it.print(0,140, id(roboto_32), "not synced");
}
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 0
image: img_doorbell
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 1
image: img_washing_machine
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 2
image: img_dishwasher
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 3
image: img_window
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 4
image: img_lightbulb
- <<: !include
file: fragments/display_page.config.yaml
vars:
page_index: 5
image: img_3dprinter
switch:
- platform: gpio
pin: ${display_on_off_pin}
name: "$devicename Display on/off"
id: display_switch
restore_mode: ALWAYS_ON
light:
- <<: !include
file: fragments/light.config.yaml
vars:
pin: ${led_pin}