-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCO2Sensor.yaml
More file actions
186 lines (161 loc) · 4.03 KB
/
Copy pathCO2Sensor.yaml
File metadata and controls
186 lines (161 loc) · 4.03 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
esphome:
name: co2sensor
esp32:
board: lolin32
framework:
type: arduino
api:
port: 6053
reboot_timeout: 0s
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
reboot_timeout: 0s
ota:
safe_mode: true
password: !secret ota_password
font:
- file: 'fonts/PragmataPro.ttf'
id: font1
size: 16
- file: 'fonts/PragmataPro.ttf'
id: font_small
size: 12
- file: 'fonts/PragmataPro.ttf'
id: font_tiny
size: 10
i2c:
sda: 5
scl: 4
switch:
- platform: template
id: hourly_graph
name: "Hourly graph"
optimistic: true
- platform: template
id: fast_poll_on
name: "Fast polling"
optimistic: true
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
id: screen
pages:
- lambda: |-
if (id(co2).has_state()) {
it.printf(0, 13, id(font_small), TextAlign::BASELINE_LEFT , "%.0f ppm", id(co2).state);
}
if (id(temperature).has_state()) {
it.printf(0, 26, id(font_small), TextAlign::BASELINE_LEFT , "%.1f°C", id(temperature).state);
}
if (id(humidity).has_state()) {
it.printf(0, 39, id(font_small), TextAlign::BASELINE_LEFT , "%.2f%%", id(humidity).state);
}
if (id(ip_address).has_state()) {
it.printf(0, 64, id(font_tiny), TextAlign::BASELINE_LEFT, "%s", id(ip_address).state.c_str());
} else {
it.print(0, 64, id(font_tiny), TextAlign::BASELINE_LEFT, "No WiFi");
}
if (id(hourly_graph).state) {
it.graph(52, 0, id(co2graph));
it.print(90, 64, id(font_tiny), TextAlign::BASELINE_CENTER, "2h");
} else {
it.graph(52, 0, id(co2graph_small));
it.print(90, 64, id(font_tiny), TextAlign::BASELINE_CENTER, "20 min");
}
auto poll_txt = id(fast_poll_on).state ? "/5s": "/60s";
it.print(128, 64, id(font_tiny), TextAlign::BASELINE_RIGHT, poll_txt);
graph:
- id: co2graph_small
sensor: co2
duration: 20min
width: 76
height: 48
min_value: 400
max_value: 2000
y_grid: 400
x_grid: 5min
border: true
- id: co2graph
sensor: co2
duration: 2h
width: 76
height: 48
min_value: 400
max_value: 2000
y_grid: 400
x_grid: 15min
border: true
sensor:
- platform: scd4x
id: sdc40
measurement_mode: periodic
update_interval: 60s
co2:
name: "Office CO2"
id: "co2"
on_value:
then:
- lambda: |-
float co2 = std::min(float(1800), x);
auto t = (co2-440)/(1800 - 440);
auto interpolated = ESPHSVColor(uint8_t((1-t)*96), 255, 32);
auto inter_rgb = interpolated.to_rgb();
auto call = id(co2light).turn_on();
call.set_rgb(inter_rgb.red / 255.0, inter_rgb.green / 255.0, inter_rgb.blue / 255.0);
call.set_brightness(0.3);
call.perform();
temperature:
name: "Office Temperature"
id: "temperature"
humidity:
name: "Office Humidity"
id: "humidity"
interval:
- interval: 5s
then:
- if:
condition:
switch.is_on: fast_poll_on
then:
- component.update: sdc40
binary_sensor:
- platform: gpio
pin:
number: GPIO25
mode:
input: true
pulldown: true
id: "btn"
name: "Breadboard button"
filters:
- delayed_on: 10ms
on_press:
then:
- switch.toggle: hourly_graph
on_click:
min_length: 750ms
max_length: 5000ms
then:
- switch.turn_on: fast_poll_on
- delay: 10min
- switch.turn_off: fast_poll_on
text_sensor:
- platform: wifi_info
ip_address:
name: ESP IP Address
id: ip_address
ssid:
name: ESP Connected SSID
id: wifi_ssid
light:
- platform: neopixelbus
type: GRB
variant: WS2812
pin: GPIO2
num_leds: 1
name: "CO2 LED"
id: co2light
entity_category: diagnostic