Alarms and Conditions
Overview
OPC UA Part 9 defines a standard Method with a fixed NodeId on ConditionType / AlarmConditionType. The SDK wraps it as a Python method with clear parameters.
| Method | NodeId | Input Parameters |
|---|---|---|
| Acknowledge | i=9111 | (event_id: bytes, comment: str) |
| Confirm | i=9113 | (event_id, comment) |
| AddComment | i=9029 | (event_id, comment) |
| Enable | i=2803 | — |
| Disable | i=2805 | — |
| ConditionRefresh | i=3875 | (subscription_id) |
| ConditionRefresh2 | i=12912 | (subscription_id, monitored_item_id) |
| OneShotShelve | i=9211 | — |
| TimedShelve | i=9213 | (duration_ms: float) |
| Unshelve | i=9215 | — |
The first 7 methods are attached to the condition instance / Server object, and the three Shelve methods are attached to the alarm instance's ShelvingState child node Up.
API
| Methods | Category | Reading and Writing | Note |
|---|---|---|---|
| ua.acknowledge(condition_id, event_id, comment="") | Alarm | Write | User Known |
| ua.confirm(condition_id, event_id, comment="") | Alarm | Write | The issue has been resolved on-site |
| ua.add_comment(condition_id, event_id, comment) | Alarm | Write | Add a note (comment required) |
| ua.enable_condition(condition_id) | Alarm | Write | Enable |
| ua.disable_condition(condition_id) | Alarm | Write | Disable |
| ua.condition_refresh(subscription_id) | Alarm | Write | Reissue and Activation Alarm |
| ua.condition_refresh2(subscription_id, monitored_item_id) | Alarm | Write | Specify only MI |
| ua.one_shot_shelve(shelving_state_id) | Alarm | Write | One-Time Blocking |
| ua.timed_shelve(shelving_state_id, duration_ms) | Alarm | Write | Temporary Mute |
| ua.unshelve(shelving_state_id) | Alarm | Write | Unblock |
def acknowledge(self, condition_id: str, event_id: bytes, comment: str = "") -> StatusCode: ...
def confirm(self, condition_id: str, event_id: bytes, comment: str = "") -> StatusCode: ...
def add_comment(self, condition_id: str, event_id: bytes, comment: str) -> StatusCode: ...
def enable_condition(self, condition_id: str) -> StatusCode: ...
def disable_condition(self, condition_id: str) -> StatusCode: ...
def condition_refresh(self, subscription_id: int) -> StatusCode: ...
def condition_refresh2(self, subscription_id: int, monitored_item_id: int) -> StatusCode: ...
def one_shot_shelve(self, shelving_state_id: str) -> StatusCode: ...
def timed_shelve(self, shelving_state_id: str, duration_ms: float) -> StatusCode: ...
def unshelve(self, shelving_state_id: str) -> StatusCode: ...
| Parameters | Default | Note |
|---|---|---|
| condition_id | — | Examples of alarm conditions NodeId; returns an empty string; returns the normalized StatusCode.Bad state |
| event_id | — | Alarm Event ID (ByteString, bytes); None Returns the normalized StatusCode |
| comment | "" | LocalizedText Comment (SDK Currently cast to a String and passed to the server) |
| subscription_id | — | Hosting Publish SubscriptionId |
| monitored_item_id | — | MonitoredItem Id |
| shelving_state_id | — | On the alarm instance ShelvingState child node NodeId |
| duration_ms | — | Duration of suspension, milliseconds (float); Returns the normalized value for negative numbers / NaN StatusCode |
Returns StatusCode; no exception is thrown on failure (internally, it is OpcUaException normalized to StatusCode).
Code Example
from darra_opcua import DarraOpcUa, StatusCode
with DarraOpcUa("opc.tcp://server:4840") as ua:
ua.connect()
# Set up your own container subscription; that's the only way to get it. subscription_id Send it to condition_refresh
sub = ua.create_subscription(500)
es = ua.subscribe_events("i=2253", existing_subscription=sub) # ServerObject
def on_event(args):
# args is EventArrivedEventArgs: severity / message / source_name / time / event_type
print(f"sev={args.severity} {args.source_name}: {args.message}")
# a. Have the server resend the current activation alert
ua.condition_refresh(sub.subscription_id)
es.event_arrived.append(on_event) # List[Callable], registered using `append`
# b. The user clicks "Confirm" — condition_id / Provided event_id by the alarm source (see "Implementation Limitations")
def ack_alarm(condition_id: str, event_id: bytes):
rc = ua.acknowledge(condition_id, event_id, "操作员已知")
if rc != StatusCode.Good:
print(f"Acknowledge 失败: {rc}")
# c. On-site processing
ua.confirm(condition_id, event_id, "现场已处理")
# d. Temporarily block for 30 seconds (retrieve the ShelvingState child nodes from the alarm instance)
node = ua.resolve("ShelvingState", condition_id)
if node is not None:
ua.timed_shelve(node.node_id, 30_000.0)
es.dispose()
sub.dispose()
Implementation Constraints
- Cannot access it in the event callback
EventId/ConditionId.EventArrivedEventArgsThere are only 5 fields (severity/message/source_name/time/event_type); these 5 fields constitute the default subscription.acknowledge/confirm/add_commentThe requiredcondition_idfieldsevent_id: bytesmust be provided by the business side’s own alarm model / server-side object tree. EventSubscription.subscribe(node_id, event_filter)accepts a customEventFilter, but custom SelectClauses do not currently take effect — events are still pushed with the default 5 fields, plus an extraDiagnosticInfo event stating that the filter condition has been ignored.acknowledge/confirm/add_commentis sent as a plaincommentstring, without a locale tag.
Error Handling
All methods return a value StatusCode and do not throw exceptions. Common results:
| Results | Meaning |
|---|---|
StatusCode.Good | Success, the server has accepted it |
StatusCode.Bad | Failure (Unified State, see below) |
The parameter is empty / event_id is None / duration_ms is negative or NaN | Returns the normalized value directly StatusCode; do not send it. RPC |
Python's StatusCode enumeration includes only commonly used codes. Codes not listed in Appendix A of Part 4 (such as BadConditionAlreadyEnabled / BadConditionAlreadyShelved / BadEventIdUnknown) are uniformly standardized to StatusCode.Bad, it is not possible to distinguish between them based on the return value. To determine the specific cause, read the raw integer value OpcUaException.status_code of, or review the diagnostic text returned by the server.
Best Practices
- Must Be Adjusted After Initial Subscription
condition_refresh(sub.subscription_id) acknowledgeThenconfirm, two more stepstimed_shelveUnit ms, not seconds- Do not send an acknowledgment synchronously in the callback
event_arrived; instead, push it to the queue for background processing.
Cross-Language Comparison
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| Acknowledge | acknowledge | acknowledge | Acknowledge | acknowledge | DarraUa_Alarm_Acknowledge |
| Confirm | confirm | confirm | Confirm | confirm | DarraUa_Alarm_Confirm |
| ConditionRefresh | condition_refresh | conditionRefresh | ConditionRefresh | condition_refresh | DarraUa_Alarm_ConditionRefresh |
C's family name is DarraUa_Alarm_*, not; DarraUa_Condition_*;Enable / Disable on the C side is DarraUa_Alarm_EnableCondition / DarraUa_Alarm_DisableCondition, Refresh is DarraUa_Alarm_ConditionRefresh(not _Refresh).