If Alarm Exists

I can use this function to determine if a tag exists,
https://docs.inductiveautomation.com/display/DOC81/system.tag.exists

Is there anything quick and easy to see if an alarm exists within a specified tag?

You can use /system.tag.getConfiguration which will return a list of tag dictionaries. Then you just need to check for “alarms”

Something like this:

path = '[default]New Tag'
config = system.tag.getConfiguration(path, False)

try:
	config[0]['alarms']
except:
	print 'no alarms'

Thanks @josborn I was aware I could do that, was curious if there was another way. Appreciate the response.

No prob! I suppose you could export all your tax as xml or json and then iterate through and return the ones that have alarms.

@jlandwerlen You can use system.tag.exists with the path to the alarms property from the tag and that path would be [tag_provider]tagpath/Alarms/Alarm_Name.

For example with a memory tag called "Test" and an alarm named "Test Alarm", the following returns True.
system.tag.exists("[default]Test/Alarms/Test Alarm")

@josborn Keep in mind that the system.tag.getConfiguration method will work well for individual tags like a single memory or OPC tag; however, if you use your method on a tag in a UDT instance, you would print "no alarms" even if the tag has alarms. The reason the UDT instance does not include the "alarms" property in its config is because it is inherited from the UDT definition. If you were to make an edit on the alarm on the UDT tags, then you will see the "alarms" property returned by getConfiguration because you will have created an override on the alarm property making it different from the UDT definition.

In the manual section for system.tag.getConfiguration, we mention this here:

The configurations returned by this function can only contain properties that are not using their default values. Thus, if a property on a tag has not been modified from its default value, then it will be included in the returned list.

2 Likes

Good point, and that’s exactly what i did, test on a single memory tag. Your answer is much better, i didn’t know you could use system.tag.exists() that way.

Why the difference between the alarm name and the tag path ? I mean, the underscore in the alarm name is replaced by a space in the tag path. Is this a typo, or is there some black magic at work there ?

Thanks, I didn't even think to try that. Great to know.

@pascal.fragnoud No dark sorcery here. Just a person and his typos. :slight_smile: You’re correct. The alarm names should match.