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:
| Field | Type | Default | Note |
|---|---|---|---|
| type_definition_id | Optional[str] | None | Event Type NodeId String (e.g., "i=2041"); None = wildcard BaseEventType |
| browse_path | Tuple[str, ...] | () | Field browsing path (each segment BrowseName); an empty tuple indicates that the entire EventType set is selected |
| attribute_id | AttributeId | AttributeId.Value | Property Id |
| index_range | Optional[str] | None | Array index range (NumericRange string) |
EventFilter It is itself a frozen dataclass:
| Field | Type | Default | Note |
|---|---|---|---|
| select_clauses | Tuple[SimpleAttributeOperand, ...] | () | Which fields to capture |
| where_clause | Optional[str] | None | Filter Expression (ContentFilter). V1 Not implemented, Just leave it as None or "" |
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:
| # | Field | Corresponding EventArrivedEventArgs |
|---|---|---|
| 1 | Severity (UInt16) | severity |
| 2 | Message (String) | message |
| 3 | SourceName (String) | source_name |
| 4 | Time (DateTime) | time |
| 5 | EventType (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)
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 Type | type_definition_id | browse_path | Meaning |
|---|---|---|---|
| BaseEventType | i=2041 | ("EventId",) | Unique Event ID |
| BaseEventType | i=2041 | ("Severity",) | Severity |
| BaseEventType | i=2041 | ("Message",) | Event Text |
| BaseEventType | i=2041 | ("Time",) | Event Time |
| ConditionType | i=2782 | ("ConditionId",) | Conditions NodeId |
| ConditionType | i=2782 | ("EnabledState", "Id") | bool Enabled |
| AcknowledgeableConditionType | i=2881 | ("AckedState", "Id") | bool Is Ack |
| AlarmConditionType | i=2915 | ("ActiveState", "Id") | bool IsActive |
| ShelvedConditionType | i=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.Infoevent 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_clauseCurrently, 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_idDeclare event-type strings NodeId pairedbrowse_pathwith
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |