# system.tag.getAlarmStates alternative?

**URL:** <https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803>\
**Category:** Ignition Early Access\
**Created:** [August 27, 2019, 3:47pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803 "2019-08-27T15:47:17Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [August 27, 2019, 3:47pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/1 "2019-08-27T15:47:17Z")

</div>

I had a function working which would pass a tagpath from a tag tree and display all the alarms under that path in a table. Since 8.0 the tag.getAlarmStates has been romved is there another option for this?

```auto
tags = system.tag.browseTagsSimple(dsSelected.getValueAt(0, 0), "ASC")
headers = ["Tag Name", "Alarm Name","Label","Active Pipeline","SetPointA","DisplayPath","Priority","enabled"]
data = []
for tag in tags:
	try:
		tagDefs = system.tag.getAlarmStates(tag.fullPath)
		for tagDef in tagDefs:		
			priority = 0
			for prop in tagDef.getAlarmProperties():
				if str(prop.property) == 'activePipeline':
					try:
						active = str(prop.value)
					except:
						pass
				elif str(prop.property) == 'setpointA':
					try:
						setPoint = str(prop.value)
					except:
						pass
				elif str(prop.property) == 'displayPath':
					try:
						displayPath = str(prop.value)
					except:
						pass
				elif str(prop.property) == 'priority':
					try:
						priority = str(prop.value)
					except:
						pass
				elif str(prop.property) == 'enabled':
					try:
						enabled = str(prop.value)
					except:
						pass
				elif str(prop.property) == 'label':
					try:
						label = str(prop.value)
					except:
						pass
			data.append([tag.fullPath,tagDef.alarm,label,active,setPoint,displayPath,priority,enabled])
	except:
		pass
dataset = system.dataset.toDataSet(headers, data)
event.source.parent.parent.getComponent('Container').getComponent('Power Table').data = dataset

```

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [August 28, 2019, 4:37pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/2 "2019-08-28T16:37:56Z")

</div>

Hi Oisin.gribben,

The functionality has been depricated. However, you can use the system.tag.configuration to do the same thing. [https://docs.inductiveautomation.com/display/DOC80/system.tag.getConfiguration](https://docs.inductiveautomation.com/display/DOC80/system.tag.getConfiguration)

Thanks  
Anthony

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [September 2, 2019, 1:31pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/3 "2019-09-02T13:31:26Z")

</div>

What way are we able to get the alarm setpoint, enabled etc. from this?  
When using the function on the docs it returns the tag properties instead of the alarms.

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [September 3, 2019, 11:08pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/4 "2019-09-03T23:08:13Z")

</div>

Hi Oisin.gribben,

Wouldn’t be far easier to get the same properties from an Alarm Status table? It seems like the same properties status such as Active time, Display path, Current State, Priority , label can all be found there.

Thanks  
Anthony

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [September 4, 2019, 8:14am UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/5 "2019-09-04T08:14:50Z")

</div>

Hi,  
I’m trying to get the alarm configurations from all tags whether or not they are or have been in alarm.

---

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [September 4, 2019, 8:33am UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/6 "2019-09-04T08:33:18Z")

</div>

Hi,

It seems that the system.tag.configuration only gets tags in folders.  
I am pointing the Tagpath to a udt instance with a hundred tags and 6 folders with tags inside.  
There should be 4 tags with alarms configured in total in the folders and 10 outside the folders.  
When I run this script i only get the ones in the folders.

```auto
    tags = system.tag.browseTags(parentPath=Tagpath, recursive=True)
	headers = ["Tag Name", "Alarm Name","Label","Active Pipeline","SetPointA","DisplayPath","Priority","enabled"]
	data = []
	for tag in tags:
		try:
			nodes = system.tag.getConfiguration(tag.fullPath, True)
		
			# Iterate over the results
			for item in nodes:
			
				# Through the results, search each dictionary
				for key, value in item.iteritems():
					#print tag.fullPath
					# ...looking for a 'tags' key
					if key == 'tags':
						# iterate over the tag configurations we found
						for tagConfig in value:
							# ...looking for a 'alarms' key
							#print tag.fullPath , tagConfig.keys()	
							if 'alarms' in tagConfig.keys():	
								#print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
								#print tag.fullPath , tagConfig.keys()	
								for alarm in tagConfig['alarms']:
									
									try:
										if type(alarm["activePipeline"]) is dict:
											active = alarm["activePipeline"].get("value")
										else:
											active = alarm["activePipeline"]
									except:
										active = ""
										
									try:
										if type(alarm["name"]) is dict:
											name = alarm["name"].get("value")
										else:
											name = alarm["name"]
									except:
										name = ""
										
									try:
										if type(alarm["setpointA"]) is dict:
											setPoint = alarm["setpointA"].get("value")
										else:
											setPoint = alarm["setpointA"]
									except:
										setPoint = ""
										
									try:
										if type(alarm["displayPath"]) is dict:
											displayPath = alarm["displayPath"].get("value")
										else:
											displayPath = alarm["displayPath"].value
									except:
										displayPath = ""
										
									try:
										if type(alarm["priority"]) is dict:
											priority = alarm["priority"].get("value")
										else:
											priority = alarm["priority"]
									except:
										priority = ""
										
									try:
										if type(alarm["enabled"]) is dict:
											enabled = alarm["enabled"].get("value")
										else:
											enabled = alarm["enabled"]
									except:
										enabled = True
									
									try:
										if type(alarm["label"]) is dict:
											label = alarm["label"].get("value")
										else:
											label = alarm["label"]
									except:
										label = ""
									row = [tag.fullPath,str(name),str(label),str(active),str(setPoint),str(displayPath),str(priority),str(enabled)]
									data.append(row)
										
		except:
			x= 1
	dataset = system.dataset.toDataSet(headers, data)

```

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [September 4, 2019, 4:08pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/7 "2019-09-04T16:08:29Z")

</div>

Hi Oisin.gribben,

Could you send me a gateway backup with a project that is displaying the issue?

Thanks,  
Anthony

---

<div class="post-metadata">

**Author:** ![latifa.rhandour](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@latifa.rhandour](https://forum.inductiveautomation.com/u/latifa.rhandour)\
**Post date:** [September 17, 2020, 12:18pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/8 "2020-09-17T12:18:36Z")

</div>

Hi @anjoroge,  
I’m facing the same issue. Did we find why we can get alarms inside folders?

Thanks for your answer!

---

<div class="post-metadata">

**Author:** ![anjoroge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/anjoroge/32/6698_2.png) [@anjoroge](https://forum.inductiveautomation.com/u/anjoroge)\
**Post date:** [September 17, 2020, 4:06pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/9 "2020-09-17T16:06:51Z")

</div>

Hi,  
What version of ignition are you on? The reason I ask is because we had a few version changes since then and the issue may be fixed in the latest version. you could try setting up a separate environment with the latest build and restoring the gwbk and see if the issue is still there.  
[https://inductiveautomation.com/downloads/ignition/8.0.16](https://inductiveautomation.com/downloads/ignition/8.0.16)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 22, 2021, 4:54pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/10 "2021-06-22T16:54:36Z")

</div>

Old post, but still relevant issue… the issue here is that `getConfiguration` returns only non-default property values of tags, nothing more. For example, if you leave the alarm Priority at the default of Low, then this configuration will not show if you run getConfiguration. Therefore you need to use getConfiguration to get the name of the alarm, then you can use readBlocking to read the properties of the alarms you need.

The only way that I can see being able to use `getConfiguration` to help with this, is if you:

1. use `system.tag.browse` to find all of the tags
2. call `system.tag.getConfiguration` in a loop to get the configuration of each tag individually. check if it has an alarm and if so, store the alarm name in a list
3. create a list or lists of the tag paths to the alarm properties that you want to read by appending to the alarm tags list created in (2) e.g. `alarmPriorityTagPaths = [tagPath + '/Alarms/' + alarmName + '.Priority' for tagPath, alarmName in zip(tags, alarmNames)]`
4. use `system.tag.readBlocking` to read the values of the alarm properties list(s)

For 350k tags, I estimated this to take a solid 9hrs… extremely inefficient, but I don’t know any other way to do this…  
For 450 tags it took 42s to do parts 1-2 above

```auto
import time
times = []
times.append(time.time())

tags = shared.tag.browseTags(path='Winery/Cask Hall', recursive=True)
tags = [str(tag['fullPath']) for tag in tags if str(tag['tagType']) == 'AtomicTag']
times.append(time.time())

alarmTagPaths=[]
alarmNames=[]
for tag in tags:
	config = system.tag.getConfiguration(basePath=tag)
	if 'alarms' in config:
		alarmTagPaths.append(tag)
		alarmNames.append(config['alarms'][0].get('name', 'Alarm')) # not sure if this would ever not exist

times.append(time.time())
print times[-1]-times[0], 's for ', len(tags), ' tags'

print 'Times'
for i in range(1,len(times)):
	print '\t', i, times[i]-times[i-1], 's'

```

---

<div class="post-metadata">

**Author:** ![Cory.grube](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cory.grube/32/20476_2.png) [@Cory.grube](https://forum.inductiveautomation.com/u/Cory.grube)\
**Post date:** [June 22, 2021, 5:15pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/11 "2021-06-22T17:15:09Z")

</div>

I've been down this path as well, definitely frustrating not being able to get the default properties. That said, I think `getAlarmStates` has the same behavior, at least per a note in the [docs](https://www.docs.inductiveautomation.com/docs/7.9/appendix/scripting-functions/system-tag/system-tag-getAlarmStates).

It would be great to get all properties, even defaults, particularly for functional testing. For instance, I've wanted to make a report that can quickly grab all alarm details, history details, etc and print them in one big PDF - that info is particularly desirable for pharma customers. Might end up doing it the way you mentioned, but as you noted it's...a bit unwieldy.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 22, 2021, 5:40pm UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/12 "2021-06-22T17:40:01Z")

</div>

The only other way that I can think to do this that would hopefully be faster, but a lot more effort… (although I’ve actually started this already as I need it for other things)  
is to:

1. First create a script that collates a _complete_ tag list with _all_ configuration, including for UDT instances (note that exporting standard tags to json doesn’t include any information for tags inside of UDT instances except for name and tagType - we want to fix this).  
This requires:  
a) taking a json export of all UDT tag definitions and a json export of all standard tags  
b) creating a dictionary with `{udtDefTagPath1: {<UDT DEF JSON>}, udtDefTagPath2: ....}`  
c) recursively merge all nested UDT instances within each UDT definition json with the UDT instance’s definition’s json (need to do this recursively as otherwise any nested UDT instances within UDT definitions would not have all the configuration for their nested tags, and think, there could be many layers of UDT nesting…)  
d) finally, loop through the standard tags looking for udt instances, then merge the udt definition json from (c) to give you the full configuration.

2. Once you have the complete tag configuration, you can then loop through the tags and compile a list of all tags with configured alarms. Note: you will still have missing configuration for default values.

3. For each tags with alarms, collate a list of alarm names and corresponding tag paths. We need the alarm names to read the alarm properties as tags.

4. Create a list of tagpaths to the alarm properties that you want to read, using (3) for the tagPath prefixes.  
E.g. to read the priority of an alarm, you would read:  
`<tagPath>/Alarms/<AlarmName>.Priority`

5. Finally, use `system.tag.readBlocking` to read the list of alarm properties…

It really shouldn’t be this hard though, especially not to get a complete list of tag configuration

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 14, 2021, 2:00am UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/13 "2021-07-14T02:00:12Z")

</div>

Update:  
You can get the alarm default values using:

```auto
from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties, AlarmModeProperties
properties = {}
properties.update(dict((s.getName(), s.getDefaultValue()) for s in CommonAlarmProperties.values()))
properties.update(dict((s.getName(), s.getDefaultValue()) for s in AlarmModeProperties.values()))

```

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [August 25, 2022, 8:39am UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/14 "2022-08-25T08:39:44Z")

</div>

where do you put the tag path?

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [April 3, 2023, 12:57am UTC](https://forum.inductiveautomation.com/t/system-tag-getalarmstates-alternative/27803/15 "2023-04-03T00:57:08Z")

</div>

You don't need to put in a tag path, all default properties will be in the properties dictionary.  
So if you are interested in returning the default priority for a tag, you would use the code provided above, and access it with:

```auto
priority = properties['priority']

```

according to the scripting name in the manual here:  
[https://docs.inductiveautomation.com/display/DOC81/Tag+Alarm+Properties](https://docs.inductiveautomation.com/display/DOC81/Tag+Alarm+Properties)
