From c5eadbbfaa9fe1b2dad369d07737495e9cc5456e Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Tue, 11 Jun 2024 09:13:26 +0200 Subject: [PATCH] User's selectable action for buttons Solves #17 --- ...Ultimate-Easy-ESPHome_addon_ble_proxy.yaml | 2 +- ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml | 96 +++++++++++++++---- 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml index ac6ac1e..de43e5f 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_addon_ble_proxy.yaml @@ -1,7 +1,7 @@ bluetooth_proxy: esp32: - framework: + framework: type: esp-idf sdkconfig_options: CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y" diff --git a/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml b/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml index bec342e..110d9af 100644 --- a/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml +++ b/ESPHome/TX-Ultimate-Easy-ESPHome_core.yaml @@ -37,12 +37,12 @@ binary_sensor: icon: mdi:gesture-tap-box internal: false platform: template - on_press: - then: - - switch.toggle: sw_relay_1 on_click: then: - - lambda: send_event_to_ha->execute("bs_button_1", "click"); + - lambda: |- + if (sl_button_1_action->active_index().has_value() and sl_button_1_action->active_index().value() == 1) + sw_relay_1->toggle(); + send_event_to_ha->execute("bs_button_1", "click"); on_double_click: then: - lambda: send_event_to_ha->execute("bs_button_1", "double_click"); @@ -58,12 +58,12 @@ binary_sensor: icon: mdi:gesture-tap-box internal: true platform: template - on_press: - then: - - switch.toggle: sw_relay_2 on_click: then: - - lambda: send_event_to_ha->execute("bs_button_2", "click"); + - lambda: |- + if (sl_button_2_action->active_index().has_value() and sl_button_2_action->active_index().value() == 1) + sw_relay_2->toggle(); + send_event_to_ha->execute("bs_button_2", "click"); on_double_click: then: - lambda: send_event_to_ha->execute("bs_button_2", "double_click"); @@ -78,12 +78,12 @@ binary_sensor: icon: mdi:gesture-tap-box internal: true platform: template - on_press: - then: - - switch.toggle: sw_relay_3 on_click: then: - - lambda: send_event_to_ha->execute("bs_button_3", "click"); + - lambda: |- + if (sl_button_3_action->active_index().has_value() and sl_button_3_action->active_index().value() == 1) + sw_relay_3->toggle(); + send_event_to_ha->execute("bs_button_3", "click"); on_double_click: then: - lambda: send_event_to_ha->execute("bs_button_3", "double_click"); @@ -98,12 +98,12 @@ binary_sensor: icon: mdi:gesture-tap-box internal: true platform: template - on_press: - then: - - switch.toggle: sw_relay_4 on_click: then: - - lambda: send_event_to_ha->execute("bs_button_4", "click"); + - lambda: |- + if (sl_button_4_action->active_index().has_value() and sl_button_4_action->active_index().value() == 1) + sw_relay_4->toggle(); + send_event_to_ha->execute("bs_button_4", "click"); on_double_click: then: - lambda: send_event_to_ha->execute("bs_button_4", "double_click"); @@ -217,10 +217,6 @@ esphome: auto index = sl_tx_model_gang->active_index(); if (index.has_value()) { uint8_t idx = index.value(); - sw_relay_1->set_internal(false); - sw_relay_2->set_internal(idx < 1); - sw_relay_3->set_internal(idx < 2); - sw_relay_4->set_internal(idx < 3); bs_button_1->set_internal(false); bs_button_2->set_internal(idx < 1); bs_button_3->set_internal(idx < 2); @@ -231,6 +227,14 @@ esphome: bs_button_4->publish_state(false); bs_swipe_left->publish_state(false); bs_swipe_right->publish_state(false); + sl_button_1_action->set_internal(false); + sl_button_2_action->set_internal(idx < 1); + sl_button_3_action->set_internal(idx < 2); + sl_button_4_action->set_internal(idx < 3); + sw_relay_1->set_internal(false); + sw_relay_2->set_internal(idx < 1); + sw_relay_3->set_internal(idx < 2); + sw_relay_4->set_internal(idx < 3); } - priority: 699 then: @@ -1608,6 +1612,58 @@ script: - switch.turn_off: sw_vibration_motor select: + - id: sl_button_1_action + name: Button 1 action + platform: template + options: + - "None" + - "Relay 1 (toggle)" + optimistic: true + restore_value: true + internal: true + entity_category: config + disabled_by_default: false + icon: mdi:dip-switch + + - id: sl_button_2_action + name: Button 2 action + platform: template + options: + - "None" + - "Relay 2 (toggle)" + optimistic: true + restore_value: true + internal: true + entity_category: config + disabled_by_default: false + icon: mdi:dip-switch + + - id: sl_button_3_action + name: Button 3 action + platform: template + options: + - "None" + - "Relay 3 (toggle)" + optimistic: true + restore_value: true + internal: true + entity_category: config + disabled_by_default: false + icon: mdi:dip-switch + + - id: sl_button_4_action + name: Button 4 action + platform: template + options: + - "None" + - "Relay 4 (toggle)" + optimistic: true + restore_value: true + internal: true + entity_category: config + disabled_by_default: false + icon: mdi:dip-switch + - id: sl_relay_light_mode_eu name: Relay light mode platform: template