ESP Switch Delay Control

I everyone. Newbie here, so forgive me if this is obvious. I’ve got a ESPHome setup wired to a relay which controls a light. If the relay goes on and off, the light will just toggle. If the relay stays on for a few milliseconds or more, the light will start to change brightness, on a loop. I’m not able to set the brightness directly but I was wondering if anyone knows if its possible to make the light button control the on and off with a single press but either using a slider to adjust the brightness by adjusting the delay on the relay. I understand that I could make this an additional button with a longer, static delay, however I thought it should be possible to allow for a variable delay. I’ve not used the lamda option but I’m assuming that could play a part here but really not entirely sure. Any help is appreciated! Thanks!

ESPHome Code

switch:
  - platform: gpio
    pin: 5 #D1
    id: relay1
    inverted: yes
    interlock: &interlock_group [relay1]
- platform: template
    name: "Toggle Light"
    icon: "mdi:lightbulb-on"
    turn_on_action:
    - switch.turn_on: relay1
    - delay: 100ms
    - switch.turn_off: relay1