# Alarm Count - Active, Unacked, and Unshelved

**URL:** <https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [September 6, 2024, 1:58pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635 "2024-09-06T13:58:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 1:58pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/1 "2024-09-06T13:58:59Z")

</div>

How can I get a count of the alarms that are active, unacked, and unshelved, since [the system tag includes shelved alarms](https://forum.inductiveautomation.com/t/shelved-alarm-behavior/95595)?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 2:50pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/2 "2024-09-06T14:50:37Z")

</div>

I've come up with this script to run inside an expression tag. Anyone else have ideas?

```python
def getActiveUnackedUnshelvedCount():
	'''
	Get the count of active unacked alarms that are not shelved
	
	Args:
		n/a
		
	Returns:
		activeUnackedCount	(integer)	:	Active, Unacked, Unshelved Count
	'''
	almPaths = [str(alm.path) for alm in system.alarm.getShelvedPaths() if alm]

	shelvedCountPaths = []
	for path in almPaths:
		
		pathParts = path.split(':/')
		
		partsDict = {}
		for part in pathParts:
		    key, value = part.split(':', 1)
		    partsDict[key] = value
		    
		    prov = partsDict.get('prov','')
	        tag = partsDict.get('tag','')
	        #alarm = partsDict.get('alm','')
	        
	        fullAlmPath = '[' + prov + ']' + tag + '/Alarms.ShelvedCount'
	        
	        shelvedCountPaths.append(fullAlmPath)
	        
	        
	tagVals = system.tag.readBlocking(['[System]Gateway/Alarming/Active and Unacked']+shelvedCountPaths)
	
	activeUnackedCount = tagVals[0].value
	
	for i in range(1,len(tagVals)):
		if tagVals[i].value:
			activeUnackedCount = activeUnackedCount - 1
	
	return activeUnackedCount

```

edit: just realized that I need to check if the alarm is active before subtracting it from the count. Script has not been updated yet.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/3 "2024-09-06T15:08:12Z")

</div>

Well,

I found that the `ActiveAckCount`, `ActiveUnackCount`, `HasActive`, and `HasUnacknowledged` properties of the Alarms tag do not populate as expected either, so I can't even check the activity before subtracting it because the individual alarm names may differ, and their may be more than one.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/8/0872f38dbb829cf4538b84735cc553bb26779cb8.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 6, 2024, 3:15pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/4 "2024-09-06T15:15:26Z")

</div>

It seems to me that excluding shelved alarms in a tag from the tag's alarm summary properties is expected and, from my viewpoint, **desirable**. The whole point of shelving is to prevent that alarm from participating in the rest of the system.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/5 "2024-09-06T15:16:12Z")

</div>

Right, then why is it _included_ in the system's `Active and Unacked` count? If it wasn't I wouldn't have this issue.

Phil, how might I loop through each individual alarm under the Alarms summary tag to check the `isActive` tag, without knowing the name of the alarm(s)?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 6, 2024, 3:30pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/6 "2024-09-06T15:30:27Z")

</div>

> [@amarks](#):
>
> then why is it _included_ in the system's `Active and Unacked` count?

Seems to me **that** is the bug.

> [@amarks](#):
>
> without knowing the name of the alarm

Yeah, have to know that. Is available in a `system.tag.getConfiguration()` call or a `system.tag.query()` call, but you don't want to be calling those often.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/7 "2024-09-06T15:33:24Z")

</div>

that's kind of what I figured, so I'm a little stuck at the moment....

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 6, 2024, 3:44pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/8 "2024-09-06T15:44:25Z")

</div>

Reference this as I made some tweaks from an exchange resource, but this will summarize alarms and get counts, etc.

> [@Highest active alarm underneath a given tagPath](https://forum.inductiveautomation.com/t/highest-active-alarm-underneath-a-given-tagpath/93769/2):
>
> I've made a modified version of the alarm summary script I found on here at one time to do just that. I literally made the change yesterday to it, although mine has a lot of other stuff I'm doing too, so let me see if I can clean it up, but essentially it's a Gateway script that runs like once a second and keeps track of all the alarms and dumps that in a global variable, then in each folder I have an "area" tag that parses that global tag and finds all the alarm stats for tags starting with the…

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 4:55pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/9 "2024-09-06T16:55:36Z")

</div>

I suppose using query or config to get the name might actually be OK since it would only be for any shelved alarms, which should be a fairly limited list.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 5:09pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/10 "2024-09-06T17:09:29Z")

</div>

It looks like

```python
system.alarm.queryStatus(state=["ActiveUnacked"], includeShelved=False)

```

is all that I need

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 6, 2024, 5:50pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/11 "2024-09-06T17:50:25Z")

</div>

Make sure you aren't calling that from the GUI unless it is in an async thread. That call can take a bit and will cause issues in your GUI unless you are careful.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [September 6, 2024, 6:21pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/12 "2024-09-06T18:21:29Z")

</div>

only calling from an expression tag. Every 3 seconds.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 6, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/alarm-count-active-unacked-and-unshelved/95635/13 "2024-09-06T18:54:28Z")

</div>

If you're doing it from a lot of different locations/areas, it can also cause problems which is why I believe the script that I used from the Exchange and tweaked for some of my own use only has one place it calls it from then saves it to a global variable that all the areas filter results from.
