Cancel a ongoing Action/Automation

Lets say I make a automation that dim up the light within a 5 minute interval.

Then lets sat after 3 minutes I change my mind and want to turn off the lights, that will not work, because the ongoing job is just turning it on again and I have to wait out the time before I turn it of.

Is it possible to cancel ongoing tasks like this?

Move the automation action to a script and use the automation to call the script. Then create an entity button or something that calls the script.turn_off service targeting the script when tapped.