Looping a script based on a variable?

Hi guys, would it be possible to trigger a script and loop it X number of times based on a variable passed to it? at the moment I’m using a separate app on android to integrate my broadlink switch with my google home via IFTTT but i’d like to do it all within Hass if possible. Basically at the moment I can turn the volume of my AVR up by X amount by issuing the command “ok google, turn up the TV volume by X” This then triggers IFTTT which targets a URL which instructs the app on the android phone to send the volume up IR command X times. I know I can use IFTTT in the same way to start a script with IFTTT via the API but what I’d need to do is pass the X variable to the ‘volume up’ script and have it send the IR command for the amount of times specified in the variable. Is this possible?

Hi, I have exactly the same need and would like to know if there is any solution.