Skip to main content

EventFilter

Overview​

OPC UA Part 4 §7.18 EventFilter consists of two parts:

  • SelectClauses — Specify which fields to retrieve
  • WhereClause — Filter Criteria (V1 Not yet implemented)

Each one is SelectClause SimpleAttributeOperand:

FieldTypeDefaultNote
type_definition_idOptional[str]NoneEvent Type NodeId String (e.g., "i=2041"); None = wildcard BaseEventType
browse_pathTuple[str, ...]()Field browsing path (each segment BrowseName); an empty tuple indicates that the entire EventType set is selected
attribute_idAttributeIdAttributeId.ValueProperty Id
index_rangeOptional[str]NoneArray index range (NumericRange string)

EventFilter It is itself a frozen dataclass:

FieldTypeDefaultNote
select_clausesTuple[SimpleAttributeOperand, ...]()Which fields to capture
where_clauseOptional[str]NoneFilter Expression (ContentFilter). V1 Not implemented, Just leave it as None or ""
The current version EventFilter doesn't actually take effect.

EventSubscription.subscribe(node_id, event_filter) Accepted EventFilter, but custom SelectClauses / WhereClause None will be issued, Events are always sent back to the callback event_arrived using the following 5 fixed fields.

Fields that are actually available​

Unrecorded Period EventFilter (andIt's the same even if you pass it on.) The 5 fixed fields returned by the callback:

#FieldCorresponding EventArrivedEventArgs
1Severity (UInt16)severity
2Message (String)message
3SourceName (String)source_name
4Time (DateTime)time
5EventType (String)event_type

NoneEventId / ConditionId / ActiveState / Any custom fields — these are currently unavailable and cannot SelectClauses be retrieved via. If you need information such ConditionId as, please actively ua.read(...) read the alarm node's properties using after receiving the event.

Code Example​

EventFilter Only EventSubscription.subscribe(node_id, event_filter) Eat; Convenient entry point—does not accept ua.subscribe_events(...) a filter. So if you want to pass a filter, you'll have to attach a container yourself:

from darra_opcua import (
DarraOpcUa, EventFilter, SimpleAttributeOperand, EventSubscription,
)

with DarraOpcUa("opc.tcp://localhost:4840") as ua:
ua.connect()

# 1) Container Subscription (Hosts Publish)
with ua.create_subscription(500) as sub:

# 2) Declare the desired fields (browse_path using a tuple)
f = EventFilter(select_clauses=(
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Severity",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Message",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("Time",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("SourceName",)),
SimpleAttributeOperand(type_definition_id="i=2041", browse_path=("EventType",)),
))

# 3) Self-hosted EventSubscription: Subscribe after mounting the container
es = EventSubscription(ua)
es.attach_container_subscription(sub, owns=False) # owns=False: es.dispose() does not destroy the sub
es.subscribe("i=2253", event_filter=f)

# 4) The callback parameter is always a fixed list of fields EventArrivedEventArgs, not a list of fields in any particular order select_clauses .
def on_event(args):
if args.time is not None:
print(f"[{args.time:%H:%M:%S}] sev={args.severity}: {args.message}")
print(f" source={args.source_name} type={args.event_type}")

es.event_arrived.append(on_event)
No args.fields in the callback

EventArrivedEventArgs has only five fields (severity / message / source_name / time / event_type). There is no args.fields[...], nor are there field accessors such as as_byte_string / as_uint16 — to get more fields, actively read them with ua.read(...) in the callback.

Field Quick Reference (browse_path Reference)​

The table below lists the event fields in the Standard OPC UA Address Space (Part 3 / Part 9), which you can use to fill in the blanks SimpleAttributeOperand.browse_path when constructing the address.Currently, SDK no notices are being issued. EventFilter, Selecting these fields won't give you any additional data—they only become meaningful once they are set to EventFilter true.

Event Typetype_definition_idbrowse_pathMeaning
BaseEventTypei=2041("EventId",)Unique Event ID
BaseEventTypei=2041("Severity",)Severity
BaseEventTypei=2041("Message",)Event Text
BaseEventTypei=2041("Time",)Event Time
ConditionTypei=2782("ConditionId",)Conditions NodeId
ConditionTypei=2782("EnabledState", "Id")bool Enabled
AcknowledgeableConditionTypei=2881("AckedState", "Id")bool Is Ack
AlarmConditionTypei=2915("ActiveState", "Id")bool IsActive
ShelvedConditionTypei=2929("ShelvingState", "CurrentState")LocalizedText Screened state

Conduct and Restrictions​

  • Custom SelectClauses / WhereClause Never takes effect; the event fields are fixed at those 5.
  • When it doesn't take effect, send a OpcUaEventCategory.Diagnostic / OpcUaEventSeverity.Info event with the message 「The current version does not support custom EventFilter applications (...), so it has fallen back to the default 5 fields」. The severity level is Info Not "Warn."
  • Filters are retained only within the current subscription and are not reapplied when the subscription is recreated.
  • where_clause Currently, this is just a string placeholder; the actual ContentFilter (ElementOperand tree) has not been implemented, so passing any value will have no effect.

Best Practices​

  • To access more fields, use the event callback to actively ua.read(...) read the alarm node properties.
  • Nested fields are written using multi-element tuples: ("ActiveState", "Id")
  • type_definition_id Declare event-type strings NodeId paired browse_path with

Cross-Language Comparison​

C#PythonJavaC++RustC
EventFilterEventFilterEventFilterEventFilterEventFilterDarraUa_EventFilter
SimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandSimpleAttributeOperandDarraUa_SimpleAttributeOperand

Next Step​