-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhass-screen-01.yaml
281 lines (252 loc) · 8.85 KB
/
hass-screen-01.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
substitutions:
name: hass-screen-01
friendly_name: Screen 01
comment: Adafruit HUZZAH32 – Sonos Screen Stua
board: featheresp32
packages:
common: !include packages/common-32.yaml
status_led:
pin:
number: LED
globals:
- id: media_artist_x
type: int
initial_value: '-1'
- id: media_artist_w
type: int
initial_value: '-1'
- id: media_title_x
type: int
initial_value: '-1'
- id: media_title_w
type: int
initial_value: '-1'
- id: media_album_x
type: int
initial_value: '-1'
- id: media_album_w
type: int
initial_value: '-1'
- id: media_channel_x
type: int
initial_value: '-1'
- id: media_channel_w
type: int
initial_value: '-1'
external_components:
- source: github://jenscski/esphome-components@main
components: [ sh1107_base, sh1107_i2c ]
i2c:
frequency: 800kHz
scan: false
display:
- platform: sh1107_i2c
model: SH1107 64X128
id: my_display
rotation: 90
contrast: 1%
update_interval: 150ms
pages:
- id: p_idle
lambda: |-
const int padding = 1500 / id(my_display).get_update_interval();
const char* tag = "${name}";
if(!id(system_status).state)
{
it.print(128/2, 64/2, id(f_mdi_64), TextAlign::CENTER, "\U000F0C5F");
}
else
{
if(!id(media_playing).state)
{
it.strftime(128/2, (64 - 14)/2, id(f_clock), COLOR_ON, TextAlign::CENTER, "%H:%M", id(hass_time).now());
if(!id(media_channel).state.empty())
it.print(0, 64, id(f_media), TextAlign::BOTTOM_LEFT, id(media_channel).state.c_str());
else if(!id(media_artist).state.empty())
it.print(0, 64, id(f_media), TextAlign::BOTTOM_LEFT, id(media_artist).state.c_str());
}
else
{
if(id(media_channel_w) < 0)
{
int x1, y1, width, height;
it.get_text_bounds(0, 0, id(media_channel).state.c_str(), id(f_media), TextAlign::CENTER, &x1, &y1, &width, &height);
id(media_channel_x) = padding;
id(media_channel_w) = width;
}
else if(id(media_channel_w) > 128 && (id(media_channel_w) - 128) + id(media_channel_x) < -padding)
{
id(media_channel_x) = padding;
}
else if(id(media_channel_w) > 128)
{
id(media_channel_x) --;
}
if(id(media_artist_w) < 0)
{
int x1, y1, width, height;
it.get_text_bounds(0, 0, id(media_artist).state.c_str(), id(f_media), TextAlign::CENTER, &x1, &y1, &width, &height);
id(media_artist_x) = padding;
id(media_artist_w) = width;
}
else if(id(media_artist_w) > 128 && (id(media_artist_w) - 128) + id(media_artist_x) < -padding)
{
id(media_artist_x) = padding;
}
else if(id(media_artist_w) > 128)
{
id(media_artist_x) --;
}
if(id(media_title_w) < 0)
{
int x1, y1, width, height;
it.get_text_bounds(0, 0, id(media_title).state.c_str(), id(f_media), TextAlign::CENTER, &x1, &y1, &width, &height);
id(media_title_x) = padding;
id(media_title_w) = width;
}
else if(id(media_title_w) > 128 && (id(media_title_w) - 128) + id(media_title_x) < -padding)
{
id(media_title_x) = padding;
}
else if(id(media_title_w) > 128)
{
id(media_title_x) --;
}
if(id(media_album_w) < 0)
{
int x1, y1, width, height;
it.get_text_bounds(0, 0, id(media_album).state.c_str(), id(f_media), TextAlign::CENTER, &x1, &y1, &width, &height);
id(media_album_x) = padding;
id(media_album_w) = width;
}
else if(id(media_album_w) > 128 && (id(media_album_w) - 128) + id(media_album_x) < -padding)
{
id(media_album_x) = padding;
}
else if(id(media_album_w) > 128)
{
id(media_album_x) --;
}
if(id(media_album_w) < 0)
{
int x1, y1, width, height;
it.get_text_bounds(0, 0, id(media_album).state.c_str(), id(f_media), TextAlign::CENTER, &x1, &y1, &width, &height);
id(media_album_x) = 0;
id(media_album_w) = width;
}
auto xpos = [](int x, int w)
{
if(w <= 128)
return 0;
int ret = x;
ret = min(ret, 0);
ret = max(ret, 128 - w);
return ret;
};
int pos = 0;
if(!id(media_channel).state.empty())
it.print(xpos(id(media_channel_x), id(media_channel_w)), 16 * pos++, id(f_media), id(media_channel).state.c_str());
if(!id(media_artist).state.empty())
it.print(xpos(id(media_artist_x), id(media_artist_w)), 16 * pos++, id(f_media), id(media_artist).state.c_str());
if(!id(media_title).state.empty())
it.print(xpos(id(media_title_x), id(media_title_w)), 16 * pos++, id(f_media), id(media_title).state.c_str());
if(!id(media_album).state.empty())
it.print(xpos(id(media_album_x), id(media_album_w)), 16 * pos++, id(f_media), id(media_album).state.c_str());
it.strftime(0, 64, id(f_clock_small), COLOR_ON, TextAlign::BOTTOM_LEFT, "%H:%M", id(hass_time).now());
}
// volume footer
int w = 35;
int h = 14;
it.filled_rectangle(128 - w, 64 - h, w, h, COLOR_OFF);
it.printf(128 - 13, 64, id(f_clock_small), TextAlign::BOTTOM_RIGHT, "%d", (int)id(media_volume).state);
it.print(128, 64, id(f_mdi_12), TextAlign::BOTTOM_RIGHT, id(media_muted).state ? "\U000F0581" : "\U000F057E");
//it.line(0, 64 - 15, 128, 64 - 15);
}
# https://maximilian.schalch.de/2018/05/complete-list-of-european-special-characters/
font:
- file: gfonts://Ubuntu@Regular
size: 14
id: f_media
glyphs: '÷!''&«»?#"%’^´()+•=,-_.:/°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz¡¿·ÄäÀàÁáÂâÃãÅåǍǎĄąĂăÆæĀāÇçĆćĈĉČčĎđĐďðÈèÉéÊêËëĚěĘęĖėĒēĜĝĢģĞğĤĥÌìÍíÎîÏïıĪīĮįĴĵĶķĹĺĻļŁłĽľĿŀÑñŃńŇňŅņÖöÒòÓóÔôÕõŐőØøŒœŔŕŘřẞߌśŜŝŞşŠšȘșŤťŢţÞþȚțÜüÙùÚúÛûŰűŨũŲųŮůŪūŴŵÝýŸÿŶŷŹźŽžŻż'
- file: gfonts://Azeret Mono@Medium
id: f_clock
size: 32
glyphs: '0123456789:'
- file: gfonts://Azeret Mono@Light
id: f_clock_small
size: 12
glyphs: '0123456789:'
- file: fonts/materialdesignicons-webfont.ttf
size: 12
id: f_mdi_12
glyphs:
- "\U000F057E" # mdi-volume-high
- "\U000F0581" # mdi-volume-off
- file: fonts/materialdesignicons-webfont.ttf
size: 64
id: f_mdi_64
glyphs:
- "\U000F0C5F" # mdi-close-network-outline
text_sensor:
- platform: homeassistant
id: media_artist
entity_id: sensor.media_artist_stua
internal: true
on_value:
then:
- globals.set:
id: media_artist_x
value: '-1'
- globals.set:
id: media_artist_w
value: '-1'
- platform: homeassistant
id: media_channel
entity_id: sensor.media_channel_stua
internal: true
on_value:
then:
- globals.set:
id: media_channel_x
value: '-1'
- globals.set:
id: media_channel_w
value: '-1'
- platform: homeassistant
id: media_title
entity_id: sensor.media_title_stua
internal: true
on_value:
then:
- globals.set:
id: media_title_x
value: '-1'
- globals.set:
id: media_title_w
value: '-1'
- platform: homeassistant
id: media_album
entity_id: sensor.media_album_stua
internal: true
on_value:
then:
- globals.set:
id: media_album_x
value: '-1'
- globals.set:
id: media_album_w
value: '-1'
sensor:
- platform: homeassistant
id: media_volume
entity_id: sensor.media_volume_stua
internal: true
binary_sensor:
- platform: homeassistant
id: media_playing
entity_id: sensor.media_playing_stua
internal: true
- platform: homeassistant
id: media_muted
entity_id: sensor.media_muted_stua
internal: true