-
Notifications
You must be signed in to change notification settings - Fork 2
/
peristaltic-aux.yaml
415 lines (393 loc) · 11.6 KB
/
peristaltic-aux.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
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
411
412
413
414
415
substitutions:
id: peristaltic-aux
device_name: Peristaltic Aux
pwm_frequency: 20000 Hz
esphome:
name: $id
friendly_name: $device_name
<<: !include common/board/wemos-d1-mini32.yaml
<<: !include common/common-esp32.yaml
globals:
- id: pump1_run_time
type: uint32_t
initial_value: "0"
- id: pump2_run_time
type: uint32_t
initial_value: "0"
- id: pump3_run_time
type: uint32_t
initial_value: "0"
- id: pump4_run_time
type: uint32_t
initial_value: "0"
- id: pump1_run_time_backup
type: uint32_t
initial_value: "0"
- id: pump2_run_time_backup
type: uint32_t
initial_value: "0"
- id: pump3_run_time_backup
type: uint32_t
initial_value: "0"
- id: pump4_run_time_backup
type: uint32_t
initial_value: "0"
output:
- platform: template
id: pump1_target_speed
type: float
write_action:
then:
- if:
condition:
switch.is_on: pump1_reverse
then:
- output.turn_off: pump1_direction_pin1
- output.turn_on: pump1_direction_pin2
else:
- output.turn_on: pump1_direction_pin1
- output.turn_off: pump1_direction_pin2
- if:
condition:
light.is_on: pump1_speed_controller
then:
- output.set_level:
id: pump1_speed_pin
level: !lambda return (0.4 + (0.6 * id(pump1_speed_controller).current_values.get_brightness()));
else:
- output.turn_off: pump1_speed_pin
- platform: template
id: pump2_target_speed
type: float
write_action:
then:
- if:
condition:
switch.is_on: pump2_reverse
then:
- output.turn_off: pump2_direction_pin1
- output.turn_on: pump2_direction_pin2
else:
- output.turn_on: pump2_direction_pin1
- output.turn_off: pump2_direction_pin2
- if:
condition:
light.is_on: pump2_speed_controller
then:
- output.set_level:
id: pump2_speed_pin
level: !lambda return (0.4 + (0.6 * id(pump2_speed_controller).current_values.get_brightness()));
else:
- output.turn_off: pump2_speed_pin
- platform: template
id: pump3_target_speed
type: float
write_action:
then:
- if:
condition:
switch.is_on: pump3_reverse
then:
- output.turn_off: pump3_direction_pin1
- output.turn_on: pump3_direction_pin2
else:
- output.turn_on: pump3_direction_pin1
- output.turn_off: pump3_direction_pin2
- if:
condition:
light.is_on: pump3_speed_controller
then:
- output.set_level:
id: pump3_speed_pin
level: !lambda return (0.4 + (0.6 * id(pump3_speed_controller).current_values.get_brightness()));
else:
- output.turn_off: pump3_speed_pin
- platform: template
id: pump4_target_speed
type: float
write_action:
then:
- if:
condition:
switch.is_on: pump4_reverse
then:
- output.turn_off: pump4_direction_pin1
- output.turn_on: pump4_direction_pin2
else:
- output.turn_on: pump4_direction_pin1
- output.turn_off: pump4_direction_pin2
- if:
condition:
light.is_on: pump4_speed_controller
then:
- output.set_level:
id: pump4_speed_pin
level: !lambda return (0.4 + (0.6 * id(pump4_speed_controller).current_values.get_brightness()));
else:
- output.turn_off: pump4_speed_pin
- platform: ledc
id: pump1_speed_pin
pin: GPIO26
frequency: $pwm_frequency
- platform: gpio
id: pump1_direction_pin1
pin: GPIO21
- platform: gpio
id: pump1_direction_pin2
pin: GPIO32
- platform: ledc
id: pump2_speed_pin
pin: GPIO18
frequency: $pwm_frequency
- platform: gpio
id: pump2_direction_pin1
pin: GPIO25
- platform: gpio
id: pump2_direction_pin2
pin: GPIO22
- platform: ledc
id: pump3_speed_pin
pin: GPIO19
frequency: $pwm_frequency
- platform: gpio
id: pump3_direction_pin1
pin: GPIO4
- platform: gpio
id: pump3_direction_pin2
pin: GPIO2
- platform: ledc
id: pump4_speed_pin
pin: GPIO23
frequency: $pwm_frequency
- platform: gpio
id: pump4_direction_pin1
pin: GPIO16
- platform: gpio
id: pump4_direction_pin2
pin: GPIO17
light:
- platform: monochromatic
id: pump1_speed_controller
name: "$device_name Pump 1"
output: pump1_target_speed
default_transition_length: 0s
gamma_correct: 0
- platform: monochromatic
id: pump2_speed_controller
name: "$device_name Pump 2"
output: pump2_target_speed
default_transition_length: 0s
gamma_correct: 0
- platform: monochromatic
id: pump3_speed_controller
name: "$device_name Pump 3"
output: pump3_target_speed
default_transition_length: 0s
gamma_correct: 0
- platform: monochromatic
id: pump4_speed_controller
name: "$device_name Pump 4"
output: pump4_target_speed
default_transition_length: 0s
gamma_correct: 0
switch:
- platform: restart
name: "$device_name Restart"
- platform: gpio
pin: GPIO27
name: "$device_name Enable Pumps 1-2"
- platform: gpio
pin: GPIO33
name: "$device_name Enable Pumps 3-4"
- platform: template
name: "$device_name Pump 1 Reverse"
id: pump1_reverse
turn_on_action:
- output.turn_off: pump1_direction_pin1
- output.turn_on: pump1_direction_pin2
- switch.template.publish:
id: pump1_reverse
state: ON
turn_off_action:
- output.turn_on: pump1_direction_pin1
- output.turn_off: pump1_direction_pin2
- switch.template.publish:
id: pump1_reverse
state: OFF
- platform: template
name: "$device_name Pump 2 Reverse"
id: pump2_reverse
turn_on_action:
- output.turn_off: pump2_direction_pin1
- output.turn_on: pump2_direction_pin2
- switch.template.publish:
id: pump2_reverse
state: ON
turn_off_action:
- output.turn_on: pump2_direction_pin1
- output.turn_off: pump2_direction_pin2
- switch.template.publish:
id: pump2_reverse
state: OFF
- platform: template
name: "$device_name Pump 3 Reverse"
id: pump3_reverse
turn_on_action:
- output.turn_off: pump3_direction_pin1
- output.turn_on: pump3_direction_pin2
- switch.template.publish:
id: pump3_reverse
state: ON
turn_off_action:
- output.turn_on: pump3_direction_pin1
- output.turn_off: pump3_direction_pin2
- switch.template.publish:
id: pump3_reverse
state: OFF
- platform: template
name: "$device_name Pump 4 Reverse"
id: pump4_reverse
turn_on_action:
- output.turn_off: pump4_direction_pin1
- output.turn_on: pump4_direction_pin2
- switch.template.publish:
id: pump4_reverse
state: ON
turn_off_action:
- output.turn_on: pump4_direction_pin1
- output.turn_off: pump4_direction_pin2
- switch.template.publish:
id: pump4_reverse
state: OFF
number:
- platform: template
name: "$device_name Pump 1 Run Time"
id: pump1_run_time_control
min_value: 0
max_value: 3600
step: 1
unit_of_measurement: "seconds"
optimistic: true
set_action:
- globals.set:
id: pump1_run_time
value: !lambda return x;
- globals.set:
id: pump1_run_time_backup
value: !lambda return x;
- platform: template
name: "$device_name Pump 2 Run Time"
id: pump2_run_time_control
min_value: 0
max_value: 3600
step: 1
unit_of_measurement: "seconds"
optimistic: true
set_action:
- globals.set:
id: pump2_run_time
value: !lambda return x;
- globals.set:
id: pump2_run_time_backup
value: !lambda return x;
- platform: template
name: "$device_name Pump 3 Run Time"
id: pump3_run_time_control
min_value: 0
max_value: 3600
step: 1
unit_of_measurement: "seconds"
optimistic: true
set_action:
- globals.set:
id: pump3_run_time
value: !lambda return x;
- globals.set:
id: pump3_run_time_backup
value: !lambda return x;
- platform: template
name: "$device_name Pump 4 Run Time"
id: pump4_run_time_control
min_value: 0
max_value: 3600
step: 1
unit_of_measurement: "seconds"
optimistic: true
set_action:
- globals.set:
id: pump4_run_time
value: !lambda return x;
- globals.set:
id: pump4_run_time_backup
value: !lambda return x;
interval:
- interval: 1s
then:
- if:
condition:
and:
- light.is_on: pump1_speed_controller
- lambda: "return id(pump1_run_time) > 0;"
then:
- globals.set:
id: pump1_run_time
value: !lambda "return id(pump1_run_time) > 0 ? id(pump1_run_time) - 1 : 0;"
- if:
condition:
lambda: "return id(pump1_run_time) == 0;"
then:
- light.turn_off: pump1_speed_controller
- globals.set:
id: pump1_run_time
value: !lambda "return id(pump1_run_time_backup);"
- if:
condition:
and:
- light.is_on: pump2_speed_controller
- lambda: "return id(pump2_run_time) > 0;"
then:
- globals.set:
id: pump2_run_time
value: !lambda "return id(pump2_run_time) > 0 ? id(pump2_run_time) - 1 : 0;"
- if:
condition:
lambda: "return id(pump2_run_time) == 0;"
then:
- light.turn_off: pump2_speed_controller
- globals.set:
id: pump2_run_time
value: !lambda "return id(pump2_run_time_backup);"
- if:
condition:
and:
- light.is_on: pump3_speed_controller
- lambda: "return id(pump3_run_time) > 0;"
then:
- globals.set:
id: pump3_run_time
value: !lambda "return id(pump3_run_time) > 0 ? id(pump3_run_time) - 1 : 0;"
- if:
condition:
lambda: "return id(pump3_run_time) == 0;"
then:
- light.turn_off: pump3_speed_controller
- globals.set:
id: pump3_run_time
value: !lambda "return id(pump3_run_time_backup);"
- if:
condition:
and:
- light.is_on: pump4_speed_controller
- lambda: "return id(pump4_run_time) > 0;"
then:
- globals.set:
id: pump4_run_time
value: !lambda "return id(pump4_run_time) > 0 ? id(pump4_run_time) - 1 : 0;"
- if:
condition:
lambda: "return id(pump4_run_time) == 0;"
then:
- light.turn_off: pump4_speed_controller
- globals.set:
id: pump4_run_time
value: !lambda "return id(pump4_run_time_backup);"