Sounding on new alarms

I have an alarm status table that can have multiple priority alarms at once. i want a sound file to play once every time a new alarm with priority high or critical comes on. i have dragged an audio file and sourced it with a path. to test this i created a button and pressing the button plays the audio. but i am unable to write a script that can execute my logic to play the audio when a new high or critical alarm comes on. i am new to this so i am not sure what i am doing wrong. i have tried adding a script with 1 seconds timer to gateway events as project script

played_ids = set()

def poll():
st = system.alarm.queryStatus(state=['ActiveUnacked'], priority=['High','Critical'])
new = {str(r['EventId']) for r in st} - played_ids
for eid in new:
system.perspective.sendMessage('playAlarmAudio', payload={'eid': eid}, scope='session')
played_ids.update(new)

and then added the following script to root > message handler.

audio = self.getChild("Audio") # rename if different
audio.props.playing = False
def _start():
audio.props.playing = True
system.util.invokeLater(_start, 50)

I got these scripts from chatgpt and i am still getting used to python. can anyone point out what am i doing wrong?

2 posts were merged into an existing topic: Play Alarm Sound