Skip to main content

Device control, status, and scenario operations

These contracts apply to Direct Devices. Before using a flow, connect with valid MQTT credentials by following the MQTT connection guide, and obtain the corresponding TargetType permission.

Control another Device​

Required permission: SendToSerial = 20

Publish to the complete topic:

{projectCode}/ControlOthers
{
"deviceSerial": "TARGET_DEVICE_SERIAL",
"operationName": "TARGET_OPERATION_NAME",
"value": "TARGET_COMMAND_VALUE"
}

Read the Operation name and command value from the Project's Operation and Command definitions; do not guess them.

FieldDescription
deviceSerialTarget Device serial.
operationNameTarget Operation name.
valueA valid command for that Operation.

The confirmed QoS is 1 and retain is false. When AES is enabled for the deployment, use {projectCode}/ControlOthers/AES. A successful publish alone does not prove execution; update state from a valid Device report.

Receive live state changes​

Required permission: ListenFromSerial = 21

The receiving Device subscribes to:

{projectCode}/ReceiveGeneralData/{DeviceSerial}

Here, deviceSerial is the receiving Device serial. QoS is 1 and retain is false. When AES is enabled, use:

{projectCode}/ReceiveGeneralData/{DeviceSerial}/AES

ListenToDevice envelope​

The incoming message has tag = ListenToDevice. Its data field is a serialized SendToApp JSON object; the inner JsonData field is another serialized JSON value containing a list of OperationValue objects.

Complete wire example:

{
"tag": "ListenToDevice",
"data": "{\"ProjectCode\":\"PROJECT_CODE\",\"DeviceSerial\":\"SOURCE_DEVICE_SERIAL\",\"Type\":\"ChangeDevice\",\"JsonData\":\"[{\\\"Key\\\":\\\"power\\\",\\\"Value\\\":\\\"on\\\"}]\"}"
}

After parsing data:

{
"ProjectCode": "PROJECT_CODE",
"DeviceSerial": "SOURCE_DEVICE_SERIAL",
"Type": "ChangeDevice",
"JsonData": "[{\"Key\":\"power\",\"Value\":\"on\"}]"
}

After parsing JsonData:

[
{
"Key": "power",
"Value": "on"
}
]

Processing order:

  1. Parse the MQTT envelope as JSON.
  2. Route only messages where tag = ListenToDevice into this flow.
  3. Parse the data string as SendToApp.
  4. Validate ProjectCode and DeviceSerial against the expected dependency.
  5. Process Type = ChangeDevice as a state change.
  6. Parse JsonData into {Key, Value} entries and update only known Operations.

Receive the last value​

GetSerialLastValue = 22 authorizes snapshots, and RequestDeviceLastValue and DeviceLastValue are listed in the topic reference. However, the current public sources do not specify the complete request/response payload and behavior. Do not derive an operational contract from the topic names alone; confirm it against the deployed Backend/SDK before use.

Enable or disable a scenario​

ActionPermissiontag
DisableDisableScenario = 10DisableServerScenario
EnableEnableScenario = 11EnableServerScenario

Publish to:

{projectCode}/SendGeneralData

data is the raw scenario-code string:

{
"tag": "EnableServerScenario",
"data": "SCENARIO_CODE"
}

To disable it, change only tag to DisableServerScenario. Do not convert data into an object such as {"code": ...}.

Get scenario information​

Required permission: ServerScenarioInfo = 12

Publish the request to {projectCode}/SendGeneralData:

{
"tag": "ServerScenarioInfo",
"data": "SCENARIO_CODE"
}

The response arrives on {projectCode}/ReceiveGeneralData/{DeviceSerial} with tag = ServerScenarioInfo. Its data is a serialized SendServerScenario object:

{
"tag": "ServerScenarioInfo",
"data": "{\"Name\":\"Evening\",\"Code\":123,\"Type\":110,\"Status\":10}"
}

Decoded model:

{
"Name": "Evening",
"Code": 123,
"Type": 110,
"Status": 10
}

Numeric scenario types​

ValueType
110Manual
120Condition
121ConditionWithTime
122Time
200Security

Numeric scenario statuses​

ValueStatus
10Enable
20Disable
21SystemDisabled
22PaymentDisabled

Handle unknown future enum values without crashing.

Run a manual scenario​

Required permission: RunServerScenario = 13

Run only manual scenarios (Type = 110) through:

{projectCode}/RunServerScenarioFromDevice
{
"code": 123
}

Read the code from a valid ServerScenarioInfo response or trusted provisioning data. This topic is not contracted for non-manual scenarios.

Troubleshooting​

ProblemCheck
Another Device does not execute the commandVerify SendToSerial = 20, target serial, Operation, command, and the complete ControlOthers topic.
No live state arrivesVerify ListenFromSerial = 21 and subscribe with the receiving Device's serial.
State parsing failsDecode data and then JsonData separately; both are serialized JSON strings.
Scenario response seems missingStay subscribed to ReceiveGeneralData/{DeviceSerial} and filter tag = ServerScenarioInfo.
Scenario does not enable or disableSend the code as the raw data string and verify permission 10 or 11.
Scenario execution is rejectedVerify permission 13, the code, and manual type (Type = 110).
Correct-looking topic receives nothingVerify projectCode, path casing, MQTT credentials, and the deployment's AES setting.

Reject malformed messages and invalid identifiers, never log secrets, and never interpret no response as success.

Test and configure the UI​

Test the flow with approved access and real Operation metadata in the AirNgin Lab. To configure target selection in a user-facing UI, continue with control configuration or live-state dependency configuration.