How to get active alarm count of all tags in a folder?

I would like to get a count of all active alarms (both ack and non-ack) in tags in a particular folder called "FAB". I have one alarm that is set to true and it is flashing on the standard alarm table in my HMI so I know the alarming is working.
But the tag path filter seems to be broken or I am using it wrong as it always returns zero alarms unless I make the tagpath filter = "*".

This code returns 0

pathValue = "[default]FAB/*"
alms = system.alarm.queryStatus(path = pathValue, state = [2,3])
print len(alms)

this code returns 1

pathValue = "*"
alms = system.alarm.queryStatus(path = pathValue, state = [2,3])
print len(alms)

I have tried many version of the pathValue string and nothing seems to work.
What am I doing wrong ?

Note: the path to the tag that has the alarm associated with it is:
[default]FAB/Pos_1110_Drive/OLFault

My next step is to put this value in a tag that continuously updates. What is best practice for this ?

Try the path without the tag provider,
https://docs.inductiveautomation.com/display/DOC81/system.alarm.queryStatus

There are a few exchange resources you could peak at, one here,

If you do need the provider included, you can use a path (or source) like this 'prov:default:/tag:FAV/*'

2 Likes

Or use the provider parameter.

List[String] provider - A list of tag providers to include in the query. Omitting this parameter will query all providers. [optional]

Note, you should never call system.alarm.queryStatus from within a Vision client unless you want performance issues as this is a slow function and all scripts in Vision run in the gui thread so will lock up the interface. You didn't tag your post so not sure what you're using

Thanks for tip. I am hoping to create a global expression tag that contains the alarm count for various machines and areas in a factory. The vision clients only read the tags.

2 Likes

It is safe to call from an asynchronous function, triggered from a client timer event, and writing results to a client tag. Everything else in the Vision client should reference the client tag.

1 Like

This worked. Thanks

Gets the count of all active acked and unacked alarms in the folder "FAB" from the default provider.


pathValue = "prov:default:/tag:FAB/*"
alms = system.alarm.queryStatus(source = pathValue , state = [2,3])
count = len(alms)
1 Like

If you're going to do that though, wouldn't you just write to a standard tag so you're not doing this for every client?

Yes, unless there is a per-client difference in how the query is called.