I assume you are using ZHA. You wouldnt have the questiions if under zigbee2mqtt.
For a ZHA script see: Zigbee Neo Siren AB02B2-v2 trying to switch melody - #8 by jerrm
But agree with @Neil_Brownlee, adding a delay between steps will probably help reliability. The z2m version of my script adds a delay.
I moved all my stuff to z2m and never went back to clean up the ZHA script.