Getting the Initial Value that Triggered an Alarm

I am currently developing a system in which management can respond to alarm events via sms through a Twilio server. The functionality that I am trying to acheive is that the alarm is triggered, sends a notification to the manager, the manager then has the option to respond to the notification. If the manager responds, an acknowledge pipeline is triggered. The acknowledge pipeline then contains logic that saves the value that triggered the alarm as well as other associated data to a custom database table.

Now this works fine until I run into the situation where the tag that triggered the alarm clears it’s alarm state. Inside the acknowledge pipeline I am using the event['eventValue'] property to get the value of the tag that triggered the alarm. The Ignition manual seemed to indicate that this property was the value that triggered the alarm, but it keeps returning the current value. I am assuming that this is just a misunderstanding of the documentation on my end. However, is there a way to get the value that triggered the alarm in the acknowledge pipeline, even after the alarm event has been cleared?

Update:

After a good amount of investigation, it does not appear that there is currently a documented way to obtain the initial “active” alarm value from an acknowledge pipeline. This definitely seems like it should be possible since when looking at the alarm status table, the active event value is still retained in the alarm information even after the alarm is cleared and acknowledged.

I was able to create a workaround for this though. It appears that there is an undocumented dictionary value on the alarm pipeline for the database alarm UUID:

event['eventId']

Using this I was able to generate a query that allowed me to retrieve the active value from my acknowledge pipeline as follows:

SELECT aed.intvalue 
FROM alarm_event_data aed
JOIN alarm_events ae ON ae.id = aed.id
WHERE ae.eventtype = 0
AND aed.propname = 'eventValue'
AND ae.eventid =?

As I mentioned before, it does seem like this data should be easier to get. If anyone from inductive knows anything about this that I have not been able to discover I would be very curious.

In a script block, try event.getActiveData(); that should give you an EventData property set you can examine.

In the pipline script block? I’ve tried calling the alarm property functions on that object but always get an error? I just tried what you suggested and also got an error. It seems like that event object being passed in is not actually the same type of alarm event object that would be generated by something like system.alarm.queryStatus() which you then could run the additional alarm methods against unless I am missing something here?

It should be:
image

You could also call sourceEvent(); the PyAlarmEvent should then give you the underlying AlarmEvent directly.

I'd recommend poking around at the event object via Phil Turmel's introspection script:

So I can get the active data by use of activeEvent = event.sourceEvent.getActiveData() but I cannot seem to then pull any of the associated property data out of the event object. The documenation states that I should be able to use get(String propertyName) on this object but when I use activeEvent.get('eventValue') I get an error stating:

1st arg can't be coerced to com.inductiveautomation.ignition.common.config.Property

If I run activeEvent.getProperties() however, I do receive back a list of property names of which “eventValue” is one of them. Do I somehow need to use an actual property “type” as an insert into the get function instead of the string name and if so how would I do that?

So after looking through the java docs, I managed to get an implementation that works without going through the database.

from com.inductiveautomation.ignition.common.alarming.evaluation import EventProperty
from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties
prop = EventProperty.createStatic(CommonAlarmProperties.EventValue, False)

activeEvent = event.sourceEvent()
activeData = activeEvent.getActiveData()

activeEventValue = activeData.get(prop)

This did the trick. I do still wish there was a more direct way to access active alarm data from an acknowledge pipeline though.

3 Likes

I was on my lunch break and about to type out pretty much exactly what you have there, so good stuff. For posterity, I’ll post it anyways:


Basically, yes.

The PyAlarmEvent wrapper has some helper methods to allow you to retrieve properties by name alone. By going to the ‘sourceEvent’ object, you’re no longer able to use those helper methods.

There are a few options:

  1. Go through the properties list and find the one with the name you’re after:
def findProperty(propertyset, propertyname):
	for prop in propertyset.properties:
		if prop.name == propertyname:
			return prop

activeData = event.sourceEvent.getActiveData()

prop = findProperty(activeData, "PropertyName")
if prop != None:
	value = activeData.getOrDefault(prop)
  1. Find a reference to the property you’re looking for in the SDK. Depending on your version of Ignition, this might be easier or harder, but you could start with, e.g.
    CommonAlarmProperties
2 Likes