-
Notifications
You must be signed in to change notification settings - Fork 0
/
epaper47.yaml
340 lines (300 loc) · 11.4 KB
/
epaper47.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
# Lilygo T5 4.7 inch epaper display: Clock, calendar and current weather
# Weather icon help from https://community.home-assistant.io/t/display-materialdesign-icons-on-esphome-attached-to-screen/199790/16
esphome:
name: epaper47
includes:
- weather_icon_map.h
esp32:
board: esp32dev
framework:
type: arduino
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
use_address: 10.0.0.106
ap:
password: !secret fallback_password
captive_portal:
mqtt:
broker: !secret mqtt_broker
port: !secret mqtt_port
username: !secret mqtt_username
password: !secret mqtt_password
discovery: false
on_message:
- topic: epaper/atwork
then:
- display.page.show: !lambda |-
int atwork = atoi(x.c_str());
switch(atwork) {
case 0:
return id(standby);
case 1:
return id(home);
case 2:
return id(black);
case 3:
return id(blank);
default:
return id(standby);
}
logger:
ota:
time:
- platform: sntp
id: tm
timezone: "Europe/Stockholm"
on_time:
- seconds: 0
minutes: /1
then:
- component.update: epaper
on_time_sync:
- then:
- component.update: epaper # TODO comment out once working
font:
- file: "gfonts://Roboto"
id: font_std
size: 30
glyphs: "!\"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/\\[]|&@#'’åäéöøú"
- file: "gfonts://Roboto@700"
id: font_media_title
size: 30
glyphs: "!\"%()+=,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/\\[]|&@#'’åäéöøú"
- file: "gfonts://Roboto"
id: font_clock
size: 150
glyphs: "-0123456789:° "
- file: fonts/FLIPclockblack.ttf
id: flipclock
size: 350
glyphs: "0123456789:"
- file: fonts/lcd.ttf
id: lcd
size: 350
glyphs: "0123456789:"
- file: "gfonts://Noto Sans Mono"
id: font_symbol
size: 30
glyphs: "-.0123456789° ▲▼▁▂▃▄▅▆▇█▓"
- file: fonts/materialdesignicons-webfont.ttf
id: mdi_calendar
size: 30
glyphs:
- "\U000F00ED" # calendar
- file: fonts/materialdesignicons-webfont.ttf
id: mdi_weather
size: 150
glyphs:
- "\U000F0590" # weather-cloudy
- "\U000F0F2F" # weather-cloudy-alert
- "\U000F0E6E" # weather-cloudy-arrow-right
- "\U000F0591" # weather-fog
- "\U000F0592" # weather-hail
- "\U000F0F30" # weather-hazy
- "\U000F0898" # weather-hurricane
- "\U000F0593" # weather-lightning
- "\U000F067E" # weather-lightning-rainy
- "\U000F0594" # weather-night
- "\U000F0F31" # weather-night-partly-cloudy
- "\U000F0595" # weather-partly-cloudy
- "\U000F0F32" # weather-partly-lightning
- "\U000F0F33" # weather-partly-rainy
- "\U000F0F34" # weather-partly-snowy
- "\U000F0F35" # weather-partly-snowy-rainy
- "\U000F0596" # weather-pouring
- "\U000F0597" # weather-rainy
- "\U000F0598" # weather-snowy
- "\U000F0F36" # weather-snowy-heavy
- "\U000F067F" # weather-snowy-rainy
- "\U000F0599" # weather-sunny
- "\U000F0F37" # weather-sunny-alert
- "\U000F14E4" # weather-sunny-off
- "\U000F059A" # weather-sunset
- "\U000F059B" # weather-sunset-down
- "\U000F059C" # weather-sunset-up
- "\U000F0F38" # weather-tornado
- "\U000F059D" # weather-windy
- "\U000F059E" # weather-windy-variant
- "\U000F04C7" # spotify
external_components:
- source: github://ashald/esphome@lilygo-t5-47 #github://guillempages/esphome@patch-2
components:
- lilygo_t5_47
- source: github://pr#3255
components:
- display
- online_image
online_image:
- url: !secret album_art_url
id: album_image
display:
- platform: lilygo_t5_47
rotation: 180°
update_interval: 10s
full_update_every: 60
id: epaper
pages:
- id: blank
lambda: |-
#define xres 960
#define yres 540
it.rectangle(0, 0, xres, yres);
- id: black
lambda: |-
#define xres 960
#define yres 540
it.filled_rectangle(0, 0, xres, yres);
- id: standby
lambda: |-
#define xres 960
#define yres 540
//it.strftime(xres/2, yres/2+25, id(lcd), TextAlign::CENTER, "%H:%M", id(tm).now());
it.strftime(rand() % xres, rand() % yres, id(font_clock), TextAlign::CENTER, "%H:%M", id(tm).now());
- id: home
lambda: |-
#define xres 960
#define yres 540
// Quadrants
it.line(xres/2, 0, xres/2, yres);
it.line(0, yres/2, xres, yres/2);
// Date and time
it.strftime(xres/4, yres/8, id(font_std), TextAlign::BOTTOM_CENTER, "%a, %e %b", id(tm).now());
it.strftime(xres/4, yres/4, id(font_clock), TextAlign::CENTER, "%H:%M", id(tm).now());
// Calendar
#define xpad 20
#define xcalendar (xres*6/12 + xpad)
#define ylinespace 50
//it.print(xres*3/4, yres/8, id(mdi_calendar), TextAlign::BOTTOM_CENTER, "\U000F00ED");
it.print(xres*3/4, yres/8, id(font_std), TextAlign::BOTTOM_CENTER, "Up next");
int y = yres/4 - ylinespace;
it.print(xcalendar, y, id(font_std), TextAlign::CENTER_LEFT, "10:00 Stand-up");
y += ylinespace;
it.print(xcalendar, y, id(font_std), TextAlign::CENTER_LEFT, "10:20 Planning");
y += ylinespace;
it.print(xcalendar, y, id(font_std), TextAlign::CENTER_LEFT, "11:30 Dale / Manuel 1on1");
// Weather
#define xweather xres*1/8
#define xtemp xres*3/8
// Rain sparkline
y = yres*5/8;
if (id(rainsparkline).has_state() && strcmp(id(rainsparkline).state.c_str(), "▁▁▁▁▁▁▁▁")) {
it.printf(xweather, y, id(font_symbol), TextAlign::BOTTOM_CENTER, "%s", id(rainsparkline).state.c_str());
} else {
it.print(xweather, y, id(font_symbol), TextAlign::BOTTOM_CENTER, " ");
}
// Weather icon and current temperature
y = yres*6/8;
if (id(weather).has_state()) {
it.print(xweather, y, id(mdi_weather), TextAlign::CENTER, weather_icon_map[id(weather).state.c_str()].c_str());
} else {
it.print(xweather, y, id(mdi_weather), TextAlign::CENTER, "\U000F0597");
}
if (id(temperature).has_state()) {
it.printf(xtemp, y, id(font_clock), TextAlign::CENTER, "%.0f°", id(temperature).state);
} else {
it.print(xtemp, y, id(font_clock), TextAlign::CENTER, "-0°");
}
// Rainfall next hour, min/max temp
y = yres*7/8;
if (id(rainfall).has_state() && id(rainfall).state > 0) {
it.printf(xweather, y, id(font_std), TextAlign::TOP_CENTER, "%.1f mm", id(rainfall).state);
} else {
it.print(xweather, y, id(font_std), TextAlign::TOP_CENTER, " ");
}
if (id(tempmin).has_state() && id(tempmax).has_state()) {
it.printf(xtemp-35, y, id(font_symbol), TextAlign::TOP_CENTER, "▲%.0f°▼%.0f°", id(tempmin).state, id(tempmax).state);
}
// Spotify
#define xtitle xcalendar
#define ytitle yres*5/8
#define xprogress_left (xres/2 + xpad)
#define xprogress_right (xres - xpad)
#define yprogress yres*7/8
#define ypad 5
#define ytime (yprogress + ypad)
#define progress_width (xprogress_right - xprogress_left)
#define imgsize 160
#define imgpad xpad
#define ximg (xres - imgsize - imgpad)
#define yimg (yres/2 + imgpad)
#define title_length 19
//ESP_LOGD("progress_bar", "xprogress_left %i, _right %i, progress_width %i", xprogress_left, xprogress_right, progress_width);
if (id(media_state).has_state() && strcmp(id(media_state).state.c_str(), "playing") == 0) {
it.image(ximg, yimg, id(album_image), COLOR_OFF, COLOR_ON);
it.rectangle(ximg, yimg, imgsize, imgsize);
if (id(media_title).has_state() && id(media_artist).has_state()) {
it.printf(xtitle, ytitle, id(font_media_title), TextAlign::BOTTOM_LEFT, "%s", id(media_title).state.substr(0, title_length).c_str());
it.printf(xtitle, ytitle, id(font_std), TextAlign::TOP_LEFT, "%s", id(media_artist).state.substr(0, title_length).c_str());
}
// Progress bar
if (id(media_duration).has_state() && id(media_start).has_state()) {
double t_now = id(tm).now().timestamp; // Unix time now
double t_start = id(media_start).state + 1.6e9; // Unix time that track started, bug in mqtt that loses precision on large numbers
int t_elapsed = int(t_now - t_start); // seconds into the track
int t_remain = int((t_elapsed - id(media_duration).state) * -1);
//ESP_LOGD("progress_bar", "t_now %f, t_start %f, t_elapsed %i, t_remain %i, media_duration %f", t_now, t_start, t_elapsed, t_remain, id(media_duration).state);
if (t_remain >= 0) {
// Elapsed and remaining time
it.printf(xprogress_left, ytime, id(font_std), TextAlign::TOP_LEFT, "%i:%02i", t_elapsed/60, t_elapsed%60);
it.printf(xprogress_right, ytime, id(font_std), TextAlign::TOP_RIGHT, "-%i:%02i", t_remain/60, t_remain%60);
double progress_elapsed = double(progress_width) * double(t_elapsed) / double(id(media_duration).state);
it.filled_rectangle(xprogress_left, yprogress-1, progress_width, 3); // full-time bar
it.filled_rectangle(xprogress_left, yprogress-3, progress_elapsed, 6); // elapsed bad
it.filled_circle(xprogress_left+progress_elapsed, yprogress, 8);
//ESP_LOGD("progress_bar", "progress_width %i, progress_elapsed %f", progress_width, progress_elapsed);
}
}
} else {
it.print(xres*3/4, yres*5/8, id(font_std), TextAlign::BOTTOM_CENTER, "Play something unexpected");
it.print(xres*3/4, yres*6/8, id(mdi_weather), TextAlign::CENTER, "\U000F04C7");
}
sensor:
- platform: mqtt_subscribe
topic: epaper/wx/temp
id: temperature
- platform: mqtt_subscribe
topic: epaper/wx/min
id: tempmin
- platform: mqtt_subscribe
topic: epaper/wx/max
id: tempmax
- platform: mqtt_subscribe
topic: epaper/wx/rain
id: rainfall
- platform: mqtt_subscribe
topic: epaper/spotify/duration
id: media_duration
- platform: mqtt_subscribe
topic: epaper/spotify/start
id: media_start
text_sensor:
- platform: mqtt_subscribe
topic: epaper/wx/icon
id: weather
- platform: mqtt_subscribe
topic: epaper/wx/rainsparkline
id: rainsparkline
- platform: mqtt_subscribe
id: next_event
topic: epaper/nextevent
- platform: mqtt_subscribe
topic: epaper/spotify/state
id: media_state
- platform: mqtt_subscribe
topic: epaper/spotify/artist
id: media_artist
- platform: mqtt_subscribe
topic: epaper/spotify/title
id: media_title
binary_sensor:
- platform: gpio
id: push_button
pin:
number: GPIO39
inverted: true
filters:
- delayed_off: 50ms
on_press:
then:
- component.update: epaper