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?
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?
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. You can edit your post by clicking the pencil icon in the bottom right.
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 and system.util.sendMessage. There are several posts on the forum regarding using both to send messages to active perspective sessions.