How can I make an output pulse 1, 2 or 3 times (one shot)

Hi

I have a Sonoff which I have modified to be a wifi remote alarm panel device.

I have a green LED that shows when the alarm panel is Armed and a Sounder (Buzzer) which is activated when the alarm has be triggered.

I would like the sounder give 1 short beep when the green LED goes “Off” (giving me an audible indication that the alarm panel is Unset)

And give 3 short beeps when the Green LED comes “On”.

I have found code to make a output pulse constantly pulse on & off but I need a one shot

Kind regards, Dave