-
Notifications
You must be signed in to change notification settings - Fork 0
/
Edward Terra ESPHome.yaml
313 lines (295 loc) · 8.83 KB
/
Edward Terra ESPHome.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
esphome:
name: "grow3"
on_boot:
then:
- lambda: |-
ESP_LOGD("MY_LOG", "cyclingRepeatHour: %d", id(cyclingRepeatHour).state);
ESP_LOGD("MY_LOG", "cyclingRepeatMin: %d", id(cyclingRepeatMin).state);
ESP_LOGD("MY_LOG", "tankFillTimeMs: %d", id(tankFillTimeMs));
ESP_LOGD("MY_LOG", "tankEmptyTimeMs: %d", id(tankEmptyTimeMs));
- delay: 1min
- lambda: |-
ESP_LOGD("MY_LOG", "cyclingRepeatHour: %d", id(cyclingRepeatHour).state);
ESP_LOGD("MY_LOG", "cyclingRepeatMin: %d", id(cyclingRepeatMin).state);
ESP_LOGD("MY_LOG", "tankFillTimeMs: %d", id(tankFillTimeMs));
ESP_LOGD("MY_LOG", "tankEmptyTimeMs: %d", id(tankEmptyTimeMs));
# Be sure that the tank is empty
- switch.turn_on: pumpDown
- wait_until:
condition:
- switch.is_off: pumpDown
# Save the current millis
- globals.set:
id: timerMs
value: !lambda "return millis();"
# Calculate the milliseconds needed to fill the tank (+30s)
- switch.turn_on: pumpUp
- wait_until:
condition:
- switch.is_off: pumpUp
- globals.set:
id: tankFillTimeMs
value: !lambda "return millis() - id(timerMs) + 30000;"
# Save the current millis
- globals.set:
id: timerMs
value: !lambda "return millis();"
# Calculate the milliseconds needed to empty the tank (+30s)
- switch.turn_on: pumpDown
- wait_until:
condition:
- switch.is_off: pumpDown
- globals.set:
id: tankEmptyTimeMs
value: !lambda "return millis() - id(timerMs) + 30000;"
- globals.set:
id: setupFinished
value: "true"
#on_loop:
#then:
#- wait_until:
# condition:
# - lambda: "return id(setupFinished);"
#- switch.turn_on: pumpUp
#- wait_until:
# condition:
# - switch.is_off: pumpUp
#- switch.turn_on: pumpDown
#- delay: 10min
#- delay: !lambda "return (id(cyclingRepeatHour).state * 60 * 60 * 1000) + (id(cyclingRepeatMin).state * 60 * 1000);"
esp32:
board: esp32dev
# --- [ Includes without configuration ] ---
captive_portal:
logger:
web_server:
# --- [ Variables ] ---
# id & name: Needed to be available to the frontend
# mode: Either a text field or a slider
# optimistic: Number is automatically updated by HA
# restore_value: Number is stored locally on the microcontoller
number:
- platform: template
id: 'cyclingRepeatHour'
name: "Cycle every x Hours"
unit_of_measurement: "hour"
icon: mdi:timeline-clock-outline
initial_value: 0
max_value: 24
min_value: 0
step: 1
mode: box
optimistic: true
restore_value: true
on_value:
- if:
condition:
lambda: "return x == 0 && id(cyclingRepeatMin).state == 0;"
then:
- number.set:
id: cyclingRepeatHour
value: 1
- platform: template
id: 'cyclingRepeatMin'
name: "Cycle every x Minutes"
unit_of_measurement: "min"
icon: mdi:timeline-clock-outline
initial_value: 15
max_value: 60
min_value: 0
step: 5
mode: box
optimistic: true
restore_value: true
on_value:
- if:
condition:
lambda: "return x == 0 && id(cyclingRepeatHour).state == 0;"
then:
- number.set:
id: cyclingRepeatMin
value: 5
globals:
- id: 'setupFinished'
type: bool
restore_value: false
initial_value: "false"
- id: 'timerMs'
type: int
restore_value: false
- id: 'tankFillTimeMs'
type: int
restore_value: true
initial_value: "600000" # 10min
- id: 'tankEmptyTimeMs'
type: int
restore_value: true
initial_value: "600000" # 10min
# --- [ API Settings ] ---
api:
encryption:
key: "p/mvy37TBCoUJTsoO/yhUoHkNOGP799hk/YBsIcHc9w="
# --- [ Over the Air Update ] ---
ota:
password: "b44fa2f6562034444f273839507c7054"
# --- [ WiFi ] ---
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-237E5E"
password: "AtWFLG1E6azs"
# --- [ I2C ] ---
i2c:
sda: 21
scl: 22
scan: True
id: bus_a
# --- [ Dallas ] ---
dallas:
pin: 17
update_interval: 5s
# --- [ Sensors ] ---
sensor:
- platform: dallas
index : 0
name: "DS18B20 (Water) Temperature"
- platform: bme680
temperature:
name: "BME680 Temperature"
pressure:
name: "BME680 Pressure"
humidity:
name: "BME680 Humidity"
gas_resistance:
name: "BME680 Gas Resistance"
address: 0x77
update_interval: 5s
# --- [ Switches ] ---
switch:
- platform: gpio
pin: 19
id: 'pumpUp'
name: "Pump Up"
interlock: [pumpDown]
on_turn_on:
- if:
condition:
- binary_sensor.is_on: tankFull
then:
# Tank is already full -> Turn pump off
- delay: 1ms
- switch.turn_off: pumpUp
else:
# Wait until "full" sensor is active
- wait_until:
condition:
- binary_sensor.is_on: tankFull
timeout: !lambda "return id(tankFillTimeMs);"
- if:
condition:
- binary_sensor.is_off: tankFull
- switch.is_on: pumpUp
then:
# The filling of the tank took to long
- logger.log: "Timeout while filling tank!"
- homeassistant.service:
service: notify.notify
data:
message: "Timeout while filling the tank..."
title: "Error!"
- switch.turn_off: pumpUp
- platform: gpio
pin: 23
id: 'pumpDown'
name: "Pump Down"
interlock: [pumpUp]
on_turn_on:
- if:
condition:
- binary_sensor.is_on: tankEmpty
then:
# Tank is already empty -> Turn pump off
- delay: 1ms
- switch.turn_off: pumpDown
else:
# Wait until "empty" sensor is active
- wait_until:
condition:
- binary_sensor.is_on: tankEmpty
timeout: !lambda "return id(tankEmptyTimeMs);"
- if:
condition:
- binary_sensor.is_off: tankEmpty
- switch.is_on: pumpDown
then:
# The emptying of the tank took to long
- logger.log: "Timeout while emptying tank!"
- homeassistant.service:
service: notify.notify
data:
message: "Timeout while emptying the tank..."
title: "Error!"
- switch.turn_off: pumpDown
# --- [ Binary sensors ] ---
binary_sensor:
- platform: gpio
pin: 34
id: 'tankFull'
name: "Full Tank"
filters:
- invert
- delayed_on: 3s
- delayed_off: 3s
# Check if tank gains water without pump
on_press:
- if:
condition:
- switch.is_off: pumpUp
then:
- homeassistant.service:
service: notify.notify
data:
message: "Tank is gaining water..."
title: "Warning!"
# Check if tank looses water without pump
on_release:
- if:
condition:
- switch.is_off: pumpDown
then:
- homeassistant.service:
service: notify.notify
data:
message: "Tank is loosing water..."
title: "Warning!"
- platform: gpio
pin: 36
id: 'tankEmpty'
name: "Empty Tank"
filters:
- delayed_on: 3s
- delayed_off: 3s
# Check if tank looses water without pump
on_press:
- if:
condition:
- switch.is_off: pumpDown
then:
- homeassistant.service:
service: notify.notify
data:
message: "Tank is loosing water..."
title: "Warning!"
# Check if tank gains water without pump
on_release:
- if:
condition:
- switch.is_off: pumpUp
then:
- homeassistant.service:
service: notify.notify
data:
message: "Tank is gaining water..."
title: "Warning!"