Help converting a custom component to an external component

I’m running esphome on a Sonoff TX Ultimate that requires a custom lambda function to map the touchpad to two buttons.

Since custom components were removed from esphome at the end of 2024, I need to move the following custom component into an external component but I have no clue how to do this.

Any help would be appreciated. Here is the function in question.

binary_sensor:
  - platform: custom
    lambda: |- 
        auto touch_panel = new touch_panel::TouchPanel(id(uart_bus));
        App.register_component(touch_panel);
        return {
          touch_panel->left,
          touch_panel->right,
          touch_panel->middle,
          touch_panel->two_finger,
          touch_panel->dragged_ltr,
          touch_panel->dragged_rtl,
        };

The full code is available in this github repo.

If that’s the case, you might want to go with this approach (like many of us here):

2 Likes

Thanks for the guidance @Karosm . I saw that and will use it if necessary but it’d be great to see if it can be migrated to an external component.

Out of my competences. Good luck anyway!