-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathco2-sm3.yaml
More file actions
235 lines (201 loc) · 5.72 KB
/
Copy pathco2-sm3.yaml
File metadata and controls
235 lines (201 loc) · 5.72 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
# 29.11.2025 R.Krüger --- Erstellung
# https://github.com/RK62/esphome/blob/main/co2-sm3.yaml
substitutions:
device_name: "co2-sm3"
friendly_name: "CO2-SM3"
project_name: "Ralf Krüger.CO2-Sensor"
project_version: "1.30"
esphome:
name: ${device_name}
name_add_mac_suffix: false
friendly_name: ${friendly_name}
project:
name: ${project_name}
version: ${project_version}
on_boot:
- priority: 800
then:
- delay: 1s
- display.page.show: PAGE01
- component.update: DISPLAY
- delay: 10s
- component.update: CO2_SENSOR # CO2-Wert updaten
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "FTYv/RwusBNZZSSO7R/13/xB8Xksa+ytdQauXiDimeM="
actions:
- action: calibrate_co2_value
variables:
co2_ppm: int
then:
- scd4x.perform_forced_calibration:
id: CO2_SENSOR
value: !lambda 'return co2_ppm;'
- action: factory_reset
then:
- scd4x.factory_reset: CO2_SENSOR
- action: set_ambient_pressure
variables:
pressure_mbar: int
then:
- lambda: "id(CO2_SENSOR)->set_ambient_pressure_compensation(pressure_mbar);"
ota:
- platform: esphome
password: "5c3b42f4f6c0e7eff99fcc62284069c9"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
min_auth_mode: WPA2
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${friendly_name} Hotspot"
password: "0123456789"
captive_portal:
# ==============================================================================
# ------------------------------------------------------------
i2c:
# ------------------------------------------------------------
sda: GPIO5
scl: GPIO6
# ------------------------------------------------------------
font:
# ------------------------------------------------------------
- id: FONT_N
file: "gfonts://Inter"
size: 22
- id: FONT_B
file: "gfonts://Inter"
size: 29
# ------------------------------------------------------------
display:
# ------------------------------------------------------------
- platform: ssd1306_i2c
id: DISPLAY
model: "SSD1306 72x40"
rotation: 0
update_interval: never
pages:
- id: PAGE01
lambda: |-
it.print(0, 0, id(FONT_N), "Hi" );
it.print(26, 18, id(FONT_N), "Bro!" );
- id: PAGE02
lambda: |-
it.printf(35, 16, id(FONT_B), TextAlign::CENTER, "%.0f", id(CO2_WERT).state);
it.rectangle(0, 35, 71, 4);
it.filled_rectangle(0, 36, id(CO2_WERT).state * 0.05, 4);
- id: PAGE03
lambda: |-
it.printf(35, 16, id(FONT_B), TextAlign::CENTER, "%.1f°", id(TEMPERATUR).state);
- id: PAGE04
lambda: |-
it.printf(35, 16, id(FONT_B), TextAlign::CENTER, "%.0f%%", id(FEUCHTIGKEIT).state);
# ------------------------------------------------------------
interval:
# ------------------------------------------------------------
- interval: 5s
startup_delay: 15s
then:
- display.page.show_next: DISPLAY
- component.update: DISPLAY
# ------------------------------------------------------------
sensor:
# ------------------------------------------------------------
- platform: scd4x
id: CO2_SENSOR
update_interval: 60s
co2:
id: CO2_WERT
name: "CO2"
accuracy_decimals: 0
filters:
- round: 1
on_value:
then:
- script.execute: SET_AMPEL
temperature:
id: TEMPERATUR
name: "Temperatur"
accuracy_decimals: 1
filters:
- offset: -1.4 # Datenkorrektur
- round: 1
humidity:
id: FEUCHTIGKEIT
name: "Feuchtigkeit"
accuracy_decimals: 0
filters:
- offset: -4.0 # Datenkorrektur
- round: 1
# ------------------------------------------------------------
light:
# ------------------------------------------------------------
- platform: binary
id: LED_RED
name: "LED Rot"
disabled_by_default: True
output: IO_RED
- platform: binary
id: LED_YELLOW
name: "LED Gelb"
disabled_by_default: True
output: IO_YELLOW
- platform: binary
id: LED_GREEN
name: "LED Grün"
disabled_by_default: True
output: IO_GREEN
# ------------------------------------------------------------
output:
# ------------------------------------------------------------
- id: IO_RED
platform: gpio
pin: GPIO21
- id: IO_YELLOW
platform: gpio
pin: GPIO20
- id: IO_GREEN
platform: gpio
pin: GPIO10
# ------------------------------------------------------------
script:
# ------------------------------------------------------------
- id: SET_AMPEL
then:
# - component.update: DISPLAY # Display updaten
- if:
condition:
lambda: return isnan(id(CO2_WERT).raw_state);
then:
- light.turn_off: LED_GREEN
- light.turn_off: LED_YELLOW
- light.turn_off: LED_RED
- if:
condition:
lambda: return id(CO2_WERT).state < 800;
then:
- light.turn_on: LED_GREEN
else:
- light.turn_off: LED_GREEN
- if:
condition:
lambda: return id(CO2_WERT).state >= 700
&& id(CO2_WERT).state < 1300;
then:
- light.turn_on: LED_YELLOW
else:
- light.turn_off: LED_YELLOW
- if:
condition:
lambda: return id(CO2_WERT).state > 1200;
then:
- light.turn_on: LED_RED
else:
- light.turn_off: LED_RED