/
ScrobyConfig
3324 lines (3101 loc) · 103 KB
/
ScrobyConfig
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Faster off
#Door Open (arrive)
#Buffer distances
#Light for auto moves allowed?
#Pin mappings
# G # TXD # EN # G
#@ 27 tm1638 # RXD # S_VP / 36 # G*
#@ 25 tm1638 # 22 i2c_a SDA #@ 26 # S_VN
#@ 32 tm1638 # 21 i2c_a SCL #@ 18 TX_pendant_green #[i] 35
# 12 #@ 17 #@ 19 RX_pendant_blue #@ 33 button_w_led
#@ 04 #RTTL #@ 16 RX_robot_blue #@ 23 #[i] NTROL
# 00 # G #@ 5 # 14
# 02 # 5v0 / vIN # 3v3 # 3v3*
# xx # 15 # 13 # 5vF*
substitutions:
transition_lights: 10ms
transition_through_lights: 50ms
home_delay: 1s
esphome:
friendly_name: Scorby
name: scorbot-quinled
comment: Scorbot ER iii w Quinled ESP32
platform: ESP32
board: mhetesp32devkit #Quinled pinout: https://quinled.info/quinled-esp32-board-details/
on_boot:
- priority: -100
then:
#Not dependant on scorby controller being online
- script.execute: zero_last_movement_amount_tracker
- script.execute: zero_cumulative_movement_amount_tracker
- script.execute: set_all_button_states_to_off
- wait_until: #Wait until API is connected
condition:
api.connected:
timeout: 20s
#Turn on contoller power
- switch.turn_on: power_control_box_switch
on_shutdown:
- priority: -400
then:
- if:
condition:
switch.is_on: power_control_box_switch
then:
- switch.turn_off: power_control_box_switch
- delay: 500ms
- script.wait: safe_shutdown
- wait_until: #Wait until power is off.
condition:
binary_sensor.is_off: robot_power_is_on
timeout: 20s
- delay: 1s #Give a few other things a second to complete.
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
logger:
# baud_rate: 0
level: VERBOSE
logs:
light: INFO
ledc.output: INFO
vl53l0x: INFO
display:
#TM1638:
# https://esphome.io/components/display/tm1638.html
# 5V
platform: tm1638
id: tm1638_display
stb_pin: 32 #White Wire
clk_pin: 25 #Brown Wire
dio_pin: 27 #Light Purple Wire
intensity: 1
update_interval: never
lambda: |-
it.print(" "); //Clear existing
it.printf(0, id(screen_message).state.c_str()); //Screen messages pushed from other locations
#Buzzer
rtttl:
output: rtttl_out
on_finished_playback:
- logger.log: 'Song ended!'
i2c:
#https://esphome.io/components/i2c.html
#Put 5v and 3v on different bus.
#VL53L0X: 3V https://esphome.io/components/sensor/vl53l0x.html
#PCA9685: 5V https://esphome.io/components/output/pca9685.html
- id: i2c_3v
sda: 21
scl: 22
scan: true
- id: i2c_5v #pca9685
sda: 23
scl: 5
scan: true
frequency: 100kHz
pca9685:
frequency: 1000 #Must be in range from 24Hz to 1525.88Hz. Default 1000Hz.
external_clock_input: false
i2c_id: i2c_5v
output:
#Rttl buzzer
- platform: ledc
pin: GPIO04
id: rtttl_out
#pca9685 outputs
- id: pca9685_output1
platform: pca9685
channel: 0
- id: pca9685_output2
platform: pca9685
channel: 1
- id: pca9685_output3
platform: pca9685
channel: 2
- id: pca9685_output4
platform: pca9685
channel: 3
- id: pca9685_output5
platform: pca9685
channel: 4
- id: pca9685_output6
platform: pca9685
channel: 5
- id: pca9685_output7
platform: pca9685
channel: 6
light:
#Retro LED Rows. Indexing a bit misaligned.
- platform: monochromatic
name: LED Row 4 Orange
id: led_row_4
output: pca9685_output1
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Row 5 Blue
id: led_row_5
output: pca9685_output2
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Row 6 Multi
id: led_row_6
output: pca9685_output3
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Row 3 Amber
id: led_row_3
output: pca9685_output4
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Row 2 Green
id: led_row_2
output: pca9685_output5
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Row 1 RED
id: led_row_1
output: pca9685_output6
default_transition_length: ${transition_lights}
internal: true
- platform: monochromatic
name: LED Head Torch
id: led_head_torch
output: pca9685_output7
icon: mdi:flashlight
default_transition_length: ${transition_lights}
on_turn_on:
- light.turn_on:
id: led_head_torch
brightness: 70%
sensor:
#Robot rosition tracking (e.g tracks distance from "home")
#On value, update the "total movement trackers"
#Last Movement amount (requested)
- platform: template
name: "M1 Last Movement Amount"
id: m1_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m1_cumulative_movement_amount).publish_state(x + id(m1_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M2 Last Movement Amount"
id: m2_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m2_cumulative_movement_amount).publish_state(x + id(m2_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M3 Last Movement Amount"
id: m3_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m3_cumulative_movement_amount).publish_state(x + id(m3_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M4 Last Movement Amount"
id: m4_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m4_cumulative_movement_amount).publish_state(x + id(m4_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M5 Last Movement Amount"
id: m5_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m5_cumulative_movement_amount).publish_state(x + id(m5_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M6 Last Movement Amount"
id: m6_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m6_cumulative_movement_amount).publish_state(x + id(m6_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M7 Last Movement Amount"
id: m7_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m7_cumulative_movement_amount).publish_state(x + id(m7_cumulative_movement_amount).state);
internal: true
- platform: template
name: "M8 Last Movement Amount"
id: m8_last_movement_amount
update_interval: never
on_value:
then:
- lambda: |-
id(m8_cumulative_movement_amount).publish_state(x + id(m8_cumulative_movement_amount).state);
internal: true
#Track cumulative motor movement amount commands
#Update the "return home uart command on value"
- platform: template
name: "M1 Cumulative Movement Amount"
id: m1_cumulative_movement_amount
update_interval: never
on_value:
then:
internal: true
- platform: template
name: "M2 Cumulative Movement Amount"
id: m2_cumulative_movement_amount
update_interval: never
on_value:
then:
internal: true
- platform: template
name: "M3 Cumulative Movement Amount"
id: m3_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
- platform: template
name: "M4 Cumulative Movement Amount"
id: m4_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
- platform: template
name: "M5 Cumulative Movement Amount"
id: m5_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
- platform: template
name: "M6 Cumulative Movement Amount"
id: m6_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
- platform: template
name: "M7 Cumulative Movement Amount"
id: m7_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
- platform: template
name: "M8 Cumulative Movement Amount"
id: m8_cumulative_movement_amount
update_interval: never
on_value:
then:
- component.update: esp_return_to_base_uart_command
internal: true
#Import power from smart switch
- platform: homeassistant
name: "Imported Power"
id: imported_power
entity_id: sensor.scorby_power_controller_power
unit_of_measurement: W
internal: true
on_value:
then: #Update the movemnent status sensor. This isn't a very responsive/reliable method.
- lambda: |-
if (x < 3) { return id(robot_status).publish_state("Off");}
else if (x < 17) { return id(robot_status).publish_state("Idle");}
else if (x >=17) { return id(robot_status).publish_state("Moving");}
else { return id(robot_status).publish_state("Other");}
- platform: uptime
name: "Uptime Sensor"
id: uptime_sensor
update_interval: 5s
entity_category: diagnostic
#############################################
#Time of Flight / Distance
#############################################
#VCC connects to 3V3 | https://esphome.io/components/sensor/vl53l0x.html
- platform: vl53l0x
i2c_id: i2c_3v
name: "Distance ToF"
id: distance_tof
icon: mdi:arrow-expand-horizontal
entity_category: diagnostic
address: 0x29
update_interval: 1s
long_range: true
filters:
- multiply: 100 #Convert to cm
# - median: #Use a moving median for spike smoothing.
# window_size: 3
# send_every: 3
- delta: 1.0
unit_of_measurement: "cm"
accuracy_decimals: 0 #Keep it simple. To the cm.
binary_sensor:
#Binary sensors to check for supervision.
#Import HA DND
##################################
#Presence
##################################
- platform: homeassistant
name: "DND"
id: "dnd"
entity_id: input_boolean.dnd_mode
icon: mdi:volume-off
publish_initial_state: true
internal: true
- platform: homeassistant
name: "Inbound Person"
internal: false
id: "last_front_door_movement_likely_inbound"
entity_id: binary_sensor.last_front_door_movement_likely_inbound
icon: mdi:door
publish_initial_state: true
#M Here.
- platform: homeassistant
name: "Mahko Here"
internal: false
id: "mahko_here"
entity_id: binary_sensor.mahko_is_here
icon: mdi:alpha-m-circle
publish_initial_state: true
# #H Here.
# - platform: homeassistant
# name: "Hannah Here"
# internal: false
# id: "hannah_here"
# entity_id: binary_sensor.hannah_is_here
# icon: mdi:alpha-h-circle
# publish_initial_state: true
# #People Here
# - platform: homeassistant
# name: "People Here"
# internal: false
# id: "people_here"
# entity_id: binary_sensor.people_home
# icon: mdi:home-import-outline
# publish_initial_state: true
# on_press:
- platform: homeassistant
name: "Front Door Open"
internal: false
id: "front_door_open"
entity_id: binary_sensor.door_window_sensor_158d00031b360f
icon: mdi:door
publish_initial_state: true
##################################
#Presence based automations
##################################
#Auto actions only allowed if supervised, not in DND mode, and hardware button enabled.
- platform: template
id: auto_moves_allowed
icon: mdi:auto-mode
name: Auto Moves Allowed
lambda: |-
return
id(mahko_here).state &&
(not id(dnd).state) &&
id(button_w_led).state
;
#Someone arrives
- platform: template
id: arrival_suss_trigger
entity_category: diagnostic
icon: mdi:motion-sensor
name: Arrival Suss Trigger
lambda: |-
return
id(last_front_door_movement_likely_inbound).state
;
on_press:
- script.execute: sussing_you_out_script
filters:
- delayed_off: 2min
- platform: template
id: someone_is_detected
entity_category: diagnostic
icon: mdi:motion-sensor
name: Someone Is Detected
lambda: |-
if (id(distance_tof).state >= id(someone_is_close_threshold).state)
{return true;}
else
{return false;}
filters:
- delayed_on: 1s
- delayed_off: 2min
on_press:
- script.execute: someone_is_detected_script
- platform: template
id: someone_is_close_binary
entity_category: diagnostic
icon: mdi:motion-sensor
name: Someone Is Close
lambda: |-
if (id(distance_tof).state < id(someone_is_close_threshold).state)
{return true;}
else
{return false;}
filters:
- delayed_on: 3s
- delayed_off: 2min
on_press:
- script.execute: someone_is_close_kiss_script
- platform: template
id: ready_for_action
name: Ready for Action
icon: mdi:motion-play
lambda: |-
return
id(esp_is_in_control).state &&
id(robot_power_is_on).state &&
id(interrupt_mode_switch).state
;
on_press:
- switch.turn_on: TM1638Led2
on_release:
- switch.turn_off: TM1638Led2
# - platform: template
# id: a_routine_is_running
# name: A Routine Is Running
# lambda: |-
# return
# id(esp_is_in_control).state &&
# id(robot_power_is_on).state &&
# id(interrupt_mode_switch).state
# ;
# on_press:
# - switch.turn_on: TM1638Led2
# on_release:
# - switch.turn_off: TM1638Led2
#Is the esp port the active port (rather than pendant)? Set from other sensors.
- platform: template
id: esp_is_in_control
name: ESP Is In Control
icon: mdi:car-esp
on_press:
- script.execute: configure_controller_settings #Once in control and communicating, configure settings.
#Scorby Power Status
- platform: template
id: robot_power_is_on
name: Robot Power Is On
icon: mdi:power
publish_initial_state: true
lambda: return id(imported_power).state >= 13; #Based on idle power
on_press:
#Not dependant on scorby controller being online
- switch.turn_on: TM1638Led1
- script.execute: zero_last_movement_amount_tracker
- script.execute: zero_cumulative_movement_amount_tracker
- script.execute: set_all_button_states_to_off
- delay: 3s #REQUIRED for Robot Controller to finsh booting!
- script.execute: make_esp_master_controller_script
on_release:
- script.execute: rtttl_single_scale_down
- switch.turn_off: TM1638Led1
- platform: template
id: robot_is_moving
icon: mdi:motion
name: Robot Is Moving #Power based heuristic.
lambda: return id(imported_power).state >= 17; #Based on moving power
- platform: copy
source_id: robot_is_moving
name: "Power Alert"
icon: mdi:flash-alert
id: power_alert
filters:
- delayed_on: 60s #If there's a high power draw for more than x seconds, turn off the controller.
on_press:
then:
- switch.turn_off: power_control_box_switch
- logger.log: 'High Power for too long! Turning off robot!!!'
- platform: homeassistant
id: imported_power_plug_is_on
name: Power Plug Is On
entity_id: binary_sensor.scorby_power_controller_power_is_on
internal: true
entity_category: diagnostic
- platform: homeassistant
id: imported_power_auto_off_soon
icon: mdi:timer-sand-complete
name: Auto Off Soon
entity_id: binary_sensor.scorby_power_controller_auto_off_soon
internal: true
- platform: template
id: motion_about_to_stop_3
name: Motion About to Stop
internal: true
on_press:
- delay: 1s
- lambda: id(motion_about_to_stop_3).publish_state(false);
- platform: template
id: motor_movements_done_4
name: Motor Movements Done
internal: true
on_press:
- delay: 1s
- lambda: id(motor_movements_done_4).publish_state(false);
- platform: template
id: robot_is_home
name: Robot Is Home
icon: mdi:home
device_class: PRESENCE
lambda: |-
return
id(limit_switch_1).state &&
id(limit_switch_2).state &&
id(limit_switch_3).state &&
id(limit_switch_4).state &&
id(limit_switch_5).state
;
on_press:
- switch.turn_on: TM1638Led4
on_release:
- switch.turn_off: TM1638Led4
- platform: template
id: robot_is_time_travelling
name: Robot Is Time Travelling
icon: mdi:home
device_class: LIGHT
lambda: |-
return
id(esp_return_to_base_uart_command).state == "1m-350\\r2m-1200\\r3m-250\\r4m-340\\r5m340\\r8m0\\r"
;
#Limit Switches
- platform: template
id: limit_switch_1
name: L1 Is Base Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_2
name: L2 Is Shoulder Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_3
name: L3 Is Elbow Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_4
name: L5 Is Wrist Pitch Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_5
name: L5 Is Wrist Rotate Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_6
name: L6 Is Gripper Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_7
name: L7 Is Limit Switch 7 Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: limit_switch_8
name: L8 Is Limit Switch 8 Home
icon: mdi:home-search
device_class: PRESENCE
- platform: template
id: input_1
name: I1 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_2
name: I2 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_3
name: I3 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_4
name: I4 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_5
name: I5 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_6
name: I6 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_7
name: I7 Input
icon: mdi:electric-switch
internal: true
- platform: template
id: input_8
name: I8 Input
icon: mdi:electric-switch
internal: true
#Latching Button with LED. Read only.
#LED wired to be on if switch closed.
#Power From 3V
- platform: gpio
name: "Auto Moves Allowed"
id: button_w_led
pin:
number: GPIO33 #Orange Wire
mode: INPUT_PULLDOWN
on_press:
then:
- script.execute: rtttl_single_high_beep
on_release:
then:
- script.execute: rtttl_single_high_beep
#tm1638 Buttons/LEDs
#Button 1: Toggle Power
- platform: tm1638
name: "Button 1 Toggle Power"
id: TM1638Button1
publish_initial_state: true
internal: true
key: 0
filters:
- delayed_on: 10ms
on_press:
then:
- switch.toggle: power_control_box_switch
- script.execute: rtttl_single_high_beep
#Button 2: Nothing
- platform: tm1638
name: "Button 2 Nothing"
id: TM1638Button2
internal: true
key: 1
filters:
- delayed_on: 10ms
# on_press:
# then:
# - switch.toggle: make_esp_master_switch
# - script.execute: rtttl_single_high_beep
#Button 3: Toggle Controller
- platform: tm1638
name: "Button 3 Toggle Controller"
id: TM1638Button3
internal: true
key: 2
filters:
- delayed_on: 10ms
on_press:
then:
- script.stop: home_search_all_script
- script.stop: someone_is_detected_script
- script.stop: someone_is_close_kiss_script
- script.stop: sussing_you_out_script
- script.stop: show_off_script
- switch.toggle: make_esp_master_switch
- script.execute: rtttl_single_high_beep
#Button 4: Search Home
- platform: tm1638
name: "Button 4 Home Search"
id: TM1638Button4
internal: true
key: 3
filters:
- delayed_on: 10ms
on_press:
then:
- script.stop: home_search_all_script
- script.stop: someone_is_detected_script
- script.stop: someone_is_close_kiss_script
- script.stop: sussing_you_out_script
- script.stop: show_off_script
- script.execute: rtttl_single_high_beep
- script.execute: home_search_all_script
on_release:
then:
- switch.turn_off: TM1638Led4
#Button 5: Return to Starting Pos
- platform: tm1638
name: "Button 5 Return To Start"
id: TM1638Button5
internal: true
key: 4
filters:
- delayed_on: 10ms
on_press:
then:
- script.stop: home_search_all_script
- script.stop: someone_is_detected_script
- script.stop: someone_is_close_kiss_script
- script.stop: sussing_you_out_script
- script.stop: show_off_script
- switch.turn_on: TM1638Led5
- script.execute: rtttl_single_high_beep
- button.press: esp_scorbot_return_to_base_command
on_release:
then:
- switch.turn_off: TM1638Led5
#Button 6
- platform: tm1638
name: "Button 6 Toggle Headlamp"
id: TM1638Button6
internal: true
key: 5
filters:
- delayed_on: 10ms
on_press:
then:
- script.execute: rtttl_single_high_beep
- switch.toggle: light_on_time_traveller_light
#Button 7
- platform: tm1638
name: "Button 7 Show Off"
id: TM1638Button7
internal: true
icon: mdi:rocket-launch
key: 6
filters:
- delayed_on: 10ms
on_press:
then:
- script.stop: home_search_all_script
- script.stop: someone_is_detected_script
- script.stop: someone_is_close_kiss_script
- script.stop: sussing_you_out_script
- switch.turn_on: TM1638Led7
- script.execute: rtttl_single_high_beep
- button.press: show_off_button
on_release:
then:
- switch.turn_off: TM1638Led7
#Button 8
- platform: tm1638
name: "Button 8 Suss it Out"
id: TM1638Button8
internal: true
key: 7
filters:
- delayed_on: 10ms
on_press:
then:
- script.stop: home_search_all_script
- script.stop: someone_is_detected_script
- script.stop: someone_is_close_kiss_script
- script.stop: show_off_script
- switch.turn_on: TM1638Led7
- script.execute: rtttl_single_high_beep
- button.press: sussing_you_out_button
on_release:
then:
- switch.turn_off: TM1638Led7
# on_release:
# then:
# - switch.turn_off: TM1638Led8
uart:
#Pendant side
- id: uart_p
rx_pin: GPIO16 #Green wire | Transmits commands from pendant to robot via mitm uart_p. Wire confusingly (?) labelled RX on pendant!!!!
# tx_pin: #Yellow wire | Not used. Bypass used.
baud_rate: 9600
data_bits: 8
stop_bits: 2
parity: NONE
rx_buffer_size: 256
debug:
direction: BOTH
dummy_receiver: true
after:
timeout: 1ms
#delimiter: "P"
sequence:
#Forward UART messages
- uart.write: #Write rx to tx.
id: uart_r
data: !lambda return bytes ;
#Log it.
- lambda:
UARTDebug::log_string(direction , bytes);
#Robot_side
- id: uart_r
rx_pin: GPIO18 #Yellow wire transmits data from robot to mitm rx uart_r
tx_pin: GPIO19 #Green wire transmits/forwards commands from the pendant > mitm > robot
baud_rate: 9600
data_bits: 8
stop_bits: 2
parity: NONE
rx_buffer_size: 256
debug:
direction: BOTH
dummy_receiver: true
after:
timeout: 1ms
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes); //Log both RX and TX.
std::string str(bytes.begin(), bytes.end()); //Convert uart text to string
str.erase(std::remove(str.begin(), str.end(), '\0'), str.end());
int strLength = str.length(); //Assign the length of str to the variable strLength
char secondChar = str[1];
std::size_t pos;
if (direction == UART_DIRECTION_TX)
{
if (secondChar == 'M' || secondChar == 'm')
{
while ((pos = str.find("\r")) != std::string::npos)
{
str.replace(pos, 1, ",");
}
id(movement_command_sent).publish_state(str);
ESP_LOGD("custom", "Found and forwarded a motor movement command");
}
}
//Do stuff with RX (Only)
else if (direction == UART_DIRECTION_RX)
switch (strLength)
{
case 1: // single charater like 0, 1, -
switch (str[0])
{
case 'F': //esp Is the current controller
id(esp_is_in_control).publish_state(true);
ESP_LOGD("Control", "ESP is confirmed as in control");
break;
case 'D': //Load-Save flag dropped message
id(make_esp_master_controller_script).stop();
id(esp_is_in_control).publish_state(false);
id(make_esp_master_controller_script).execute();
ESP_LOGD("Control", "Load Flag Dropped...Re-executing F");
break;
case '-': // Movement almost complete
id(motion_about_to_stop_3).publish_state(true);
id(motor_movements_done_4).publish_state(false);
ESP_LOGD("custom", "Movement almost complete message");
break;
}
case 2: //Limit switch and input State change reporting like K8,L1,I1
switch (str[0]) {
case 'K': // Limit switch has turned off
switch (str[1]) {
case '1': id(limit_switch_1).publish_state(false); break;
case '2': id(limit_switch_2).publish_state(false); break;
case '3': id(limit_switch_3).publish_state(false); break;
case '4': id(limit_switch_4).publish_state(false); break;
case '5': id(limit_switch_5).publish_state(false); break;
case '6': id(limit_switch_6).publish_state(false); break;
case '7': id(limit_switch_7).publish_state(false); break;
case '8': id(limit_switch_8).publish_state(false); break;
}
ESP_LOGD("custom", "Limit Switch OFF Message");
break;
case 'L': // Limit switch has turned on
switch (str[1]) {
case '1': id(limit_switch_1).publish_state(true); break;
case '2': id(limit_switch_2).publish_state(true); break;
case '3': id(limit_switch_3).publish_state(true); break;
case '4': id(limit_switch_4).publish_state(true); break;
case '5': id(limit_switch_5).publish_state(true); break;
case '6': id(limit_switch_6).publish_state(true); break;
case '7': id(limit_switch_7).publish_state(true); break;
case '8': id(limit_switch_8).publish_state(true); break;
}
ESP_LOGD("custom", "Limit Switch ON Message"); break;
}
break;
case 3: // Response From "Check if Movement Almost Completed"