> For the complete documentation index, see [llms.txt](https://docs.mclimate.eu/mclimate-lorawan-devices/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mclimate.eu/mclimate-lorawan-devices/devices/mclimate-16a-switch-and-power-meter-lorawan-16aspm/decoding-and-bacnet-object-mapping/bacnet-codec-and-definition-files/milesight.md).

# Milesight

## Creation procedure

### **Network Server → Payload Codec → Custom Payload Codec**

Copy and paste each of the following in their respective fields:

#### Payload Decoder Function

```js
// DataCake
function Decoder(bytes, port){
    var decoded = decodeUplink({ bytes: bytes, fPort: port }).data;
    return decoded;
}

// Milesight
function Decode(port, bytes){
    var decoded = decodeUplink({ bytes: bytes, fPort: port }).data;
    return decoded;
}

// The Things Industries / Main
function decodeUplink(input) {
    try {
        var bytes = input.bytes;
        var data = {};

        function handleKeepalive(bytes, data) {
            data.intTemp     = bytes[1];
            var energy       = (bytes[2] << 24) | (bytes[3] << 16) | (bytes[4] << 8) | bytes[5];
            data.energy_kWh  = energy / 1000;
            data.power_W     = (bytes[6] << 8) | bytes[7];
            data.acVolt      = bytes[8];
            data.acCurr_mA   = (bytes[9] << 8) | bytes[10];
            data.relayState_txt = bytes[11] === 0x01 ? "ON" : "OFF";
            return data;
        }

        function handleResponse(bytes, data) {
            var commands = bytes.map(function(byte) {
                return ("0" + byte.toString(16)).substr(-2);
            });
            commands = commands.slice(0, -12);
            var command_len = 0;

            commands.map(function(command, i) {
                switch (command) {
                    case '04':
                        command_len = 2;
                        // Nibble-encoded: 0x14 = version 1.4
                        var hwByte = parseInt(commands[i + 1], 16);
                        var swByte = parseInt(commands[i + 2], 16);
                        data.devHwVer = ((hwByte >> 4) & 0x0F) + ((hwByte & 0x0F) / 10);
                        data.devSwVer = ((swByte >> 4) & 0x0F) + ((swByte & 0x0F) / 10);
                        break;
                    case '12':
                        command_len = 1;
                        data.keepAliveTime = parseInt(commands[i + 1], 16);
                        break;
                    case '19':
                        command_len = 1;
                        data.joinRetry = parseInt(commands[i + 1], 16) * 5 / 60;
                        break;
                    case '1b':
                        command_len = 1;
                        data.uplinkType = parseInt(commands[i + 1], 16);
                        break;
                    case '1d':
                        command_len = 2;
                        data.wdog_wdpC  = parseInt(commands[i + 1], 16);
                        data.wdog_wdpUc = parseInt(commands[i + 2], 16);
                        break;
                    case '1f':
                        command_len = 2;
                        data.overheatTrig = parseInt(commands[i + 1], 16);
                        data.overheatRec  = parseInt(commands[i + 2], 16);
                        break;
                    case '21':
                        command_len = 3;
                        data.overvoltTrig = (parseInt(commands[i + 1], 16) << 8) | parseInt(commands[i + 2], 16);
                        data.overvoltRec  = parseInt(commands[i + 3], 16);
                        break;
                    case '23':
                        command_len = 1;
                        data.overcurrThres = parseInt(commands[i + 1], 16);
                        break;
                    case '25':
                        command_len = 2;
                        data.overpwrThres = (parseInt(commands[i + 1], 16) << 8) | parseInt(commands[i + 2], 16);
                        break;
                    case '5a':
                        command_len = 1;
                        data.afterOverhtRec = parseInt(commands[i + 1], 16);
                        break;
                    case '5c':
                        command_len = 1;
                        data.ledIndMode = parseInt(commands[i + 1], 16);
                        break;
                    case '5d':
                        command_len = 1;
                        data.manualRelay_txt = parseInt(commands[i + 1], 16) === 0x01 ? "ON" : "OFF";
                        break;
                    case '5f':
                        command_len = 1;
                        data.relayRecState = parseInt(commands[i + 1], 16);
                        break;
                    case '60':
                        command_len = 2;
                        data.overheatCnt   = parseInt(commands[i + 1], 16);
                        data.overheatEvTmp = parseInt(commands[i + 2], 16);
                        break;
                    case '61':
                        command_len = 3;
                        data.overvoltCnt  = parseInt(commands[i + 1], 16);
                        data.overvoltVolt = (parseInt(commands[i + 2], 16) << 8) | parseInt(commands[i + 3], 16);
                        break;
                    case '62':
                        command_len = 3;
                        data.overcurrCnt  = parseInt(commands[i + 1], 16);
                        data.overcurrCurr = (parseInt(commands[i + 2], 16) << 8) | parseInt(commands[i + 3], 16);
                        break;
                    case '63':
                        command_len = 3;
                        data.overpowerCnt = parseInt(commands[i + 1], 16);
                        data.overpowerPwr = (parseInt(commands[i + 2], 16) << 8) | parseInt(commands[i + 3], 16);
                        break;
                    case '70':
                        command_len = 2;
                        data.overheatRecTm = (parseInt(commands[i + 1], 16) << 8) | parseInt(commands[i + 2], 16);
                        break;
                    case '71':
                        command_len = 2;
                        data.overvoltRecTm = (parseInt(commands[i + 1], 16) << 8) | parseInt(commands[i + 2], 16);
                        break;
                    case '72':
                        command_len = 1;
                        data.overcurrRecTp = parseInt(commands[i + 1], 16);
                        break;
                    case '73':
                        command_len = 1;
                        data.overpwrRecTmp = parseInt(commands[i + 1], 16);
                        break;
                    case 'b1':
                        command_len = 1;
                        data.relayState_txt = parseInt(commands[i + 1], 16) === 0x01 ? "ON" : "OFF";
                        break;
                    case 'a0':
                        command_len = 4;
                        data.fuota = {
                            fuota_address: (parseInt(commands[i+1],16) << 24) |
                                           (parseInt(commands[i+2],16) << 16) |
                                           (parseInt(commands[i+3],16) << 8)  |
                                            parseInt(commands[i+4],16)
                        };
                        break;
                    default:
                        break;
                }
                commands.splice(i, command_len);
            });
            return data;
        }

        if (bytes[0] === 1) {
            data = handleKeepalive(bytes, data);
        } else {
            data = handleResponse(bytes, data);
            bytes = bytes.slice(-12);
            data = handleKeepalive(bytes, data);
        }
        return { data: data };
    } catch (e) {
        throw new Error('Unhandled data');
    }
}

```

#### Payload Encoder Function

```js
function asNumber(value, fallback) {
  if (value === null || value === undefined || value === "") return fallback;
  if (typeof value === "number") return value;
  var n = Number(value);
  return isNaN(n) ? fallback : n;
}

function asBool(value, fallback) {
  if (value === null || value === undefined || value === "") return fallback;
  if (typeof value === "boolean") return value;
  if (typeof value === "number") return value !== 0;
  if (typeof value === "string") {
    var v = value.trim().toLowerCase();
    if (v === "true" || v === "on" || v === "1" || v === "yes") return true;
    if (v === "false" || v === "off" || v === "0" || v === "no") return false;
  }
  return fallback;
}

function parseMaybeJson(value) {
  if (value && typeof value === "object") return value;
  if (typeof value !== "string") return value;
  try {
    return JSON.parse(value);
  } catch (e) {
    return value;
  }
}

function normalizeCall(portOrInput, maybeInput) {
  var fPort = 1;
  var input = {};
  var legacy = arguments.length >= 2 && maybeInput !== undefined && maybeInput !== null;

  if (legacy) {
    fPort = portOrInput || 1;
    input = maybeInput || {};
  } else {
    input = portOrInput || {};
    fPort = input.fPort || input.port || 1;
  }

  if (!input.hasOwnProperty("data")) {
    input = { data: input };
  }

  return {
    legacy: legacy,
    fPort: fPort,
    data: input.data || {}
  };
}

function normalizeInputData(data) {
  var out = {};
  var key;

  // exact commands first
  for (key in data) {
    if (!data.hasOwnProperty(key)) continue;

    switch (key) {
      case "setKeepAlive":
      case "setJoinRetryPeriod":
      case "setUplinkType":
      case "setOvercurrentThreshold":
      case "setOverpowerThreshold":
      case "setLedIndicationMode":
      case "setRelayRecoveryState":
      case "setRelayState":
        out[key] = asNumber(data[key], 0);
        break;

      case "setAfterOverheatingProtectionRecovery":
        out[key] = asBool(data[key], false) ? 1 : 0;
        break;

      case "setWatchDogParams":
      case "setOverheatingThresholds":
      case "setOvervoltageThresholds":
        out[key] = parseMaybeJson(data[key]);
        break;

      case "sendCustomHexCommand":
        out[key] = String(data[key] || "");
        break;

      default:
        out[key] = data[key];
        break;
    }
  }

  // legacy short aliases, only if exact command is not already present
  if (!out.hasOwnProperty("setJoinRetryPeriod") && data.hasOwnProperty("joinRetry")) {
    out.setJoinRetryPeriod = asNumber(data.joinRetry, 0);
  }
  if (!out.hasOwnProperty("setOvercurrentThreshold") && data.hasOwnProperty("overcurrThres")) {
    out.setOvercurrentThreshold = asNumber(data.overcurrThres, 0);
  }
  if (!out.hasOwnProperty("setOverpowerThreshold") && data.hasOwnProperty("overpwrThres")) {
    out.setOverpowerThreshold = asNumber(data.overpwrThres, 0);
  }
  if (!out.hasOwnProperty("setAfterOverheatingProtectionRecovery") && data.hasOwnProperty("afterOverhtRec")) {
    out.setAfterOverheatingProtectionRecovery = asBool(data.afterOverhtRec, false) ? 1 : 0;
  }
  if (!out.hasOwnProperty("setLedIndicationMode") && data.hasOwnProperty("ledIndMode")) {
    out.setLedIndicationMode = asNumber(data.ledIndMode, 0);
  }
  if (!out.hasOwnProperty("setRelayRecoveryState") && data.hasOwnProperty("relayRecState")) {
    out.setRelayRecoveryState = asNumber(data.relayRecState, 0);
  }

  if (!out.hasOwnProperty("setWatchDogParams") && (data.hasOwnProperty("wdog_wdpC") || data.hasOwnProperty("wdog_wdpUc"))) {
    out.setWatchDogParams = {
      confirmedUplinks: asNumber(data.wdog_wdpC, 0),
      unconfirmedUplinks: asNumber(data.wdog_wdpUc, 0)
    };
  }

  if (!out.hasOwnProperty("setOverheatingThresholds") && (data.hasOwnProperty("overheatTrig") || data.hasOwnProperty("overheatRec"))) {
    out.setOverheatingThresholds = {
      trigger: asNumber(data.overheatTrig, 0),
      recovery: asNumber(data.overheatRec, 0)
    };
  }

  if (!out.hasOwnProperty("setOvervoltageThresholds") && (data.hasOwnProperty("overvoltTrig") || data.hasOwnProperty("overvoltRec"))) {
    out.setOvervoltageThresholds = {
      trigger: asNumber(data.overvoltTrig, 0),
      recovery: asNumber(data.overvoltRec, 0)
    };
  }

  return out;
}

function encodeDownlink(input) {
  var bytes = [];
  var data = normalizeInputData((input && input.data) || {});
  var key, i;

  for (key in data) {
    if (!data.hasOwnProperty(key)) continue;

    switch (key) {
      case "setKeepAlive":
        bytes.push(0x02);
        bytes.push(asNumber(data.setKeepAlive, 0) & 0xFF);
        break;

      case "getKeepAliveTime":
        bytes.push(0x12);
        break;

      case "getDeviceVersions":
        bytes.push(0x04);
        break;

      case "setJoinRetryPeriod":
        var periodToPass = Math.floor((asNumber(data.setJoinRetryPeriod, 0) * 60) / 5);
        bytes.push(0x10);
        bytes.push(periodToPass & 0xFF);
        break;

      case "getJoinRetryPeriod":
        bytes.push(0x19);
        break;

      case "setUplinkType":
        bytes.push(0x11);
        bytes.push(asNumber(data.setUplinkType, 0) & 0xFF);
        break;

      case "getUplinkType":
        bytes.push(0x1b);
        break;

      case "setWatchDogParams":
        bytes.push(0x1c);
        bytes.push(asNumber((data.setWatchDogParams || {}).confirmedUplinks, 0) & 0xFF);
        bytes.push(asNumber((data.setWatchDogParams || {}).unconfirmedUplinks, 0) & 0xFF);
        break;

      case "getWatchDogParams":
        bytes.push(0x1d);
        break;

      case "setOverheatingThresholds":
        bytes.push(0x1e);
        bytes.push(asNumber((data.setOverheatingThresholds || {}).trigger, 0) & 0xFF);
        bytes.push(asNumber((data.setOverheatingThresholds || {}).recovery, 0) & 0xFF);
        break;

      case "getOverheatingThresholds":
        bytes.push(0x1f);
        break;

      case "setOvervoltageThresholds":
        // FIX: trigger is UINT16 (2 bytes hi+lo); recovery is UINT8 (1 byte).
        // Confirmed by uplink decoder case '21': reads (hi<<8)|lo for trigger,
        // single byte for recovery. Previously only 1 byte was pushed for
        // trigger, truncating any value >255V to its low byte.
        var overvoltTrig = asNumber((data.setOvervoltageThresholds || {}).trigger, 0);
        var overvoltRec  = asNumber((data.setOvervoltageThresholds || {}).recovery, 0);
        bytes.push(0x20);
        bytes.push((overvoltTrig >> 8) & 0xFF);  // trigger high byte
        bytes.push(overvoltTrig & 0xFF);           // trigger low byte
        bytes.push(overvoltRec & 0xFF);            // recovery byte
        break;

      case "getOvervoltageThresholds":
        bytes.push(0x21);
        break;

      case "setOvercurrentThreshold":
        bytes.push(0x22);
        bytes.push(asNumber(data.setOvercurrentThreshold, 0) & 0xFF);
        break;

      case "getOvercurrentThreshold":
        bytes.push(0x23);
        break;

      case "setOverpowerThreshold":
        // FIX: value is UINT16 (2 bytes hi+lo) for FW>=1.4.
        // Previously only 1 byte was pushed, so any value >255W was silently
        // truncated and the device (running FW14) interpreted the single-byte
        // command as malformed and ignored it entirely.
        var overpwr = asNumber(data.setOverpowerThreshold, 0);
        bytes.push(0x24);
        bytes.push((overpwr >> 8) & 0xFF);  // high byte
        bytes.push(overpwr & 0xFF);           // low byte
        break;

      case "getOverpowerThreshold":
        bytes.push(0x25);
        break;

      case "setAfterOverheatingProtectionRecovery":
        bytes.push(0x59);
        bytes.push(asBool(data.setAfterOverheatingProtectionRecovery, false) ? 1 : 0);
        break;

      case "getAfterOverheatingProtectionRecovery":
        bytes.push(0x5a);
        break;

      case "setLedIndicationMode":
        bytes.push(0x5b);
        bytes.push(asNumber(data.setLedIndicationMode, 0) & 0xFF);
        break;

      case "getLedIndicationMode":
        bytes.push(0x5c);
        break;

      case "setRelayRecoveryState":
        bytes.push(0x5e);
        bytes.push(asNumber(data.setRelayRecoveryState, 0) & 0xFF);
        break;

      case "getRelayRecoveryState":
        bytes.push(0x5f);
        break;

      case "setRelayState":
        bytes.push(0xc1);
        bytes.push(asNumber(data.setRelayState, 0) & 0xFF);
        break;

      case "getRelayState":
        bytes.push(0xb1);
        break;

      case "getOverheatingEvents":
        bytes.push(0x60);
        break;

      case "getOvervoltageEvents":
        bytes.push(0x61);
        break;

      case "getOvercurrentEvents":
        bytes.push(0x62);
        break;

      case "getOverpowerEvents":
        bytes.push(0x63);
        break;

      case "getOverheatingRecoveryTime":
        bytes.push(0x70);
        break;

      case "getOvervoltageRecoveryTime":
        bytes.push(0x71);
        break;

      case "getOvercurrentRecoveryTemp":
        bytes.push(0x72);
        break;

      case "getOverpowerRecoveryTemp":
        bytes.push(0x73);
        break;

      case "sendCustomHexCommand":
        var sendCustomHexCommand = String(data.sendCustomHexCommand || "").replace(/\s+/g, "");
        for (i = 0; i < sendCustomHexCommand.length; i += 2) {
          var byte = parseInt(sendCustomHexCommand.substr(i, 2), 16);
          if (!isNaN(byte)) bytes.push(byte);
        }
        break;

      default:
        break;
    }
  }

  return {
    bytes: bytes,
    fPort: (input && input.fPort) || 1,
    warnings: [],
    errors: []
  };
}

function Encode(portOrInput, maybeInput) {
  var call = normalizeCall(portOrInput, maybeInput);
  var result = encodeDownlink({
    fPort: call.fPort,
    data: call.data
  });

  // legacy style: Encode(port, input) -> return raw bytes
  if (call.legacy) {
    return result.bytes;
  }

  // UG65 style: Encode(input) -> return object
  return result;
}

function decodeDownlink(input) {
  return {
    data: {
      bytes: input.bytes
    },
    warnings: [],
    errors: []
  };
}

```

#### Object Mapping Function (JSON Function)

```json
{
    "object": [
        {
            "id": "intTemp",
            "name": "Internal Temp",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "energy_kWh",
            "name": "Energy",
            "value": "",
            "unit": "kWh",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 19,
            "bacnet_unit_type": "UNITS_KILOWATT_HOURS"
        },
        {
            "id": "power_W",
            "name": "Power",
            "value": "",
            "unit": "W",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 47,
            "bacnet_unit_type": "UNITS_WATTS"
        },
        {
            "id": "acVolt",
            "name": "AC Voltage",
            "value": "",
            "unit": "V",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 5,
            "bacnet_unit_type": "UNITS_VOLTS"
        },
        {
            "id": "acCurr_mA",
            "name": "AC Current",
            "value": "",
            "unit": "mA",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 2,
            "bacnet_unit_type": "UNITS_MILLIAMPERES"
        },
        {
            "id": "relayState_txt",
            "name": "Relay State",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 8
        },
        {
            "id": "devHwVer",
            "name": "HW Version",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "devSwVer",
            "name": "SW Version",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "keepAliveTime",
            "name": "KeepAlive",
            "value": "",
            "unit": "min",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 72,
            "bacnet_unit_type": "UNITS_MINUTES"
        },
        {
            "id": "joinRetry",
            "name": "Join Retry",
            "value": "",
            "unit": "h",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 71,
            "bacnet_unit_type": "UNITS_HOURS"
        },
        {
            "id": "uplinkType",
            "name": "Uplink Type",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "ENUM",
            "value_type": "UINT8",
            "bacnet_type": "multistate_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Unconfirmed" },
                { "value": 1, "name": "Confirmed" }
            ]
        },
        {
            "id": "wdog_wdpC",
            "name": "WDP-C",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "wdog_wdpUc",
            "name": "WDP-UC",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "overheatTrig",
            "name": "OHeat Trig",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "overheatRec",
            "name": "OHeat Rec",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "overvoltTrig",
            "name": "OVolt Trig",
            "value": "",
            "unit": "V",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 5,
            "bacnet_unit_type": "UNITS_VOLTS"
        },
        {
            "id": "overvoltRec",
            "name": "OVolt Rec",
            "value": "",
            "unit": "V",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 5,
            "bacnet_unit_type": "UNITS_VOLTS"
        },
        {
            "id": "overcurrThres",
            "name": "OCurr Thr",
            "value": "",
            "unit": "A",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 2,
            "bacnet_unit_type": "UNITS_MILLIAMPERES"
        },
        {
            "id": "overpwrThres",
            "name": "OPower Thr",
            "value": "",
            "unit": "W",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 47,
            "bacnet_unit_type": "UNITS_WATTS"
        },
        {
            "id": "afterOverhtRec",
            "name": "After OHeat",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "ledIndMode",
            "name": "LED Mode",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "manualRelay_txt",
            "name": "Manual Relay",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 8
        },
        {
            "id": "relayRecState",
            "name": "Relay Rec",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "ENUM",
            "value_type": "UINT8",
            "bacnet_type": "multistate_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Restore Last" },
                { "value": 1, "name": "Off" },
                { "value": 2, "name": "On" }
            ]
        },
        {
            "id": "overheatCnt",
            "name": "OH Cnt",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "overheatEvTmp",
            "name": "OH Temp",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "overvoltCnt",
            "name": "OV Cnt",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "overvoltVolt",
            "name": "OV Volt",
            "value": "",
            "unit": "V",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 5,
            "bacnet_unit_type": "UNITS_VOLTS"
        },
        {
            "id": "overcurrCnt",
            "name": "OC Cnt",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "overcurrCurr",
            "name": "OC Curr",
            "value": "",
            "unit": "mA",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 2,
            "bacnet_unit_type": "UNITS_MILLIAMPERES"
        },
        {
            "id": "overpowerCnt",
            "name": "OP Cnt",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "overpowerPwr",
            "name": "OP Power",
            "value": "",
            "unit": "W",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 47,
            "bacnet_unit_type": "UNITS_WATTS"
        },
        {
            "id": "overheatRecTm",
            "name": "OH RecTime",
            "value": "",
            "unit": "s",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 73,
            "bacnet_unit_type": "UNITS_SECONDS"
        },
        {
            "id": "overvoltRecTm",
            "name": "OV RecTime",
            "value": "",
            "unit": "s",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 73,
            "bacnet_unit_type": "UNITS_SECONDS"
        },
        {
            "id": "overcurrRecTp",
            "name": "OC RecTemp",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "overpwrRecTmp",
            "name": "OP RecTemp",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "setKeepAlive",
            "name": "Set KeepAlv",
            "value": "",
            "unit": "min",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 72,
            "bacnet_unit_type": "UNITS_MINUTES"
        },
        {
            "id": "setJoinRetryPeriod",
            "name": "Set JoinRt",
            "value": "",
            "unit": "h",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 71,
            "bacnet_unit_type": "UNITS_HOURS"
        },
        {
            "id": "setUplinkType",
            "name": "Set Uplink",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Unconfirmed" },
                { "value": 1, "name": "Confirmed" }
            ]
        },
        {
            "id": "setWatchDogParams",
            "name": "Set WD Pms",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 128
        },
        {
            "id": "setOverheatingThresholds",
            "name": "Set OHeat",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 128
        },
        {
            "id": "setOvervoltageThresholds",
            "name": "Set OVolt",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 128
        },
        {
            "id": "setOvercurrentThreshold",
            "name": "Set OCurr",
            "value": "",
            "unit": "mA",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 2,
            "bacnet_unit_type": "UNITS_MILLIAMPERES"
        },
        {
            "id": "setOverpowerThreshold",
            "name": "Set OPwr",
            "value": "",
            "unit": "W",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 47,
            "bacnet_unit_type": "UNITS_WATTS"
        },
        {
            "id": "setAfterOverheatingProtectionRecovery",
            "name": "Set AHPR",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Off" },
                { "value": 1, "name": "On" }
            ]
        },
        {
            "id": "setLedIndicationMode",
            "name": "Set LED",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Off" },
                { "value": 1, "name": "On" }
            ]
        },
        {
            "id": "setRelayRecoveryState",
            "name": "Set RelRec",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "ENUM",
            "value_type": "UINT8",
            "bacnet_type": "multistate_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Restore Last" },
                { "value": 1, "name": "Off" },
                { "value": 2, "name": "On" }
            ]
        },
        {
            "id": "setRelayState",
            "name": "Set Relay",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Off" },
                { "value": 1, "name": "On" }
            ]
        },
        {
            "id": "getKeepAliveTime",
            "name": "Get KeepAlv",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getDeviceVersions",
            "name": "Get DevVers",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getJoinRetryPeriod",
            "name": "Get JoinRt",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getUplinkType",
            "name": "Get Uplink",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getWatchDogParams",
            "name": "Get WD Pms",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverheatingThresholds",
            "name": "Get OHeat",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvervoltageThresholds",
            "name": "Get OVolt",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvercurrentThreshold",
            "name": "Get OCurr",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverpowerThreshold",
            "name": "Get OPwr",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getAfterOverheatingProtectionRecovery",
            "name": "Get AHPR",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getLedIndicationMode",
            "name": "Get LED",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getRelayRecoveryState",
            "name": "Get RelRec",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getRelayState",
            "name": "Get Relay",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverheatingEvents",
            "name": "Get OHEv",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvervoltageEvents",
            "name": "Get OVEv",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvercurrentEvents",
            "name": "Get OCEv",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverpowerEvents",
            "name": "Get OPEv",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverheatingRecoveryTime",
            "name": "Get OHRecT",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvervoltageRecoveryTime",
            "name": "Get OVRecT",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOvercurrentRecoveryTemp",
            "name": "Get OCRecT",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "getOverpowerRecoveryTemp",
            "name": "Get OPRecT",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "BOOL",
            "value_type": "UINT8",
            "bacnet_type": "binary_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "values": [
                { "value": 0, "name": "Idle" },
                { "value": 1, "name": "Run" }
            ]
        },
        {
            "id": "sendCustomHexCommand",
            "name": "Send HexCmd",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "TEXT",
            "value_type": "STRING",
            "bacnet_type": "character_string_value_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS",
            "max_length": 242
        }
    ]
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mclimate.eu/mclimate-lorawan-devices/devices/mclimate-16a-switch-and-power-meter-lorawan-16aspm/decoding-and-bacnet-object-mapping/bacnet-codec-and-definition-files/milesight.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
