User's selectable action for buttons

Solves #17
This commit is contained in:
Edward Firmo
2024-06-11 09:13:26 +02:00
parent 999a24c2cb
commit c5eadbbfaa
2 changed files with 77 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
bluetooth_proxy: bluetooth_proxy:
esp32: esp32:
framework: framework:
type: esp-idf type: esp-idf
sdkconfig_options: sdkconfig_options:
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y" CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST: "y"

View File

@@ -37,12 +37,12 @@ binary_sensor:
icon: mdi:gesture-tap-box icon: mdi:gesture-tap-box
internal: false internal: false
platform: template platform: template
on_press:
then:
- switch.toggle: sw_relay_1
on_click: on_click:
then: 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: on_double_click:
then: then:
- lambda: send_event_to_ha->execute("bs_button_1", "double_click"); - lambda: send_event_to_ha->execute("bs_button_1", "double_click");
@@ -58,12 +58,12 @@ binary_sensor:
icon: mdi:gesture-tap-box icon: mdi:gesture-tap-box
internal: true internal: true
platform: template platform: template
on_press:
then:
- switch.toggle: sw_relay_2
on_click: on_click:
then: 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: on_double_click:
then: then:
- lambda: send_event_to_ha->execute("bs_button_2", "double_click"); - lambda: send_event_to_ha->execute("bs_button_2", "double_click");
@@ -78,12 +78,12 @@ binary_sensor:
icon: mdi:gesture-tap-box icon: mdi:gesture-tap-box
internal: true internal: true
platform: template platform: template
on_press:
then:
- switch.toggle: sw_relay_3
on_click: on_click:
then: 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: on_double_click:
then: then:
- lambda: send_event_to_ha->execute("bs_button_3", "double_click"); - lambda: send_event_to_ha->execute("bs_button_3", "double_click");
@@ -98,12 +98,12 @@ binary_sensor:
icon: mdi:gesture-tap-box icon: mdi:gesture-tap-box
internal: true internal: true
platform: template platform: template
on_press:
then:
- switch.toggle: sw_relay_4
on_click: on_click:
then: 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: on_double_click:
then: then:
- lambda: send_event_to_ha->execute("bs_button_4", "double_click"); - lambda: send_event_to_ha->execute("bs_button_4", "double_click");
@@ -217,10 +217,6 @@ esphome:
auto index = sl_tx_model_gang->active_index(); auto index = sl_tx_model_gang->active_index();
if (index.has_value()) { if (index.has_value()) {
uint8_t idx = index.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_1->set_internal(false);
bs_button_2->set_internal(idx < 1); bs_button_2->set_internal(idx < 1);
bs_button_3->set_internal(idx < 2); bs_button_3->set_internal(idx < 2);
@@ -231,6 +227,14 @@ esphome:
bs_button_4->publish_state(false); bs_button_4->publish_state(false);
bs_swipe_left->publish_state(false); bs_swipe_left->publish_state(false);
bs_swipe_right->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 - priority: 699
then: then:
@@ -1608,6 +1612,58 @@ script:
- switch.turn_off: sw_vibration_motor - switch.turn_off: sw_vibration_motor
select: 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 - id: sl_relay_light_mode_eu
name: Relay light mode name: Relay light mode
platform: template platform: template