This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathUlanziTC001_night_mode.yaml
399 lines (376 loc) · 9.76 KB
/
UlanziTC001_night_mode.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
substitutions:
name: "ulanzi"
room: "MyRoom"
friendly_name: "Ulanzi TC001"
matrix_pin: GPIO32
buzzer_pin: GPIO15
battery_pin: GPIO34
ldr_pin: GPIO35
left_button_pin: GPIO26
mid_button_pin: GPIO27
right_button_pin: GPIO14
scl_pin: GPIO22
sda_pin: GPIO21
external_components:
- source:
type: git
url: https://github.com/lubeda/EsphoMaTrix
refresh: 60s
components: [ ehmtx ]
esphome:
comment: "Ulanzi TC001"
name: $name
friendly_name: $friendly_name
on_boot:
then:
- ds1307.read_time:
esp32:
board: esp32dev
# WiFi connection
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ap_${name}
password: !secret ap_password
ap_timeout: 1min
# Unavailable for esp-idf https://github.com/esphome/feature-requests/issues/1649
captive_portal:
# Enable logging
logger:
# Enable over-the-air updates
ota:
password: !secret ota_password
id: my_ota
# Unavailable for esp-idf https://github.com/esphome/feature-requests/issues/1649
# Enable Web server
web_server:
port: 80
auth:
username: admin
password: !secret web_server_password
font:
# adapt the filename to your local settings
- file: Calcium.ttf
id: ehmtx_font
size: 16
glyphs: |
!?"%‰()+*=,-_.:°µ²³0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnÖÄÜöäüopqrstuvwxyz€$@<>/
globals:
# aab = auto-adjustable brightness
- id: aab_enable
type: "bool"
restore_value: true
initial_value: "true"
- id: aab_add
type: int
initial_value: '10'
- id: aab_max
type: int
initial_value: '220'
- id: aab_min
type: int
initial_value: '40'
- id: night_enable
type: "bool"
restore_value: true
initial_value: "false"
ehmtx:
id: rgb8x32
time_component: ehmtx_time
matrix_component: ehmtx_display
clock_time: 8 # duration to display the clock after this time the date is display until next "show_screen"
clock_interval: 20 # show the clock at least each x seconds
screen_time: 15 # duration to display a screen or a clock/date sequence
date_format: "%d.%m" # defaults "%d.%m." (use "%m.%d." for the US)
time_format: "%H:%M" # defaults "%H:%M" (use "%I:%M%p" for the US)
show_dow: false # draw the day indicator on the bottom of the screen, defaults to true
show_date: true # show the date for show_screen - show_clock seconds otherwise only shows the clock for show_screen seconds, defaults to true
week_start_monday: true # default monday is first day of week, false = sunday
yoffset: 8 # the text is aligned BASELINE_LEFT, the baseline defaults to 6
xoffset: 1 # the text is aligned BASELINE_LEFT, the left defaults to 1
scroll_interval: 80 # the interval in ms to scroll the text (default=80), should be a multiple of the update_interval from the display (default: 16ms)
frame_interval: 192 # the interval in ms to display the next anim frame (default=192), should be a multiple of the update_interval from the display (default: 16ms)
font_id: ehmtx_font
icons:
- id: ha
lameid: 7956
- id: tempc
lameid: 2422
- id: plug
lameid: 403
- id: humidity
lameid: 51764
- id: co2
lameid: 30662
- id: weather_clear_night
lameid: 53383
- id: weather_cloudy
lameid: 53384
- id: weather_fog
lameid: 12196
- id: weather_hail
lameid: 53385
- id: weather_lightning
lameid: 50231
- id: weather_lightning_rainy
lameid: 49299
- id: weather_partlycloudy
lameid: 53802
- id: weather_pouring
lameid: 49300
- id: weather_rainy
lameid: 2284
- id: weather_snowy
lameid: 2289
- id: weather_snowy_rainy
lameid: 49301
- id: weather_sunny
lameid: 1246
- id: weather_windy
lameid: 17076
- id: weather_windy_variant
lameid: 15618
- id: weather_exceptional
lameid: 5464
- id: washing_machine_ready
lameid: 26673
- id: dryer_ready
lameid: 48497
- id: dishwasher_ready
lameid: 47488
- id: door_ringing
lameid: 24800
- id: fire
lameid: 24873
# on_next_clock:
# lambda: |-
# id(rgb8x32)->set_clock_color(235, 0, 0);
# id(rgb8x32)->set_brightness(30);
binary_sensor:
- platform: status
name: "Status"
- platform: gpio
pin:
number: $left_button_pin
inverted: true
name: "Left button"
on_press:
then:
- number.decrement: screen_brightness
- platform: gpio
pin:
inverted: true
number: $mid_button_pin
mode: INPUT_PULLUP
name: "Middle button"
on_press:
then:
- switch.toggle: displaycontrol
- platform: gpio
pin:
number: $right_button_pin
inverted: true
name: "Right button"
on_press:
then:
- number.increment: screen_brightness
# example to switch to next screen
# lambda: |-
# id(rgb8x32)->skip_screen();
# Enable Home Assistant API
api:
encryption:
key: !secret api_password
services:
- service: alarm
variables:
icon_name: string
text: string
then:
lambda: |-
if (!id(night_enable)) {
id(rgb8x32)->add_screen(icon_name,text,7,20,true);
id(rgb8x32)->force_screen(icon_name);
}
- service: add_screen_respect_night_mode
variables:
icon_name: string
text: string
lifetime: int
screen_time: int
alarm: bool
then:
lambda: |-
if (!id(night_enable)) {
id(rgb8x32)->add_screen(icon_name,text,lifetime,screen_time,alarm);
}
- service: brightness
variables:
brightness: int
then:
lambda: |-
id(rgb8x32)->set_brightness(brightness);
- service: icons
then:
lambda: |-
id(rgb8x32)->show_all_icons();
- service: skip_screen
then:
lambda: |-
id(rgb8x32)->skip_screen();
- service: tuneplay
variables:
tune: string
then:
- rtttl.play:
rtttl: !lambda 'return tune;'
number:
- platform: template
name: "Brightness"
id: screen_brightness
min_value: 0
max_value: 255
update_interval: 1s
step: 1
lambda: |-
return id(rgb8x32)->get_brightness();
set_action:
lambda: |-
id(rgb8x32)->set_brightness(x);
switch:
- platform: template
name: "Display"
id: displaycontrol
icon: "mdi:power"
restore_mode: ALWAYS_ON
lambda: |-
return id(rgb8x32)->show_display;
turn_on_action:
lambda: |-
id(rgb8x32)->set_display_on();
turn_off_action:
lambda: |-
id(rgb8x32)->set_display_off();
- platform: template
name: "Auto-Adjust Brightness"
id: switch_autobrightness
icon: mdi:brightness-auto
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
if (id(aab_enable)) {
return true;
} else {
return false;
}
turn_on_action:
lambda: |-
id(aab_enable) = true;
turn_off_action:
lambda: |-
id(aab_enable) = false;
- platform: template
name: "Night mode"
id: switch_night_mode
icon: mdi:sleep
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
if (id(night_enable)) {
return true;
} else {
return false;
}
turn_on_action:
lambda: |-
id(night_enable) = true;
id(rgb8x32)->del_screen("*");
id(rgb8x32)->set_show_date(false);
id(rgb8x32)->set_brightness(30);
id(rgb8x32)->set_clock_color(235, 0, 0);
turn_off_action:
lambda: |-
id(night_enable) = false;
id(rgb8x32)->set_show_date(true);
id(rgb8x32)->set_clock_color(255, 255, 255);
sensor:
- platform: sht3xd
temperature:
name: "Temperature"
humidity:
name: "Humidity"
update_interval: 60s
- platform: adc
id: light_sensor
name: "Illuminance"
pin: $ldr_pin
device_class: illuminance
update_interval: 10s
attenuation: auto
unit_of_measurement: lx
accuracy_decimals: 0
filters:
- lambda: |-
return (x / 10000.0) * 2000000.0 - 15 ;
on_value:
then:
- lambda: |-
if ( id(aab_enable) && !id(night_enable) ) {
int n = x / 4 + id(aab_add); // new_value
if (n > id(aab_max)) n = id(aab_max);
if (n < id(aab_min)) n = id(aab_min);
int c = id(rgb8x32)->get_brightness(); // current value
int d = (n - c) * 100 / c; // diff in %
if ( abs(d) > 2 ) id(rgb8x32)->set_brightness(n);
}
output:
- platform: ledc
pin: $buzzer_pin
id: rtttl_out
rtttl:
output: rtttl_out
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
light:
- platform: neopixelbus
id: ehmtx_light
type: GRB
variant: WS2812
pin: $matrix_pin
num_leds: 256
color_correct: [30%, 30%, 30%]
name: "Light"
restore_mode: ALWAYS_OFF
on_turn_on:
lambda: |-
id(ehmtx_display)->set_enabled(false);
on_turn_off:
lambda: |-
id(ehmtx_display)->set_enabled(true);
time:
- platform: homeassistant
on_time_sync:
then:
ds1307.write_time:
- platform: ds1307
update_interval: never
id: ehmtx_time
display:
- platform: addressable_light
id: ehmtx_display
addressable_light_id: ehmtx_light
width: 32
height: 8
pixel_mapper: |-
if (y % 2 == 0) {
return (y * 32) + x;
}
return (y * 32) + (31 - x);
rotation: 0°
update_interval: 16ms
auto_clear_enabled: true
lambda: |-
id(rgb8x32)->tick();
id(rgb8x32)->draw();