Skip to main content

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.

MethodNodeIdInput Parameters
Acknowledgei=9111(event_id: bytes, comment: str)
Confirmi=9113(event_id, comment)
AddCommenti=9029(event_id, comment)
Enablei=2803—
Disablei=2805—
ConditionRefreshi=3875(subscription_id)
ConditionRefresh2i=12912(subscription_id, monitored_item_id)
OneShotShelvei=9211—
TimedShelvei=9213(duration_ms: float)
Unshelvei=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​

MethodsCategoryReading and WritingNote
ua.acknowledge(condition_id, event_id, comment="")AlarmWriteUser Known
ua.confirm(condition_id, event_id, comment="")AlarmWriteThe issue has been resolved on-site
ua.add_comment(condition_id, event_id, comment)AlarmWriteAdd a note (comment required)
ua.enable_condition(condition_id)AlarmWriteEnable
ua.disable_condition(condition_id)AlarmWriteDisable
ua.condition_refresh(subscription_id)AlarmWriteReissue and Activation Alarm
ua.condition_refresh2(subscription_id, monitored_item_id)AlarmWriteSpecify only MI
ua.one_shot_shelve(shelving_state_id)AlarmWriteOne-Time Blocking
ua.timed_shelve(shelving_state_id, duration_ms)AlarmWriteTemporary Mute
ua.unshelve(shelving_state_id)AlarmWriteUnblock
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: ...
ParametersDefaultNote
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.EventArrivedEventArgs There are only 5 fields (severity / message / source_name / time / event_type); these 5 fields constitute the default subscription.acknowledge / confirm / add_comment The required condition_id fields event_id: bytes must be provided by the business side’s own alarm model / server-side object tree.
  • EventSubscription.subscribe(node_id, event_filter) accepts a custom EventFilter, but custom SelectClauses do not currently take effect — events are still pushed with the default 5 fields, plus an extra Diagnostic Info event stating that the filter condition has been ignored.
  • acknowledge / confirm / add_comment is sent as a plain comment string, without a locale tag.

Error Handling​

All methods return a value StatusCode and do not throw exceptions. Common results:

ResultsMeaning
StatusCode.GoodSuccess, the server has accepted it
StatusCode.BadFailure (Unified State, see below)
The parameter is empty / event_id is None / duration_ms is negative or NaNReturns the normalized value directly StatusCode; do not send it. RPC
Standardization of Status Codes

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)
  • acknowledge Then confirm, two more steps
  • timed_shelve Unit 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#PythonJavaC++RustC
AcknowledgeacknowledgeacknowledgeAcknowledgeacknowledgeDarraUa_Alarm_Acknowledge
ConfirmconfirmconfirmConfirmconfirmDarraUa_Alarm_Confirm
ConditionRefreshcondition_refreshconditionRefreshConditionRefreshcondition_refreshDarraUa_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).

Next Step​