Command
The command object represents a command to be sent to a device or endpoint. This object is normally received as a parameter in the buildDownlink method as part of a LoRaWAN or MQTT data conversion script.
Properties
### commandId (int) The commandId property indicates an internal number that uniquely identifies the command. If the device is capable of responding to the command, the response must contain the same commandId.
Examples
The following is an example based on the buildDownlink method documentation in the LoRaWAN or MQTT data conversion section.
function buildDownlink(device, endpoint, command, payload)
{
payload.port = 25; // This device receives commands on LoRaWAN port 25
payload.buildResult = downlinkBuildResult.ok;
switch (command.type) {
case commandType.onOff:
switch (command.onOff.type) {
case onOffCommandType.turnOn:
payload.setAsBytes([30]); // Command ID 30 is "turn on"
break;
case onOffCommandType.turnOff:
payload.setAsBytes([31]); // Command ID 31 is "turn off"
break;
case onOffCommandType.toggle:
payload.setAsBytes([32]); // Command ID 32 is "toggle"
break;
default:
payload.buildResult = downlinkBuildResult.unsupported;
break;
}
break;
default:
payload.buildResult = downlinkBuildResult.unsupported;
break;
}
}### type (int, enum)
The type property indicates the command type. The possible values are as follows:
- commandType.onOff (1): indicates that the command is of on/off type, meaning it is for turning on, turning off, or toggling an endpoint.
- commandType.dimmer (2): indicates that the command is for altering the level of a dimmer.
- commandType.closure (3): indicates that the command is for controlling a closure, such as a curtain or blind.
- commandType.thermostat (4): indicates that the command is for controlling a thermostat.
- commandType.management (5): indicates that the command is for managing the device (reboot, firmware upgrade, etc.).
- commandType.custom (6): indicates that it is a user-defined command.
Examples
A complete example is presented at the beginning of this section.
### onOff (object)
The onOff property is an object containing the command parameters when it is of type commandType.onOff. The object has the following properties:
- type (int enum): indicates the on/off command type, among the following:
- onOffCommandType.turnOn (0): indicates that the command is to turn on the endpoint.
- onOffCommandType.turnOff (1): indicates that the command is to turn off the endpoint.
- onOffCommandType.toggle (2): indicates that the command is to toggle the endpoint.
Examples
A complete example is presented at the beginning of this section.
### dimmer (object)
The dimmer property is an object containing the command parameters when it is of type commandType.dimmer. The object has the following properties:
- level (double): indicates the dimming level as a percentage, from zero to 100%.
Examples
A complete example is presented at the beginning of this section.
### thermostat (object)
The thermostat property is an object containing the command parameters when it is of type commandType.thermostat. The object has the following properties:
- type (int enum): indicates the type of command sent to the thermostat, among the following:
- thermostatCommandType.setMode (0): the command is to change the thermostat mode.
- thermostatCommandType.setFanMode (1): the command is to change the thermostat fan mode.
- thermostatCommandType.setSetpoint (2): the command is to change the setpoint.
- thermostatCommandType.setAll (3): the command is to change all parameters simultaneously.
- mode (int enum): indicates the mode the thermostat should switch to, when the type is thermostatCommandType.setMode or thermostatCommandType.setAll. The possible values are as follows:
- thermostatMode.off (1): the thermostat should be turned off.
- thermostatMode.auto (2): the thermostat should switch to auto mode.
- thermostatMode.heat (3): the thermostat should switch to heat mode.
- thermostatMode.cool (4): the thermostat should switch to cool mode.
- thermostatMode.dry (5): the thermostat should switch to dehumidification (dry) mode.
- thermostatMode.fan (6): the thermostat should switch to fan mode.
- fanMode (int enum): indicates the fan mode the thermostat should switch to, when the type is thermostatCommandType.setFanMode or thermostatCommandType.setAll. The possible values are as follows:
- thermostatFanMode.auto (1): the fan should switch to auto mode.
- thermostatFanMode.low (2): the fan should switch to low mode.
- thermostatFanMode.mid (3): the fan should switch to mid mode.
- thermostatFamMode.high (4): the fan should switch to high mode.
- setpoint (double): indicates the setpoint in degrees Celsius, when the type is thermostatCommandType.setSetpoint or thermostatCommandType.setAll.
Examples
A complete example is presented at the beginning of this section.
### closure (object)
The closure property is an object containing the command parameters when it is of type commandType.closure. The object has the following properties:
- type (int enum): indicates the type of command sent to the closure, among the following:
- closureCommandType.open (0): the command is for the closure to open.
- closureCommandType.close (1): the command is for the closure to close.
- closureCommandType.position (2): the command is to change the position of the closure.
- closureCommandType.stop (3): the command is to stop the closure movement.
- closureCommandType.openStop (4): the command is to open the closure, or stop it if it is moving.
- closureCommandType.closeStop (5): the command is to close the closure, or stop it if it is moving.
- position (int): indicates the position to which the closure should move, when the type is closureCommandType.position, as a percentage, between 0% (closed) and 100% (open).
Examples
A complete example is presented at the beginning of this section.
### management (object)
The management property is an object containing the command parameters when it is of type commandType.management. The object has the following properties:
- type (int enum): indicates the type of command sent to the device, among the following:
- managementCommandType.identify (0): requests the device to identify itself. This is used on some devices to have the device activate a visual or audible indicator.
- managementCommandType.reboot (1): requests the device to restart.
- managementCommandType.powerOff (2): requests the device to power off.
- managementCommandType.poll (3): requests the device to send updated information as soon as possible.
- managementCommandType.updateFirmware (4): requests the device to update its firmware.
- managementCommandType.setValue (5): requests the device to change a value.
- updateFirmware (object): indicates the firmware update parameters, when the value of the type field is managementCommandType.updateFirmware. The properties of this object are as follows:
- downloadUrl (string): indicates the URL from which the device should download the firmware update.
- setValue (object): the setValue object contains the necessary information to change the value, when the value of the type field is managementCommandType.setValue. The properties of this object are as follows:
- newValue (double): indicates the new value to be assigned.
Examples
A complete example is presented at the beginning of this section.
### custom (object)
The custom property is an object containing the command parameters when it is of type commandType.custom. The object has the following properties:
- type (int): arbitrary value indicating the custom command type.
- data (string): arbitrary value to be sent to the device.
Examples
A complete example is presented at the beginning of this section.