Simplify relay handler

This commit is contained in:
Edward Firmo
2024-12-22 02:03:35 +01:00
parent fbc5cb79cc
commit be0fc353f6
2 changed files with 35 additions and 29 deletions

View File

@@ -74,7 +74,7 @@ improv_serial:
id: serial_improv id: serial_improv
logger: logger:
level: INFO level: DEBUG
ota: ota:
platform: esphome platform: esphome

View File

@@ -113,34 +113,40 @@ script:
- id: !extend button_click_event - id: !extend button_click_event
then: then:
- lambda: |- - lambda: |-
if (click_count == 1) { // Single click // Handle only single clicks
if (!bs_multi_touch->state and if (click_count != 1)
!bs_swipe_left->state and return;
!bs_swipe_down->state and
!bs_swipe_right->state) { // Ignore if other events are active // Ignore if other touch events are active
switch (button_id) { if (bs_multi_touch->state ||
case 1: bs_swipe_left->state ||
if (sl_button_1_action->active_index().has_value() and bs_swipe_down->state ||
sl_button_1_action->active_index().value() == 1) bs_swipe_right->state) {
sw_relay_1->toggle(); return;
break; }
case 2:
if (sl_button_2_action->active_index().has_value() and // Toggle relay if corresponding button action is enabled
sl_button_2_action->active_index().value() == 1) switch (button_id) {
sw_relay_2->toggle(); case 1:
break; if (sl_button_1_action->active_index().has_value() and
case 3: sl_button_1_action->active_index().value() == 1)
if (sl_button_3_action->active_index().has_value() and sw_relay_1->toggle();
sl_button_3_action->active_index().value() == 1) break;
sw_relay_3->toggle(); case 2:
break; if (sl_button_2_action->active_index().has_value() and
case 4: sl_button_2_action->active_index().value() == 1)
if (sl_button_4_action->active_index().has_value() and sw_relay_2->toggle();
sl_button_4_action->active_index().value() == 1) break;
sw_relay_4->toggle(); case 3:
break; if (sl_button_3_action->active_index().has_value() and
} sl_button_3_action->active_index().value() == 1)
} sw_relay_3->toggle();
break;
case 4:
if (sl_button_4_action->active_index().has_value() and
sl_button_4_action->active_index().value() == 1)
sw_relay_4->toggle();
break;
} }
- id: show_relay_status - id: show_relay_status