forked from nicolaij/esphomes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namotka.yaml
506 lines (475 loc) · 13.4 KB
/
namotka.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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
esphome:
name: namotka
platformio_options:
board_build.f_cpu: 160000000L
esp32:
board: esp32dev
framework:
type: esp-idf
wifi:
ssid: !secret wifi_ssid_home
password: !secret wifi_password_home
reboot_timeout: 0s
ap:
ssid: "Namotka"
password: !secret ap_password
ap_timeout: 0s
# power_save_mode: HIGH
#captive_portal:
# Enable logging
logger:
#level: VERBOSE
#level: VERY_VERBOSE
#level: INFO
# Enable Home Assistant API
api:
reboot_timeout: 0s
ota:
# Активация web сервера
web_server:
port: 80
#local: true
ota: false
version: 2
js_include: "www_all_number.js"
js_url: ""
binary_sensor:
- platform: gpio
pin:
number: GPIO0
inverted: true
filters:
- delayed_on: 50ms
name: "Boot button"
on_press:
then:
- if:
condition:
- lambda: "return id(g_layer_mode) < 10;"
then:
- button.press: btn_layer_home
- platform: gpio
pin:
inverted: true
number: 17
mode:
input: true
pullup: true
name: "Layer home switch"
id: id_home
- platform: gpio
id: id_turns
pin:
number: 16
inverted: false
mode:
input: true
pullup: false
on_press:
then:
- lambda: |-
if (id(fan_rotator).state) //если включен
{
if (id(fan_rotator).direction == FanDirection::FORWARD) {
auto call = id(num_cur_turn).make_call();
call.number_increment(true);
call.perform();
} else {
auto call = id(num_cur_turn).make_call();
call.number_decrement(true);
call.perform();
}
auto call = id(num_step_cur_turn).make_call();
call.number_decrement(true);
call.perform();
if (id(g_layer_mode) == 11) //мотаем влево
{
id(g_coil_counter)++;
int pos = id(g_layer_position) - (id(g_coil_counter) * id(num_d).state) / id(num_layer_step_size).state;
id(id_stepper_lay).set_target(pos);
auto callp = id(id_layer_position).make_call();
callp.set_value(id(id_stepper_lay).target_position);
callp.perform();
}
if (id(g_layer_mode) == 12) //мотаем вправо
{
id(g_coil_counter)++;
int pos = id(g_layer_position) + (id(g_coil_counter) * id(num_d).state) / id(num_layer_step_size).state;
id(id_stepper_lay).set_target(pos);
auto callp = id(id_layer_position).make_call();
callp.set_value(id(id_stepper_lay).target_position);
callp.perform();
}
if (id(g_rotator_turn_stop) == id(num_cur_turn).state)
{
// Turn the fan off
id(g_layer_mode) = 10;
auto call = id(fan_rotator).turn_off();
call.perform();
}
}
status_led:
pin:
number: GPIO2
inverted: false
globals:
- id: g_layer_mode
type: int
restore_value: no
initial_value: "0"
- id: id_layer_timeout
type: int
restore_value: no
initial_value: "3"
- id: id_stepper_offset
type: int
restore_value: no
initial_value: "0"
- id: g_coil_counter
type: int
restore_value: no
initial_value: "0"
- id: id_direction
type: int
restore_value: no
initial_value: "1"
- id: g_rotator_turn_stop
type: int
restore_value: no
initial_value: "0"
- id: g_layer_direction
type: int
restore_value: no
initial_value: "0"
- id: g_layer_position
type: int
restore_value: no
initial_value: "0"
number:
- platform: template
name: "V1 Катушка. Начало:"
id: num_offset
optimistic: true
restore_value: true
min_value: 0
max_value: 100
step: 0.01
unit_of_measurement: "мм."
- platform: template
name: "V2 Катушка. D проволоки:"
id: num_d
optimistic: true
restore_value: true
min_value: 0
max_value: 5
step: 0.001
unit_of_measurement: "мм."
- platform: template
name: "V3 Катушка. Ширина:"
id: num_width
optimistic: true
restore_value: true
min_value: 1
max_value: 100
step: 0.01
unit_of_measurement: "мм."
- platform: template
name: "X2 Укладчик. Шаг:"
id: num_layer_step_size
optimistic: true
restore_value: true
min_value: 0
max_value: 1
initial_value: 0.0750
step: 0.0001
unit_of_measurement: "мм/шаг"
- platform: template
name: "X3 Укладчик. Смещение:"
id: num_layer_position_offset
optimistic: true
restore_value: true
min_value: -50
max_value: 50
initial_value: 0
step: 0.01
unit_of_measurement: "мм."
- platform: template
name: "X4 Укладчик. Текущая позиция: "
id: id_layer_position
optimistic: true
restore_value: false
min_value: -1000
max_value: 1000
initial_value: 0
step: 1
unit_of_measurement: "шаг."
- platform: template
name: "Y2 Намотчик. Витки всего:"
id: num_cur_turn
optimistic: true
restore_value: false
min_value: -100000
max_value: 100000
initial_value: 0
step: 1
- platform: template
name: "Y3 Намотчик. Витки на слой:"
id: num_step_cur_turn
optimistic: true
restore_value: false
min_value: -100000
max_value: 100000
initial_value: 0
step: 1
- platform: template
name: "Y1 Намотчик. Скорость:"
id: n_layer_speed_turn
optimistic: true
restore_value: true
min_value: 0
max_value: 100
initial_value: 90
step: 1
select:
- platform: template
name: "V5 Катушка. Начало:"
id: sl_begin
optimistic: true
options:
- "Со стороны привода"
- "Со свободной стороны"
initial_option: "Со стороны привода"
restore_value: true
sensor:
- platform: uptime
name: Uptime Sensor
id: uptime_id
update_interval: 1min
# - platform: esp32_hall
# name: "ESP32 Hall Sensor"
# id: hall_id
# update_interval: 30s
stepper:
- platform: uln2003
id: id_stepper_lay
pin_a: 14
pin_b: 27
pin_c: 13
pin_d: 26
max_speed: 200 steps/s
sleep_when_done: true
step_mode: HALF_STEP
acceleration: inf
deceleration: inf
output:
- platform: ledc
id: motor_forward_pin
pin: 32
frequency: "1000Hz"
- platform: ledc
id: motor_reverse_pin
pin: 33
frequency: "1000Hz"
- platform: ledc
id: motor_enable
pin: 25
frequency: "1000Hz"
fan:
- platform: hbridge
id: fan_rotator
name: "Y0 Намотчик"
pin_a: motor_forward_pin
pin_b: motor_reverse_pin
enable_pin: motor_enable
decay_mode: slow # slow decay mode (coasting) or fast decay (braking).
speed_count: 100
button:
- platform: template
name: "X1 Укладчик. Инициализация"
id: btn_layer_home
on_press:
- globals.set:
id: id_layer_timeout
value: "300"
- globals.set:
id: g_layer_mode
value: "1"
#режим 1 - движение в сторону 0
- stepper.set_speed:
id: id_stepper_lay
speed: 200 steps/s
- stepper.report_position:
id: id_stepper_lay
position: 0
- stepper.set_target:
id: id_stepper_lay
target: -550
- while:
condition:
and:
- binary_sensor.is_off: id_home
- lambda: "return id(id_layer_timeout)-- > 0;"
then:
- delay: 10ms
- if:
condition:
lambda: "return id(id_layer_timeout) > 0;"
then:
- globals.set:
id: id_layer_timeout
value: "100"
- globals.set:
id: g_layer_mode
value: "2"
- stepper.set_speed:
id: id_stepper_lay
speed: 20 steps/s
- stepper.report_position:
id: id_stepper_lay
position: 0
- stepper.set_target:
id: id_stepper_lay
target: 10
#режим 2 - съезд с концевика
- while:
condition:
and:
- binary_sensor.is_on: id_home
- lambda: "return id(id_layer_timeout)-- > 0;"
then:
- delay: 10ms
- if:
condition:
lambda: "return id(id_layer_timeout) > 0;"
then:
- globals.set:
id: g_layer_mode
value: "10"
# переезд на offset
- stepper.set_speed:
id: id_stepper_lay
speed: 200 steps/s
- stepper.report_position:
id: id_stepper_lay
position: 0
- number.set:
id: id_layer_position
value: !lambda if(id(sl_begin).active_index() == 0) { return int((id(num_offset).state - id(num_layer_position_offset).state)/id(num_layer_step_size).state);} else {return int((id(num_offset).state + id(num_width).state + id(num_layer_position_offset).state)/id(num_layer_step_size).state);};
- stepper.set_target:
id: id_stepper_lay
target: !lambda return id(id_layer_position).state;
else:
- logger.log: "ERROR. Home switch error!"
else:
- logger.log: "ERROR. Home switch not found!"
- platform: template
name: "X5 Укладчик. На позицию!"
id: id_layer_go
on_press:
- stepper.set_target:
id: id_stepper_lay
target: !lambda return id(id_layer_position).state;
- platform: template
name: "Y6 Намотчик. STOP"
id: id_layer_stop
on_press:
- fan.turn_off: fan_rotator
- globals.set:
id: g_layer_mode
value: "10"
- globals.set:
id: g_rotator_turn_stop
value: !lambda return id(num_cur_turn).state;
switch:
- platform: template
name: "Y4 Намотчик. Слой Лево/Право"
assumed_state: true
optimistic: true
restore_mode: DISABLED
turn_off_action:
- globals.set:
id: g_layer_mode
value: "11"
- globals.set:
id: g_coil_counter
value: "0"
- globals.set:
id: g_layer_position
value: !lambda return id(id_layer_position).state;
- globals.set:
id: g_rotator_turn_stop
value: !lambda return id(num_cur_turn).state + id(num_step_cur_turn).state;
- stepper.set_speed:
id: id_stepper_lay
speed: 200 steps/s
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3 * 2;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state;
turn_on_action:
- globals.set:
id: g_layer_mode
value: "12"
- globals.set:
id: g_coil_counter
value: "0"
- globals.set:
id: g_layer_position
value: !lambda return id(id_layer_position).state;
- globals.set:
id: g_rotator_turn_stop
value: !lambda return id(num_cur_turn).state + id(num_step_cur_turn).state;
- stepper.set_speed:
id: id_stepper_lay
speed: 200 steps/s
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3 * 2;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state;
- platform: template
name: "Y5 Намотчик. Виток -1/+1"
assumed_state: true
optimistic: true
restore_mode: DISABLED
turn_on_action:
- lambda: id(g_rotator_turn_stop) = int(id(num_cur_turn).state) + 1;
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state / 3 * 2;
- delay: 100ms
- fan.turn_on:
id: fan_rotator
direction: forward
speed: !lambda return id(n_layer_speed_turn).state;
turn_off_action:
- lambda: id(g_rotator_turn_stop) = int(id(num_cur_turn).state) - 1;
- fan.turn_on:
id: fan_rotator
direction: reverse
speed: !lambda return id(n_layer_speed_turn).state;