Alarm Table Filter Script

Hello All!

Disclaimer, I’m VERY new to Ignition, but not HMI programming. I have been steadily working my way through the university training videos/tests, and trying to apply some version of each lesson in a sample project. I’m currently stuck on the Alarm Table Filtering based on associated tags…

When I apply my script, instead of filtering the alarms, it makes them ALL disappear. I’ve tried filtering on both “priority” and a custom tag called “group”. My script for priority is as follows:

def filterAlarm(self, alarmEvent):

Priority = alarmEvent.get("priority")

if Priority == "Critical" or Priority == "High":
	return True
else:
        return False

image

The idea is to have 2 fault banners at the top of my display. One will ONLY show the higher level alarms, the other showing ONLY medium-low level. However, every alarm is disappearing when the script is applied. When I disable the filter script, the alarms come back immediately. This exact case is happening when using the custom tag “group”.

Any assistance is appreciated,
Thank you!

Why not use the built-in priority filters ?

image

About your issue: You're comparing a priority object with a string. This will not work.
Two solutions here:

  • get the string value of the priority (or its int value):
alarmEvent.priority.toString() == "Critical"
alarmEvent.priority.intValue() == 4
  • use the class attributes (I suggest using this):
alarmEvent.priority == alarmEvent.priority.Critical

example I ran in a script console:

data = system.alarm.queryStatus()

priority = data[0].priority

priority.toString() == "High"
priority.intValue >= 2
priority < data[0].priority.Critical

True
True
True

Note: You can use the >, >=, <= and < operators too when using the int value or the class attributes.

1 Like

Converting the .get(“Priority”) to a string before my compare worked.

def filterAlarm(self, alarmEvent):

Priority = alarmEvent.get("Priority").toString()

if Priority == "Critical" or Priority == "High":
	return True
else:
    return False

I dont have the filters you showed… perhaps I have the wrong properties open…? Trying to find one in view that actually opens hasnt been successful either… but that would be FAR easier than a script…


That’s because you’re using vision, and I’m using perspective.
I don’t know anything about vision.

I’d suggest reworking your script like this:

priority = alarmEvent.priority
return priority >= priority.High

You don’t need the if/else statement, as the comparison already returns a boolean.
And using the class attribute allows you to use >= and check for both high and critical alarms at once, instead of having 2 conditions.

Great suggestion!

Thank you!