11---
2- esphome :
3- on_boot :
4- then :
5- - component.suspend : tap_timer
6-
72substitutions :
83 spi_data_rate : 200kHz
94 # spi_data_rate: 1Mhz #TODO: decrease this to increase reliability for long cable runs
@@ -18,6 +13,10 @@ globals:
1813 type : int
1914 restore_value : no
2015 initial_value : ' 0'
16+ - id : global_error
17+ type : bool
18+ restore_value : no
19+ initial_value : ' false'
2120
2221interval :
2322 - id : tap_timer
@@ -81,14 +80,15 @@ pn532_spi:
8180 - delay : 500ms
8281 - lambda : |-
8382 id(tap_timer).setup();
84- if(id(global_tap_counter) == 5){
85- id(set_led_rainbow).execute();
86- } else{
87- for(int i = 0; i < id(global_tap_counter); i++) {
88- id(set_led_green).execute(i);
89- }
83+ if(id(global_error) == false) {
84+ if(id(global_tap_counter) == 5){
85+ id(set_led_rainbow).execute();
86+ } else{
87+ for(int i = 0; i < id(global_tap_counter); i++) {
88+ id(set_led_green).execute(i);
89+ }
90+ }
9091 }
91-
9292 - delay : 500ms
9393 - light.turn_on :
9494 id : neopixel_light
@@ -99,6 +99,7 @@ pn532_spi:
9999 - if :
100100 condition :
101101 and :
102+ - lambda : ' return id(global_error) == false;'
102103 - lambda : ' return id(global_tap_counter) > 0;'
103104 - ${mqtt}.connected
104105 - lambda : ' return id(filament_raw_data0).state != "";'
@@ -113,6 +114,9 @@ pn532_spi:
113114 # payload: !lambda "return bambulabs::generate_mqtt_payload( id(filament_raw_data0).state, 255, 254 );"
114115 payload : !lambda "return bambulabs::generate_mqtt_payload( id(filament_raw_data0).state, id(global_tap_counter) == 5 ? 255 : 0, id(global_tap_counter) == 5 ? 254: id(global_tap_counter) - 1 );"
115116 - lambda : ' id(filament_raw_data0).publish_state("");'
117+ - globals.set :
118+ id : global_error
119+ value : ' false'
116120
117121
118122 on_tag :
@@ -122,6 +126,7 @@ pn532_spi:
122126 state : ON
123127 - lambda : |-
124128 bool is_valid_openspool = false;
129+ id(global_error) = false;
125130 std::string payload;
126131
127132 if (tag.has_ndef_message()) {
@@ -176,6 +181,7 @@ pn532_spi:
176181 } else {
177182 id(tap_timer).stop_poller();
178183 id(tap_timer).setup();
184+ id(global_error) = true;
179185 for(int i = 0; i < 4; i++) {
180186 id(set_led_red).execute(i);
181187 }
0 commit comments