Performance - ESP home trigger script or create automation

Hi, I would like to ask what is better approach, I have switch based on esp home and I would like to perform some actions based on single click (toggle light), double click (toggle light color) and long press (toggle brightness). Currently I have implemented it in the esp home it self, so it triggeres script, this way it should be probably the fastest way how to do it but it has some disadvantages. I plan to do the same for all my switches at home but that would mean that each switch would have different esp home configuration. I could also create three entities which would turn on and of for single press, double press and long press and than create automations based on that. Any advice what would be the best aproach?

CURRENT CONFIG:

# Configuration
substitutions:
  name: esp-switch-2g-8

esphome:
  name: ${name}

esp8266:
  board: esp8285
  restore_from_flash: true

# Enable logging
logger:
  #Turn off RX TX
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret esp_home_api_password

ota:
  password: !secret esp_home_ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name}.o"
    password: !secret esp_home_fallback_wifi_password

captive_portal:

output:
  - platform: gpio
    pin: GPIO4
    id: relay1
  - platform: gpio
    pin: GPIO5
    id: relay2

switch:
  - platform: output
    name: "${name} relé 1"
    icon: mdi:toggle-switch-variant
    restore_mode: RESTORE_DEFAULT_ON
    output: relay1
    id: switch_relay1
  - platform: output
    name: "${name} relé 2"
    icon: mdi:toggle-switch-variant
    restore_mode: RESTORE_DEFAULT_ON
    output: relay2
    id: switch_relay2

binary_sensor:
  # Wired switch 1
  - platform: gpio
    name: "${name} vypínač 1"
    icon: mdi:light-switch
    id: the_switch_1
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      #Single click
      - timing:
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_pracovne_klik
      # Double click
      - timing:
        - ON for at most 0.5s
        - OFF for at most 0.2s
        - ON for at most 0.5s
        - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_pracovne_dvojklik
      #Long click
      - timing:
        - ON for at least 1s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_pracovne_dlouhy_klik
      #Reset
      - timing:
          - ON for at least 5s
        then:
          - switch.toggle: switch_relay1

  # Wired switch 2
  - platform: gpio
    name: "${name} vypínač 2"
    icon: mdi:light-switch
    id: the_switch_2
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      # Single click
      - timing:
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_loznici_klik
      # Double click
      - timing:
          - ON for at most 0.5s
          - OFF for at most 0.2s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_loznici_dvojklik
      # Long click
      - timing:
        - ON for at least 1s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.svetlo_v_loznici_dlouhy_klik
      # Reset click
      - timing:
          - ON for at least 5s
        then:
          - switch.toggle: switch_relay2

  # Button on mini switch
  - platform: gpio
    name: "${name} tlačítko"
    icon: mdi:gesture-tap-button
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: switch_relay1
          - switch.toggle: switch_relay2

  - platform: status
    name: "${name} stav"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${name} IP adresa"
      icon: mdi:ip-network

sensor:
  - platform: wifi_signal
    name: "${name} signál"
    update_interval: 10s
  
  - platform: uptime
    name: "${name} doba běhu"

time:
  - platform: sntp
    id: my_time

I have moved the common configuration to template on esphome side so now I just need to specify the scripts in config for each switch. I am still open for any advices how this should be implemented.

TEMPLATE:

esphome:
  name: ${name}

esp8266:
  board: esp8285
  restore_from_flash: true

# Enable logging
logger:
  #Turn off RX TX
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret esp_home_api_password

ota:
  password: !secret esp_home_ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${name}.o"
    password: !secret esp_home_fallback_wifi_password

captive_portal:

output:
  - platform: gpio
    pin: GPIO4
    id: relay1
  - platform: gpio
    pin: GPIO5
    id: relay2

switch:
  - platform: output
    name: "${name} relé 1"
    icon: mdi:toggle-switch-variant
    restore_mode: RESTORE_DEFAULT_ON
    output: relay1
    id: switch_relay1
  - platform: output
    name: "${name} relé 2"
    icon: mdi:toggle-switch-variant
    restore_mode: RESTORE_DEFAULT_ON
    output: relay2
    id: switch_relay2

light:
  - platform: status_led
    name: "${name} stavová LED"
    icon: mdi:led-on
    entity_category: config
    pin:
      number: GPIO12
      inverted: true

binary_sensor:
  # Wired switch 1
  - platform: gpio
    name: "${name} vypínač 1"
    icon: mdi:light-switch
    id: the_switch_1
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      #Single press
      - timing:
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch1_single_press}
      # Double press
      - timing:
        - ON for at most 0.5s
        - OFF for at most 0.2s
        - ON for at most 0.5s
        - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch1_double_press}
      #Long press
      - timing:
        - ON for at least 1s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch1_long_press}
      #Reset
      - timing:
          - ON for at least 5s
        then:
          - switch.toggle: switch_relay1

  # Wired switch 2
  - platform: gpio
    name: "${name} vypínač 2"
    icon: mdi:light-switch
    id: the_switch_2
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      # Single press
      - timing:
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch2_single_press}
      # Double press
      - timing:
          - ON for at most 0.5s
          - OFF for at most 0.2s
          - ON for at most 0.5s
          - OFF for at least 0.2s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch2_double_press}
      # Long click
      - timing:
        - ON for at least 1s
        then:
          - homeassistant.service:
              service: script.turn_on
              data:
                entity_id: script.${switch2_long_press}
      # Reset press
      - timing:
          - ON for at least 5s
        then:
          - switch.toggle: switch_relay2

  # Button on mini switch
  - platform: gpio
    name: "${name} tlačítko"
    icon: mdi:gesture-tap-button
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: true
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: switch_relay1
          - switch.toggle: switch_relay2

  - platform: status
    name: "${name} stav"

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${name} IP adresa"
      icon: mdi:ip-network

sensor:
  - platform: wifi_signal
    name: "${name} signál"
    update_interval: 10s
  
  - platform: uptime
    name: "${name} doba běhu"

time:
  - platform: sntp
    id: my_time

DEVICE:

<<: !include templates/template-esp-button-2g.yaml

# Configuration
substitutions:
  name: esp-switch-2g-8

  switch1_single_press: svetlo_v_pracovne_klik
  switch1_double_press: svetlo_v_pracovne_dvojklik
  switch1_long_press: svetlo_v_pracovne_dlouhy_klik

  switch2_single_press: svetlo_v_loznici_klik
  switch2_double_press: svetlo_v_loznici_dvojklik
  switch2_long_press: svetlo_v_loznici_dlouhy_klik