#################################################################################################### ##### TX Ultimate Easy for ESPHome ##### ##### Repository: https://github.com/edwardtfn/TX-Ultimate-Easy ##### #################################################################################################### ##### Purpose: ESPHome Core - Hardware - Touch panel ##### #################################################################################################### ##### 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: TOUCH_POSITION_MAX_VALUE: '10' # Maximum touch position value returned by the touch pad via uart binary_sensor: - id: bs_multi_touch name: Multi-touch icon: mdi:gesture-two-tap internal: false platform: template on_click: then: - lambda: send_event_to_ha->execute("multi_touch", "multi_touch"); - id: bs_swipe_left name: Swipe left icon: mdi:gesture-swipe-left internal: true platform: template on_click: then: - lambda: send_event_to_ha->execute("swipe", "left"); - id: bs_swipe_right name: Swipe right icon: mdi:gesture-swipe-right internal: true platform: template on_click: then: - lambda: send_event_to_ha->execute("swipe", "right"); - id: bs_swipe_up name: Swipe up icon: mdi:gesture-swipe-up internal: true platform: template on_click: then: - lambda: send_event_to_ha->execute("swipe", "up"); - id: bs_swipe_down name: Swipe down icon: mdi:gesture-swipe-down internal: true platform: template on_click: then: - lambda: send_event_to_ha->execute("swipe", "down"); external_components: - source: type: git url: https://github.com/edwardtfn/TX-Ultimate-Easy ref: v${version} refresh: 1h components: - tx_ultimate_easy number: - id: nr_touch_duration name: Touch duration icon: mdi:timer-cog-outline unit_of_measurement: ms # mode: box internal: false entity_category: config platform: template min_value: 10 max_value: 1500 step: 1 initial_value: 250 optimistic: true restore_value: true script: - id: !extend boot_initialize then: - script.execute: boot_initialize_touch - id: boot_initialize_touch mode: restart then: - wait_until: condition: - lambda: return sl_tx_model_format->active_index().has_value(); - lambda: |- const bool is_model_us = sl_tx_model_format->active_index().has_value() and sl_tx_model_format->active_index().value() == 1; bs_multi_touch->publish_state(false); bs_swipe_down->publish_state(false); bs_swipe_down->set_internal(!is_model_us); bs_swipe_left->publish_state(false); bs_swipe_left->set_internal(is_model_us); bs_swipe_right->publish_state(false); bs_swipe_right->set_internal(is_model_us); bs_swipe_up->publish_state(false); bs_swipe_up->set_internal(!is_model_us); - id: touch_on_multi_touch_release mode: restart then: # Extended by: # - HW Buttons # - HW Vibration - script.execute: touch_on_multi_touch_release_touch - id: touch_on_multi_touch_release_touch mode: restart then: - lambda: bs_multi_touch->publish_state(true); - delay: !lambda return nr_touch_duration->state; - lambda: bs_multi_touch->publish_state(false); - id: touch_on_press mode: restart parameters: touch_position: uint8_t then: # Extended by: # - HW Buttons # - HW Vibration - id: touch_on_release mode: restart then: # Extended by: # - HW Buttons # - HW Vibration - script.execute: touch_swipe_turn_off_binary_sensor - id: touch_swipe_left mode: restart then: # Extended by: # - HW Buttons - script.execute: touch_swipe_left_touch - id: touch_swipe_left_touch mode: restart then: - binary_sensor.template.publish: id: bs_swipe_left state: ON # yamllint disable-line rule:truthy - delay: !lambda return nr_touch_duration->state; - script.execute: touch_swipe_turn_off_binary_sensor - id: touch_swipe_right mode: restart then: # Extended by: # - HW Buttons - script.execute: touch_swipe_right_touch - id: touch_swipe_right_touch mode: restart then: - binary_sensor.template.publish: id: bs_swipe_right state: ON # yamllint disable-line rule:truthy - delay: !lambda return nr_touch_duration->state; - script.execute: touch_swipe_turn_off_binary_sensor - id: touch_swipe_turn_off_binary_sensor mode: restart then: - if: condition: binary_sensor.is_on: bs_swipe_left then: - binary_sensor.template.publish: id: bs_swipe_left state: OFF # yamllint disable-line rule:truthy - if: condition: binary_sensor.is_on: bs_swipe_right then: - binary_sensor.template.publish: id: bs_swipe_right state: OFF # yamllint disable-line rule:truthy switch: - id: sw_touch_panel_power name: Touch panel - Power platform: gpio pin: number: GPIO5 inverted: true restore_mode: ALWAYS_ON internal: false entity_category: config tx_ultimate_easy: id: tx_ultimate uart: uart_touch on_long_touch_release: - lambda: |- const uint8_t touch_position = static_cast(touch.x); if (touch_position > ${TOUCH_POSITION_MAX_VALUE}) { // Check for valid range ESP_LOGE("tx_ultimate_easy", "Invalid long-touch position: %" PRIu8, touch_position); } else { ESP_LOGI("tx_ultimate_easy", "Long-touch released at position %" PRIu8, touch_position); } on_multi_touch_release: - lambda: ESP_LOGI("tx_ultimate_easy", "Multi-touch released"); - script.execute: touch_on_multi_touch_release on_press: - lambda: |- const uint8_t touch_position = static_cast(touch.x); if (touch_position > ${TOUCH_POSITION_MAX_VALUE}) { // Check for valid range ESP_LOGE("tx_ultimate_easy", "Invalid touch position: %" PRIu8, touch_position); } else { ESP_LOGI("tx_ultimate_easy", "Pressed at position %" PRIu8, touch_position); touch_on_press->execute(touch_position); } on_release: - lambda: ESP_LOGI("tx_ultimate_easy", "Released"); - script.execute: touch_on_release on_swipe_left: - lambda: ESP_LOGI("tx_ultimate_easy", "Swipe left"); - script.execute: touch_swipe_left on_swipe_right: - lambda: ESP_LOGI("tx_ultimate_easy", "Swipe right"); - script.execute: touch_swipe_right on_touch_event: - lambda: |- ESP_LOGD("tx_ultimate_easy", "Touch event:"); ESP_LOGD("tx_ultimate_easy", " State: %i (%s)", touch.state, touch.state_str.c_str()); ESP_LOGD("tx_ultimate_easy", " Position: %i", touch.x); uart: - id: uart_touch tx_pin: GPIO19 rx_pin: GPIO22 baud_rate: 115200 ...