# Play Alarm Sound

**URL:** <https://forum.inductiveautomation.com/t/play-alarm-sound/110177>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [August 26, 2025, 3:57pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177 "2025-08-26T15:57:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjaved1](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@mjaved1](https://forum.inductiveautomation.com/u/mjaved1)\
**Post date:** [August 26, 2025, 3:57pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177/1 "2025-08-26T15:57:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mjaved1](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@mjaved1](https://forum.inductiveautomation.com/u/mjaved1)\
**Post date:** [August 26, 2025, 5:43pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177/2 "2025-08-26T17:43:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 26, 2025, 5:47pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177/3 "2025-08-26T17:47:13Z")

</div>

Please avoid creating multiple topics related to the same issue. It can cause confusion between the 2 and help from users can get split between 2 locations, adding to the confusion. Please just edit your original topic to add additional info/questions, or reply to your original topic.

And be _patient_. This forum is populated with _volunteers_. If you don't get an answer in a few **days** , a self-reply to gain more attention is reasonable.

Also, please post scripts as preformatted text. It preserves the indentation that is important to python, and helps to speed up troubleshooting by others. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). You can edit your post by clicking the pencil icon in the bottom right.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 26, 2025, 5:57pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177/4 "2025-08-26T17:57:26Z")

</div>

Some points on your polling logic:

- Don't stringify the event ids, leave them as is.

- You are sending a message for _every_ new item in the list. Avoid this, and instead get a total count of new items and pass that as part of the message payload

- Personally, I would only play the sound once on new events detected, instead of playing a sound for each new event. Imagine getting 100 new events at once.

- You are attempting to use `system.perspective.sendMessage` in a gateway context without providing a session Id. Look up the difference in scope and use cases of [`system.perspective.sendMessage`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-perspective/system-perspective-sendMessage) and [`system.util.sendMessage`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-sendMessage). There are several posts on the forum regarding using both to send messages to active perspective sessions.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 26, 2025, 6:01pm UTC](https://forum.inductiveautomation.com/t/play-alarm-sound/110177/5 "2025-08-26T18:01:39Z")

</div>

You may also find this of interest.

> [@\[feature-12986, 15300\]Unacknowledged Alarm Sound](https://forum.inductiveautomation.com/t/feature-12986-15300-unacknowledged-alarm-sound/25460/3):
>
> Use an invisible IFrame, and bind src to (don’t take this literally wink ): if(something = 1, 'http://path/to/some/noise.mp3', '' )
