From e0a5ea1cc815e32354c69fe84904cff9ae77c4f4 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 20 Dec 2024 20:39:19 +0100 Subject: [PATCH] Do not toggle if other action is on place Helps with #18 --- ...Ultimate-Easy-ESPHome_core_hw_buttons.yaml | 26 +++++--- ...-Ultimate-Easy-ESPHome_core_hw_relays.yaml | 64 +++++++++---------- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml index f8cd34f..2e8a8a0 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_buttons.yaml @@ -14,6 +14,12 @@ substitutions: invalid_cooldown: 100ms + BUTTON_ACTION_NONE_TEXT: "None" + BUTTON_1_ACTION_TEXT: "Relay 1 (toggle)" + BUTTON_2_ACTION_TEXT: "Relay 2 (toggle)" + BUTTON_3_ACTION_TEXT: "Relay 3 (toggle)" + BUTTON_4_ACTION_TEXT: "Relay 4 (toggle)" + binary_sensor: - id: bs_button_1 name: Button 1 @@ -232,8 +238,9 @@ select: name: Button 1 action platform: template options: - - "None" - - "Relay 1 (toggle)" + - "${BUTTON_ACTION_NONE_TEXT}" + - "${BUTTON_1_ACTION_TEXT}" + initial_option: "${BUTTON_1_ACTION_TEXT}" optimistic: true restore_value: true internal: true @@ -245,23 +252,26 @@ select: name: Button 2 action platform: template options: - - "None" - - "Relay 2 (toggle)" + - "${BUTTON_ACTION_NONE_TEXT}" + - "${BUTTON_2_ACTION_TEXT}" + initial_option: "${BUTTON_2_ACTION_TEXT}" <<: *button_select_action_base - id: sl_button_3_action name: Button 3 action platform: template options: - - "None" - - "Relay 3 (toggle)" + - "${BUTTON_ACTION_NONE_TEXT}" + - "${BUTTON_3_ACTION_TEXT}" + initial_option: "${BUTTON_3_ACTION_TEXT}" <<: *button_select_action_base - id: sl_button_4_action name: Button 4 action platform: template options: - - "None" - - "Relay 4 (toggle)" + - "${BUTTON_ACTION_NONE_TEXT}" + - "${BUTTON_4_ACTION_TEXT}" + initial_option: "${BUTTON_4_ACTION_TEXT}" <<: *button_select_action_base ... diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml index 884f8ef..e096d2a 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core_hw_relays.yaml @@ -15,50 +15,50 @@ binary_sensor: - id: !extend bs_button_1 on_click: then: - - lambda: |- - if (sl_button_1_action->active_index().has_value() and - sl_button_1_action->active_index().value() == 1 and - !bs_multi_touch->state and - !bs_swipe_left->state and - !bs_swipe_down->state and - !bs_swipe_right->state) - sw_relay_1->toggle(); + - if: + condition: + - lambda: return sl_button_1_action->active_index().has_value(); + - lambda: return sl_button_1_action->active_index().value() == 1; + - and: &button_click_no_other_click + - lambda: return not bs_multi_touch->state; + - lambda: return not bs_swipe_left->state; + - lambda: return not bs_swipe_down->state; + - lambda: return not bs_swipe_right->state; + then: + - switch.toggle: sw_relay_1 - id: !extend bs_button_2 on_click: then: - - lambda: |- - if (sl_button_2_action->active_index().has_value() and - sl_button_2_action->active_index().value() == 1 and - !bs_multi_touch->state and - !bs_swipe_left->state and - !bs_swipe_down->state and - !bs_swipe_right->state) - sw_relay_2->toggle(); + - if: + condition: + - lambda: return sl_button_2_action->active_index().has_value(); + - lambda: return sl_button_2_action->active_index().value() == 1; + - and: *button_click_no_other_click + then: + - switch.toggle: sw_relay_2 - id: !extend bs_button_3 on_click: then: - - lambda: |- - if (sl_button_3_action->active_index().has_value() and - sl_button_3_action->active_index().value() == 1 and - !bs_multi_touch->state and - !bs_swipe_left->state and - !bs_swipe_down->state and - !bs_swipe_right->state) - sw_relay_3->toggle(); + - if: + condition: + - lambda: return sl_button_3_action->active_index().has_value(); + - lambda: return sl_button_3_action->active_index().value() == 1; + - and: *button_click_no_other_click + then: + - switch.toggle: sw_relay_3 - id: !extend bs_button_4 on_click: then: - - lambda: |- - if (sl_button_4_action->active_index().has_value() and - sl_button_4_action->active_index().value() == 1 and - !bs_multi_touch->state and - !bs_swipe_left->state and - !bs_swipe_down->state and - !bs_swipe_right->state) - sw_relay_4->toggle(); + - if: + condition: + - lambda: return sl_button_4_action->active_index().has_value(); + - lambda: return sl_button_4_action->active_index().value() == 1; + - and: *button_click_no_other_click + then: + - switch.toggle: sw_relay_4 globals: - id: boot_initialization_relays