-
Notifications
You must be signed in to change notification settings - Fork 1
/
robot_0.yaml
457 lines (387 loc) · 12.3 KB
/
robot_0.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
#------------------------------
#-- robot_0.yaml
#-- Code pour piloter un petit robot NodeMCU à 20 balles au moyen d'un brocker MQTT
#-- Les commandes sont expressément très simplistes
#-- location: Hôtel du Cervin à St-Luc ;-)
#-- zf230122.1510
#--
# sources:
# ...
substitutions:
devicename: robot_1
esphome:
name: $devicename
on_boot:
- switch.turn_on: ${devicename}_motor_direction_forward
- switch.turn_on: ${devicename}_stop
- switch.turn_on: ${devicename}_led
- delay: 0.5s
- switch.turn_off: ${devicename}_led
esp8266:
board: nodemcuv2
# Configuration WIFI
wifi:
ssid: !secret wifi_ssid_cours_iot
password: !secret wifi_pass_cours_iot
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${devicename} Fallback"
password: !secret ap_wifi_password
captive_portal:
# Enable logging
logger:
level: DEBUG
logs:
sensor: INFO
ultrasonic.sensor: INFO
# Enable Home Assistant API
# api:
# password: !secret api_password
ota:
password: !secret ota_password
# WEB Server
web_server:
port: 80
# Définitions du MQTT server
mqtt:
broker: 192.168.20.107
port: 1883
username: toto
password: tutu
birth_message:
will_message:
on_message:
# Commandes de déplacements du robot
- topic: ${devicename}/switch/${devicename}_motor_start/set
payload: 'ON'
then:
- logger.log: Receive START command !
- switch.turn_on:
id: ${devicename}_start
- topic: ${devicename}/switch/${devicename}_motor_stop/set
payload: 'ON'
then:
- logger.log: Receive STOP command !
- switch.turn_on:
id: ${devicename}_stop
- topic: ${devicename}/switch/${devicename}_motor_go/set
payload: 'ON'
then:
- logger.log: Receive GO command !
- switch.turn_on:
id: ${devicename}_go
- topic: ${devicename}/switch/${devicename}_motor_direction_forward/set
payload: 'ON'
then:
- logger.log: Receive FORWARD command !
- switch.turn_on:
id: ${devicename}_motor_direction_forward
- topic: ${devicename}/switch/${devicename}_motor_direction_backward/set
payload: 'ON'
then:
- logger.log: Receive BACKWARD command !
- switch.turn_on:
id: ${devicename}_motor_direction_backward
- topic: ${devicename}/switch/${devicename}_motor_direction_left/set
payload: 'ON'
then:
- logger.log: Receive LEFT command !
- switch.turn_on:
id: ${devicename}_motor_direction_left
- topic: ${devicename}/switch/${devicename}_motor_direction_right/set
payload: 'ON'
then:
- logger.log: Receive RIGHT command !
- switch.turn_on:
id: ${devicename}_motor_direction_right
on_json_message:
# valeurs de réglages pour le robot
- topic: ${devicename}/number/${devicename}_motor_speed/set
then:
- logger.log: Receive Motor Speed value !
- number.set:
id: ${devicename}_motor_speed
value: !lambda |-
return x["value"];
- topic: ${devicename}/number/${devicename}_motor_preburn/set
then:
- logger.log: Receive Motor Preburn value !
- number.set:
id: ${devicename}_motor_preburn
value: !lambda |-
return x["value"];
- topic: ${devicename}/number/${devicename}_motor_preburn_time/set
then:
- logger.log: Receive Motor Preburn Time value !
- number.set:
id: ${devicename}_motor_preburn_time
value: !lambda |-
return x["value"];
- topic: ${devicename}/number/${devicename}_motor_differentiel/set
then:
- logger.log: Receive Motor Differentiel value !
- number.set:
id: ${devicename}_motor_differentiel
value: !lambda |-
return x["value"];
- topic: ${devicename}/number/${devicename}_motor_time/set
then:
- logger.log: Receive Motor Time value !
- number.set:
id: ${devicename}_motor_time
value: !lambda |-
return x["value"];
# Définition des Switch's
switch:
- platform: gpio
name: "${devicename} LED"
inverted: True
id: ${devicename}_led
pin: D0
- platform: restart
name: "${devicename} Restart"
- platform: gpio
name: "${devicename} Motor Direction A "
# inverted: True
id: ${devicename}_motor_direction_a
pin: D3
- platform: gpio
name: "${devicename} Motor Direction B"
# inverted: True
id: ${devicename}_motor_direction_b
pin: D4
- platform: template
name: "${devicename} Motor GO"
id: ${devicename}_go
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_on:
id: ${devicename}_start
- platform: template
name: "${devicename} Motor START"
id: ${devicename}_start
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
# Préchauffage des moteurs pour combattre le frottement mu zéro
- light.turn_on:
id: ${devicename}_motor_speed_a
brightness: !lambda |-
// output value must be in range 0 - 1.0
return id(${devicename}_motor_preburn).state / 100;
- light.turn_on:
id: ${devicename}_motor_speed_b
brightness: !lambda |-
// output value must be in range 0 - 1.0
return id(${devicename}_motor_preburn).state / 100;
- delay: !lambda return id(${devicename}_motor_preburn_time).state * 1000;
# Allumage des moteurs selon la consigne avec le différentiel gauche/droite
- light.turn_on:
id: ${devicename}_motor_speed_a
brightness: !lambda |-
// output value must be in range 0 - 1.0
return id(${devicename}_motor_speed).state / 100.0 * (0.5 + id(${devicename}_motor_differentiel).state);
- light.turn_on:
id: ${devicename}_motor_speed_b
brightness: !lambda |-
// output value must be in range 0 - 1.0
return id(${devicename}_motor_speed).state / 100.0 / (0.5 + id(${devicename}_motor_differentiel).state);
- switch.turn_off: ${devicename}_stop
- platform: template
name: "${devicename} Motor STOP"
id: ${devicename}_stop
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_off:
id: ${devicename}_start
- light.turn_off:
id: ${devicename}_motor_speed_a
- light.turn_off:
id: ${devicename}_motor_speed_b
- switch.turn_off: ${devicename}_start
- switch.turn_off: ${devicename}_go
- platform: template
name: "${devicename} Motor Direction FORWARD"
id: ${devicename}_motor_direction_forward
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_off: ${devicename}_motor_direction_a
- switch.turn_off: ${devicename}_motor_direction_b
- switch.turn_off: ${devicename}_motor_direction_backward
- switch.turn_off: ${devicename}_motor_direction_right
- switch.turn_off: ${devicename}_motor_direction_left
- platform: template
name: "${devicename} Motor Direction BACKWARD"
id: ${devicename}_motor_direction_backward
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_on: ${devicename}_motor_direction_a
- switch.turn_on: ${devicename}_motor_direction_b
- switch.turn_off: ${devicename}_motor_direction_forward
- switch.turn_off: ${devicename}_motor_direction_right
- switch.turn_off: ${devicename}_motor_direction_left
- platform: template
name: "${devicename} Motor Direction RIGHT"
id: ${devicename}_motor_direction_right
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_off: ${devicename}_motor_direction_a
- switch.turn_on: ${devicename}_motor_direction_b
- switch.turn_off: ${devicename}_motor_direction_left
- switch.turn_off: ${devicename}_motor_direction_forward
- switch.turn_off: ${devicename}_motor_direction_backward
- platform: template
name: "${devicename} Motor Direction LEFT"
id: ${devicename}_motor_direction_left
optimistic: true
restore_mode: ALWAYS_OFF
turn_on_action:
- switch.turn_on: ${devicename}_motor_direction_a
- switch.turn_off: ${devicename}_motor_direction_b
- switch.turn_off: ${devicename}_motor_direction_right
- switch.turn_off: ${devicename}_motor_direction_forward
- switch.turn_off: ${devicename}_motor_direction_backward
# Définition des Output's
output:
- platform: esp8266_pwm
pin: D1
frequency: 50 Hz
id: ${devicename}_motor_pwm_a
- platform: esp8266_pwm
pin: D2
frequency: 50 Hz
id: ${devicename}_motor_pwm_b
# Définition des Light's
light:
- platform: monochromatic
output: ${devicename}_motor_pwm_a
name: "${devicename} motor Speed A"
id: ${devicename}_motor_speed_a
internal: true
- platform: monochromatic
output: ${devicename}_motor_pwm_b
name: "${devicename} motor Speed B"
id: ${devicename}_motor_speed_b
internal: true
# Définition des Sensors
sensor:
- platform: wifi_signal
name: "${devicename} Signal Wi-Fi"
update_interval: 15s
on_value:
then:
- switch.turn_on: ${devicename}_led
- platform: uptime
name: "${devicename} uptime"
update_interval: 5s
- platform: ultrasonic
trigger_pin: D5
echo_pin: D6
name: "${devicename} Distance"
id: ${devicename}_distance
update_interval: 0.25s
on_value:
then:
- if:
condition:
lambda: 'return (id(${devicename}_start).state == 1 and id(${devicename}_motor_direction_forward).state == 1 and id(${devicename}_distance).state < 0.25) ;'
then:
- switch.turn_off:
id: ${devicename}_start
- switch.turn_on:
id: ${devicename}_stop
- switch.turn_off:
id: ${devicename}_go
# Définition des Sensors text
text_sensor:
- platform: version
name: "${devicename} Version 1209"
- platform: wifi_info
ip_address:
name: ${devicename} IP Address
id: wifi_ip
ssid:
name: ${devicename} Connected SSID
id: wifi_ssid
# Définition des inputs numbers
number:
- platform: template
name: "${devicename} Motor Speed"
id: ${devicename}_motor_speed
restore_value: true
optimistic: true
mode: box
min_value: 60
max_value: 100
step: 1
initial_value: 75
unit_of_measurement: "%"
- platform: template
name: "${devicename} Motor Preburn"
id: ${devicename}_motor_preburn
restore_value: true
optimistic: true
mode: box
min_value: 75
max_value: 100
step: 3
initial_value: 100
unit_of_measurement: "%"
- platform: template
name: "${devicename} Motor Preburn Time"
id: ${devicename}_motor_preburn_time
restore_value: true
optimistic: true
mode: box
min_value: 0
max_value: 1
step: 0.01
initial_value: 1
unit_of_measurement: "S"
- platform: template
name: "${devicename} Motor Differentiel"
id: ${devicename}_motor_differentiel
restore_value: true
optimistic: true
mode: box
min_value: 0.2
max_value: 0.8
step: 0.01
initial_value: 0.50
unit_of_measurement: ""
- platform: template
name: "${devicename} Motor Time"
id: ${devicename}_motor_time
restore_value: false
optimistic: true
mode: box
min_value: 0
max_value: 20
# ATTENTION, ne pas modifier le 'step' car c'est le 'décrement' du chronomètre de la commande 'go'
step: 0.2
initial_value: 2
unit_of_measurement: "S"
# Gestion des timers
interval:
# Timer pour calculer le temps passé à avancer !
- interval: 0.2s
then:
- if:
condition:
lambda: 'return (id(${devicename}_motor_time).state > 0 and id(${devicename}_go).state == 1) ;'
then:
- number.decrement:
id: ${devicename}_motor_time
cycle: false
else:
- if:
condition:
lambda: 'return id(${devicename}_go).state == 1;'
then:
- switch.turn_on:
id: ${devicename}_stop