Touch lamp emulator - one button hold

I have touch switches - currently upgrading to ESP touch sensors and PCA9685 PWM controlling the lights.
I was after a solution to touch on/off and hold to gradually raise to full brightness then continue to dim if held. After much searching I have hobbled together the following solution.
NB: I have only had HA running for 2 weeks and appreciate any optimizations or constructive thoughts.
Pre-requesites:
Trigger different actions on a single, double or double click on a binary sensor from Slashback
GitHub - snarky-snark/home-assistant-variables: A custom Home Assistant component for declaring and setting generic variable entities dynamically.

Features:
Dimming:
If starting from brightness 0, brightness will be set to a minimum threshhold.
Dimming resumes in the same direction when button is re-held.
Accelerated stepping when the light approaches fully on to give a more even effect.
configuation.yaml

var:
  lup_001:
    friendly_name: "Light 1 Step setting"
    initial_value: 2
    icon: mdi:debug-step-out
  lup_002:
    friendly_name: "Light 2 Step setting"
    initial_value: 3
    icon: mdi:debug-step-out

automation:

alias: test 1
description: ""
use_blueprint:
  path: >-
    slashback/trigger-different-actions-on-a-single-double-or-double-click-on-a-binary-sensor.yaml
  input:
    switch_id: binary_sensor.sw1_tp0
    short_click_action:
      - service: light.toggle
        data:
          brightness_pct: 100
        target:
          entity_id: light.test_light1
    long_click_action:
      - service: script.dimmer
        data:
          entity: var.lup_001
          ln: light.test_light1
          sn: binary_sensor.sw1_tp0
          lt: 22
    delay: 0.5

script:

alias: Dimmer
fields:
  sn:
    description: Switch Name
  ln:
    description: Light Name
  entity:
    description: Light step variable (configuration.yaml)
  lt:
    description: Light visible threshhold
sequence:
  - service: light.turn_on
    target:
      entity_id: "{{ ln }}"
    data:
      transition: 0
      brightness: >
        {% set cb = state_attr(ln, 'brightness')|int(0) %} {% if cb == 0 %}
          {{ lt }}
        {% else %}
          {{ cb }}
        {% endif %}
  - repeat:
      while:
        - condition: template
          value_template: "{{ is_state(sn, 'on') }}"
      sequence:
        - service: var.set
          data:
            entity_id: "{{ entity }}"
            value: >
              {% set cb = state_attr(ln, 'brightness')|int(0) %}
              {% set x = (states(entity)|int(0)) %} {% if cb == 255 or cb < (lt|int(0)) %} 
                {{0 - x}}
              {% else %}
                {{x}}
              {% endif %}
        - service: light.turn_on
          target:
            entity_id: "{{ ln }}"
          data:
            transition: 0
            brightness_step: >
              {{ (states(entity)|float(0) * (state_attr(ln,'brightness')|float(0)/95+1)|int(0)) }}
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 35
mode: parallel
icon: mdi:lightbulb-on-50
max: 10