-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttgo-tdisplay-co2.yaml
223 lines (200 loc) · 4.31 KB
/
ttgo-tdisplay-co2.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
esphome:
name: ttgo-tdisplay-co2
friendly_name: ttgo-tdisplay-co2
esp32:
board: esp32dev
framework:
type: arduino
logger:
api:
encryption:
key: !secret api_secret
services:
- service: ttgo_tdisplay_co2_calibrate_zero
then:
- mhz19.calibrate_zero: id_mhz19
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
# CO2 sensor
uart:
rx_pin: GPIO13
tx_pin: GPIO12
baud_rate: 9600
# Dipslay driver: ST7789
spi:
clk_pin: GPIO18
mosi_pin: GPIO19
font:
- file: "fonts/Oswald-Light.ttf"
id: font_80
size: 80
- file: "fonts/Oswald-Light.ttf"
id: font_70
size: 70
# glyphs: 0123456789 # Only used for CO2 level
- file: "fonts/Oswald-Light.ttf"
id: font_30
size: 30
color:
- id: color_black
red: 0%
green: 0%
blue: 0%
white: 0%
- id: color_green
red: 0%
green: 100%
blue: 0%
- id: color_yellow
red: 100%
green: 100%
blue: 0%
- id: color_orange
red: 100%
green: 55%
blue: 0%
- id: color_red
red: 100%
green: 0%
- id: color_white
red: 100%
green: 100%
blue: 100%
display:
- platform: st7789v
model: TTGO_TDISPLAY_135X240
update_interval: 5s
id: my_display
backlight_pin:
number: 4
allow_other_uses: true
mode:
output: True
input: False
open_drain: False
pullup: False
pulldown: False
cs_pin: GPIO5
dc_pin: GPIO16
reset_pin: GPIO23
rotation: 90
pages:
# Page 1: Current CO2 levels
# 0 - 1000 -> Green
# 1000 - 1600 -> Yellow
# 1600 - 2000 -> Orange
# >2000 -> Red
- id: page1
lambda: |-
if(!id(co2_sensor).has_state() ){
it.print(
it.get_width()/2,
it.get_height()/2,
id(font_70),
color_white,
TextAlign::CENTER,
"Starting..."
);
return;
}
auto bg_color = id(color_black);
auto text_color = id(color_green);
auto co2 = id(co2_sensor).state;
if(co2 > 1000) text_color = id(color_yellow);
if(co2 > 1500) text_color = id(color_orange);
if(co2 > 2000){
text_color = id(color_white);
bg_color = id(color_red);
}
it.filled_rectangle(0, 0, it.get_width(), it.get_height(), bg_color);
it.printf(
it.get_width()/2,
it.get_height()/2,
id(font_70),
text_color,
TextAlign::CENTER,
"%.0f ppm",
co2
);
# Page 2: WiFi information
- id: page2
lambda: |-
it.print(
0, 0,
id(font_30),
id(color_white),
"WiFi details"
);
it.printf(
0, 30,
id(font_30),
id(color_white),
"%s",
id(wifi_ssid).state.c_str()
);
it.printf(
0, 60,
id(font_30),
id(color_white),
"%s",
id(wifi_ip_addr).state.c_str()
);
switch:
- platform: gpio
pin:
number: GPIO4
allow_other_uses: true
id: backlight
internal: true
sensor:
- platform: mhz19
co2:
name: "CO2 Indoor"
id: "co2_sensor"
temperature:
name: "Temperature"
internal: true
update_interval: 5s
id: id_mhz19
automatic_baseline_calibration: False
- platform: adc
pin: GPIO34
attenuation: auto
filters:
- multiply: 2
name: VBatt
id: vcc
update_interval: 10s
text_sensor:
- platform: wifi_info
ip_address:
internal: true
id: wifi_ip_addr
ssid:
internal: true
id: wifi_ssid
binary_sensor:
# Button to cycle through pages on the display
- platform: gpio
pin:
number: GPIO35
inverted: true
id: button_1
on_click:
then:
- display.page.show_next: my_display
- component.update: my_display
# Button to toggle the backlight (for use at night)
- platform: gpio
pin:
number: GPIO0
inverted: true
id: button_2
on_click:
then:
- switch.toggle: backlight