#################################################################################################### ##### TX Ultimate Easy for ESPHome ##### ##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy ##### #################################################################################################### ##### Purpose: ESPHome Core - Hardware - Buttons ##### #################################################################################################### ##### Author: edwardtfn - https://github.com/edwardtfn - https://buymeacoffee.com/edwardfirmo ##### #################################################################################################### ##### NOTE: ##### ##### - Make changes ONLY if absolutely necessary and you have the required knowledge. ##### ##### - For normal system use, modifications to this file are NOT required. ##### #################################################################################################### --- substitutions: invalid_cooldown: 100ms binary_sensor: - id: bs_button_1 name: Button 1 icon: mdi:gesture-tap-box internal: false platform: template on_click: then: - script.execute: id: button_action component: bs_button_1 event: click on_double_click: then: - script.execute: id: button_action component: bs_button_1 event: double_click on_multi_click: - timing: &long_click-timing - ON for at least 0.8s invalid_cooldown: ${invalid_cooldown} then: - script.execute: id: button_action component: bs_button_1 event: long_click - id: bs_button_2 name: Button 2 icon: mdi:gesture-tap-box internal: true platform: template on_click: then: - script.execute: id: button_action component: bs_button_2 event: click on_double_click: then: - script.execute: id: button_action component: bs_button_2 event: double_click on_multi_click: - timing: *long_click-timing invalid_cooldown: ${invalid_cooldown} then: - script.execute: id: button_action component: bs_button_2 event: long_click - id: bs_button_3 name: Button 3 icon: mdi:gesture-tap-box internal: true platform: template on_click: then: - script.execute: id: button_action component: bs_button_3 event: click on_double_click: then: - script.execute: id: button_action component: bs_button_3 event: double_click on_multi_click: - timing: *long_click-timing invalid_cooldown: ${invalid_cooldown} then: - script.execute: id: button_action component: bs_button_3 event: long_click - id: bs_button_4 name: Button 4 icon: mdi:gesture-tap-box internal: true platform: template on_click: then: - script.execute: id: button_action component: bs_button_4 event: click on_double_click: then: - script.execute: id: button_action component: bs_button_4 event: double_click on_multi_click: - timing: *long_click-timing invalid_cooldown: ${invalid_cooldown} then: - script.execute: id: button_action component: bs_button_4 event: long_click script: - id: button_action mode: parallel parameters: component: string event: string then: # There's nothing here so far # Extended by: # - core_api - id: buttons_release mode: restart then: - if: condition: binary_sensor.is_on: bs_button_1 then: - binary_sensor.template.publish: id: bs_button_1 state: OFF # yamllint disable-line rule:truthy - if: condition: binary_sensor.is_on: bs_button_2 then: - binary_sensor.template.publish: id: bs_button_2 state: OFF # yamllint disable-line rule:truthy - if: condition: binary_sensor.is_on: bs_button_3 then: - binary_sensor.template.publish: id: bs_button_3 state: OFF # yamllint disable-line rule:truthy - if: condition: binary_sensor.is_on: bs_button_4 then: - binary_sensor.template.publish: id: bs_button_4 state: OFF # yamllint disable-line rule:truthy - id: !extend touch_on_multi_touch_release then: - script.execute: buttons_release - id: !extend touch_on_press then: - script.execute: id: touch_on_press_buttons touch_x: !lambda return touch_x; - id: touch_on_press_buttons mode: restart parameters: touch_x: uint8_t then: - lambda: |- auto model_index = sl_tx_model_gang->active_index(); if (model_index.has_value()) { uint8_t model_idx = model_index.value() + 1; switch (model_idx) { case 1: // 1 Gang bs_button_1->publish_state(true); break; case 2: // 2 Gang if (touch_x <= 5) bs_button_1->publish_state(true); else bs_button_2->publish_state(true); break; case 3: // 3 Gang if (touch_x <= 3) bs_button_1->publish_state(true); else if (touch_x <= 7) bs_button_2->publish_state(true); else bs_button_3->publish_state(true); break; case 4: // 4 Gang if (touch_x <= 2) bs_button_1->publish_state(true); else if (touch_x <= 5) bs_button_2->publish_state(true); else if (touch_x <= 8) bs_button_3->publish_state(true); else bs_button_4->publish_state(true); break; } } - id: !extend touch_on_release then: - script.execute: buttons_release - id: !extend touch_swipe_left then: - script.execute: buttons_release - id: !extend touch_swipe_right then: - script.execute: buttons_release select: - &button_select_action_base 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)" <<: *button_select_action_base - id: sl_button_3_action name: Button 3 action platform: template options: - "None" - "Relay 3 (toggle)" <<: *button_select_action_base - id: sl_button_4_action name: Button 4 action platform: template options: - "None" - "Relay 4 (toggle)" <<: *button_select_action_base ...