-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm5stickc-plus2.yaml
More file actions
410 lines (378 loc) · 10.4 KB
/
m5stickc-plus2.yaml
File metadata and controls
410 lines (378 loc) · 10.4 KB
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
399
400
401
402
403
404
405
406
407
408
409
410
substitutions:
name: m5stickc-plus2
friendly_name: M5StickC PLUS2
esphome:
name: ${name}
name_add_mac_suffix: false
friendly_name: ${friendly_name}
platformio_options:
upload_speed: 115200
on_boot:
- priority: 600
then:
- output.turn_on: output_high
- then:
# read the RTC time once when the system boots
- pcf8563.read_time: my_time
- text_sensor.template.publish:
id: template_text
state: !lambda |-
char str[17];
time_t currTime = id(my_time).now().timestamp;
strftime(str, sizeof(str), "%H:%M:%S %d/%m/%y", localtime(&currTime));
return { str };
- light.turn_on:
id: display_bl
brightness: 75%
on_shutdown:
- priority: 600
then:
- output.turn_off: output_high
esp32:
board: m5stick-c
framework:
type: esp-idf
advanced:
minimum_chip_revision: "3.1"
flash_size: 8MB
psram:
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
ota:
- platform: esphome
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.X.X
gateway: !secret wifi_gtw
subnet: !secret wifi_sub
dns1: !secret wifi_dns1
script:
- id: buzzer_cycle
mode: single
then:
- output.turn_on: buzzer
- output.ledc.set_frequency:
id: buzzer
frequency: "1000Hz"
- output.set_level:
id: buzzer
level: "50%"
- delay: 2s
- output.turn_off: buzzer
# Battery voltage measured through ADC1_CH2. PLUS2 has a voltage divider,
# so reading needs to be multiplied by 2
sensor:
- platform: adc
pin: GPIO38
attenuation: 11db
update_interval: 60s
name: Battery Voltage
id: battery_voltage
filters:
- multiply: 2.0
on_value_range:
- below: 3.2
then:
- script.execute: buzzer_cycle
- platform: template
name: "Battery Level"
id: battery_level
unit_of_measurement: "%"
icon: "mdi:battery"
device_class: battery
state_class: measurement
lambda: 'return id(battery_voltage).state;'
update_interval: 60s
filters:
- calibrate_linear:
- 4.15 -> 100.0
- 3.96 -> 90.0
- 3.91 -> 80.0
- 3.85 -> 70.0
- 3.80 -> 60.0
- 3.75 -> 50.0
- 3.68 -> 40.0
- 3.58 -> 30.0
- 3.49 -> 20.0
- 3.41 -> 10.0
- 3.30 -> 5.0
- 3.27 -> 0.0
- clamp:
min_value: 0
max_value: 100
- platform: sht3xd
i2c_id: i2c_external
temperature:
name: Temperature
id: temp_state
filters:
- offset: -1.5
humidity:
name: Humidity
id: hum_state
filters:
- offset: 8.0
address: 0x44
update_interval: 60s
- platform: qmp6988
i2c_id: i2c_external
pressure:
name: Pression
id: pression_state
address: 0x70
update_interval: 60s
iir_filter: 2x
- platform: wifi_signal
id: wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
internal: true
- platform: copy
source_id: wifi_signal_db
name: WiFi Signal
id: wifi_signal_pct
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
device_class: ""
- platform: uptime
id: uptime_sec
update_interval: 60s
internal: true
switch:
- platform: restart
name: Restart
entity_category: "diagnostic"
binary_sensor:
# Turn on display backlight TFT LCD while Button A is click. Turn on red led while Button A is double_click
- platform: gpio
pin:
number: GPIO37
inverted: true
name: Button A
on_multi_click:
- timing:
- ON for 40ms to 400ms
- OFF for at least 330ms
then:
- light.toggle: display_bl
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 300ms
- ON for 40ms to 400ms
- OFF for at least 330ms
then:
- light.toggle: led1
# Play 1000Hz tone through buzzer while Button B is pressed
- platform: gpio
pin:
number: GPIO39
inverted: true
name: Button B
on_press:
then:
- output.turn_on: buzzer
- output.ledc.set_frequency:
id: buzzer
frequency: "1000Hz"
- output.set_level:
id: buzzer
level: "50%"
on_release:
then:
- output.turn_off: buzzer
- platform: gpio
pin:
number: GPIO35
inverted: true
name: Button C
- platform: status
name: Statut
entity_category: "diagnostic"
light:
# Red led
- platform: monochromatic
output: builtin_led
name: Led
id: led1
# Backlight TFT LCD
- platform: monochromatic
output: backlight
name: Backlight
id: display_bl
restore_mode: ALWAYS_ON
time:
- platform: pcf8563
i2c_id: i2c_internal
id: my_time
address: 0x51
update_interval: never
- platform: homeassistant
on_time_sync:
then:
- pcf8563.write_time: my_time
- text_sensor.template.publish:
id: template_text
state: !lambda |-
char str[17];
time_t currTime = id(my_time).now().timestamp;
strftime(str, sizeof(str), "%H:%M:%S %d/%m/%y", localtime(&currTime));
return { str };
text_sensor:
- platform: template
name: RTC Sensor
id: template_text
- platform: template
id: plus_uptime
name: Uptime
lambda: |-
int seconds = (id(uptime_sec).state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
if ( days ) {
return { (to_string(days) +"d " + to_string(hours) +"h " + to_string(minutes) +"m "+ to_string(seconds) +"s ").c_str() };
} else if ( hours ) {
return { (to_string(hours) +"h " + to_string(minutes) +"m "+ to_string(seconds) +"s ").c_str() };
} else if ( minutes ) {
return { (to_string(minutes) +"m "+ to_string(seconds) +"s ").c_str() };
} else {
return { (to_string(seconds) +"s ").c_str() };
}
icon: mdi:clock-start
update_interval: 60s
entity_category: "diagnostic"
output:
# Red led
- platform: ledc
pin: 19
inverted: false
id: builtin_led
# Buzzer
- platform: ledc
pin: 2
inverted: true
id: buzzer
# Backlight TFT LCD
- platform: ledc
pin: 27
inverted: false
id: backlight
# Battery switch
- platform: gpio
id: output_high
pin:
number: GPIO4
mode:
output: true
spi:
clk_pin: GPIO13
mosi_pin: GPIO15
# Built-in I2C Bus. Bus_external is for devices connected via the HAT pins. Not sure which interface is used for devices connected via the Grove port
i2c:
- id: i2c_internal
sda: GPIO21
scl: GPIO22
scan: false
- id: i2c_external
sda: GPIO0
scl: GPIO26
scan: false
font:
- file: "gfonts://Roboto"
id: roboto
size: 22
image:
- file: mdi:weather-pouring
id: pouring
type: BINARY
resize: 70x70
- file: mdi:weather-partly-cloudy
id: partly_cloudy
type: BINARY
resize: 70x70
- file: mdi:weather-sunny
id: sunny
type: BINARY
resize: 70x70
- file: mdi:close
id: croix
type: BINARY
resize: 70x70
- file: mdi:battery-high
id: battery
type: BINARY
resize: 30x30
- file: mdi:wifi
id: wifi_icon
type: BINARY
resize: 30x30
color:
- id: my_white
red: 100%
green: 100%
blue: 100%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_orange
red: 100%
green: 50%
blue: 0%
# 1.14 inch, 135*240 Colorful TFT LCD, ST7789v2
display:
- platform: mipi_spi
model: st7789v
cs_pin: GPIO5
dc_pin: GPIO14
reset_pin: GPIO12
rotation: 90
color_palette: NONE
dimensions:
height: 240
width: 135
offset_height: 40
offset_width: 52
# Required or the colors are all inverted, and Black screen is White
invert_colors: true
lambda: |-
it.strftime(30, 2, id(roboto), id(my_blue), "%H:%M:%S %d/%m/%y", id(my_time).now());
if ((id(pression_state).state >= 960) && (id(pression_state).state < 983)) {it.image(14, 30, id(pouring), id(my_red));}
else if ((id(pression_state).state >= 983) && (id(pression_state).state < 1016)) {it.image(14, 30, id(partly_cloudy), id(my_yellow));}
else if ((id(pression_state).state >= 1016) && (id(pression_state).state < 1060)) {it.image(14, 30, id(sunny), id(my_green));}
else {it.image(14, 30, id(croix), id(my_red));}
it.printf(94, 40, id(roboto), id(my_green), "%.0fhpa", id(pression_state).state);
it.printf(94, 66, id(roboto), id(my_blue), "%.1f°C", id(temp_state).state);
it.printf(173, 66, id(roboto), id(my_blue), "%.0f%%", id(hum_state).state);
if (id(battery_level).state < 21) { it.image(20, 102, id(battery), id(my_red));}
else {it.image(20, 102, id(battery), id(my_green));}
it.printf(54, 106, id(roboto), id(my_white), "%.0f%%", id(battery_level).state);
if ((id(wifi_signal_pct).state >= 1) && (id(wifi_signal_pct).state < 25)) {it.image(123, 102, id(wifi_icon), id(my_red));}
else if ((id(wifi_signal_pct).state >= 25) && (id(wifi_signal_pct).state < 50)) {it.image(123, 102, id(wifi_icon), id(my_orange));}
else if ((id(wifi_signal_pct).state >= 50) && (id(wifi_signal_pct).state < 75)) {it.image(123, 102, id(wifi_icon), id(my_yellow));}
else {it.image(123, 102, id(wifi_icon), id(my_green));}
it.printf(161, 106, id(roboto), id(my_white), "%.0f%%", id(wifi_signal_pct).state);