Optimizing Touch button remote for FAN Speed controller in HA

Hi Folks,

I have ESP32 based fan speed controller which parallels a couple of high voltage capacitors through relays to get me 5-speed control. The relays are controlled through a couple of scripts in HA to determine the speeds and within HA I control them with input booleans on UI which in turn trigger automation and eventually the scripts to control the fan speed. While this works perfectly well but my wife and kid found this a bit cumbersome to open the app on IPAD every time to control the fan/lights in the room.

So I build a small switchboard with a couple of touch sensors capable of controlling all the switches in the room. Thinking 5 separate touch buttons for fan speed to be a bit much, I decided to go with a two-button up and down approach. These up and down touch buttons trigger automation which in turn updates a counter/automation which in turn triggers the scripts to control the relay and fan speed. All is well so far but my kid being a kid and impatient she pushes the buttons quickly to get to the desired speed and this messes up the controller automation somehow leading to some of the undesired relays left on/off. My scripts switch these relays in different combinations and at 1second delays to ensure they don’t overlap and I believe the fast touch button toggling by my daughter is causing some of the unwanted relays to stay on/off causing unpredictable speeds. To wrap up if I press the touch button once and wait for the script to finish executing and then select the next speed it works fine.

Is there a way in HA to avoid the scripts/automation running in parallel and messing up the relay combination.

Regards
Anil

can anyone help on this topic?

for anyone interested in the solution, here is what I figured out.

My scripts takes about 2Secs to execute so triggering the touch button faster than that, home assistant tries to execute multiple scripts which makes the fan controller act funny so used the delayed_off function from ESPHOME which ensures intermittent presses are not registered.

binary_sensor:
  - platform: gpio
    pin: GPIO34
    name: "up"
    filters:
     delayed_off: 1600ms