Skip to content

Control Relays Safely

Use Case

Use this pattern when relay operations affect equipment and the caller must handle retries, uncertain outcomes, and multiple relay channels without creating duplicate side effects.

Send all relay changes for one device in one relays array. A single batch becomes one device command and avoids consecutive transmissions that the device may not process reliably.

Step-by-Step Implementation

  1. Use List Device Type Definitions to confirm device.relay.set, relay count, and allowed actions.
  2. Build the desired relay array. Use one item for single-channel control and multiple unique indexes for a coordinated change.
  3. Generate a new caller-owned Idempotency-Key for this operation intent.
  4. Call Execute Relay Command with device:control.
  5. Read data.command.id and data.command.status. If the status is SENT, use Get Command Result until a terminal state or your bounded polling deadline.
  6. Use data.state when the device acknowledgement includes it. Do not issue another refresh only to populate an optional field.
  7. If the result is TIMEOUT, read the current device state before deciding whether another operation is safe.

Command Lifecycle

ResultMeaningClient action
HTTP 202 + COMMAND_ACCEPTEDThe platform accepted the request; it is not a separate command statusRead data.command.status and retain the command ID
SENTThe command is still waiting for confirmationQuery the command result with bounded polling
SUCCESSThe device confirmed executionApply returned state when present
FAILEDThe platform confirmed that the command did not completeStop automatic retries and handle the failure
TIMEOUTNo final confirmation arrived within the wait windowDo not assume the device did or did not execute; read current state first

Key Interfaces

Failure and Recovery

  • If the HTTP outcome is unknown because the network failed, retry the identical request with the same Idempotency-Key.
  • After 429 RATE_LIMITED, wait for Retry-After, then retry the same operation with the original key.
  • Never reuse a key for a different device, relay array, or action; that returns IDEMPOTENCY_CONFLICT.
  • After TIMEOUT, refresh state first. If the state is still unknown, require a business decision before sending another physical operation.
  • Repeating JOG or other equipment actions can produce real side effects even when the previous response was lost. Design confirmation and operator safeguards accordingly.

Production Considerations

  • Store the idempotency key, command ID, requested relay array, status, and requestId together for audit and recovery.
  • Serialize or coordinate operations targeting the same device in your application.
  • Use bounded result polling and honor rate limits.
  • Validate the target channel and physical safety before allowing control from a UI or automation rule.

Next Steps

Docs buildVersion v1.3.6-20260720-180213-70
Copyright © 2026 WLTE