> 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-dry-switch-16ads/decoding-and-bacnet-object-mapping/bacnet-codec-and-definition-files/milesight.md).

# Milesight

## Creation procedure <a href="#creation-procedure" id="creation-procedure"></a>

### **Network Server → Payload Codec → Custom Payload Codec** <a href="#network-server-payload-codec-custom-payload-codec" id="network-server-payload-codec-custom-payload-codec"></a>

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) {
            // byte1: bit7 sign, bits6:0 |T| degC; byte2: relay 0/1
            var isNegative = (bytes[1] & 0x80) !== 0;
            var temperature = bytes[1] & 0x7F;
            data.internalTemperature = isNegative ? -temperature : temperature;
            data.relayState = bytes[2] === 0x01 ? 1 : 0;   // FIX D2: numeric
            return data;
        }

        function handleResponse(bytes, data) {
            var commands = bytes.map(function (byte) {
                return ("0" + byte.toString(16)).substr(-2);
            });
            // FIX D10: the trailing 3 bytes are the appended keepalive frame —
            // do not let them be parsed as command bytes.
            commands = commands.slice(0, -3);
            var command_len = 0;

            commands.map(function (command, i) {
                switch (command) {
                    case '04': {
                        command_len = 2;
                        // FIX D1: nibble-encoded, 0x12 -> 1.2
                        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); // minutes
                        break;
                    }
                    case '19': {
                        command_len = 1;
                        // raw*5 seconds -> minutes (FIX D12: unit is MINUTES)
                        data.joinRetryPeriod = (parseInt(commands[i + 1], 16) * 5) / 60;
                        break;
                    }
                    case '1b': {
                        command_len = 1;
                        data.uplinkType = parseInt(commands[i + 1], 16); // 0 unconf, 1 conf
                        break;
                    }
                    case '1d': {
                        command_len = 2;
                        // FIX D7: plain numbers (0 = disabled), no false/number mix
                        data.wdogConfirmed   = parseInt(commands[i + 1], 16); // uplink count
                        data.wdogUnconfirmed = parseInt(commands[i + 2], 16); // hours
                        break;
                    }
                    case '1f': {
                        command_len = 2;
                        // FIX D6: flat scalar keys
                        data.overheatingThresholdTrigger  = parseInt(commands[i + 1], 16); // degC
                        data.overheatingThresholdRecovery = parseInt(commands[i + 2], 16); // degC
                        break;
                    }
                    case '54': {
                        command_len = 1;
                        // FIX D3: 0 restart, 1 manual, 2 overheating,
                        // 6 radio C1/F1, 7 radio timers (non-contiguous)
                        data.relayStateChangeReason = parseInt(commands[i + 1], 16);
                        break;
                    }
                    case '56': {
                        command_len = 3;
                        // FIX D4: state + 16-bit REMAINING milliseconds
                        data.relayTimerMsState = parseInt(commands[i + 1], 16);
                        data.relayTimerMsRemaining =
                            (parseInt(commands[i + 2], 16) << 8) | parseInt(commands[i + 3], 16);
                        break;
                    }
                    case '58': {
                        command_len = 3;
                        // FIX D4: state + 16-bit REMAINING seconds
                        data.relayTimerSState = parseInt(commands[i + 1], 16);
                        data.relayTimerSRemaining =
                            (parseInt(commands[i + 2], 16) << 8) | parseInt(commands[i + 3], 16);
                        break;
                    }
                    case '5a': {
                        command_len = 1;
                        // 0 last state, 1 force OFF after overheating recovery
                        data.afterOverheatingRecovery = parseInt(commands[i + 1], 16);
                        break;
                    }
                    case '5c': {
                        command_len = 1;
                        data.ledIndicationMode = parseInt(commands[i + 1], 16); // 0 off, 1 on
                        break;
                    }
                    case '5d': {
                        command_len = 1;
                        // FIX D5: numeric 0/1 (button-changed relay state event)
                        data.manualChangeRelayState = parseInt(commands[i + 1], 16) === 0x01 ? 1 : 0;
                        break;
                    }
                    case '5f': {
                        command_len = 1;
                        // 0 last state, 1 ON, 2 OFF after return of power supply
                        data.relayRecoveryState = parseInt(commands[i + 1], 16);
                        break;
                    }
                    case '60': {
                        command_len = 2;
                        // FIX D8: flat scalar keys
                        data.overheatingEventsCount       = parseInt(commands[i + 1], 16);
                        data.overheatingEventsTemperature = parseInt(commands[i + 2], 16); // degC
                        break;
                    }
                    case '70': {
                        command_len = 2;
                        // 16-bit protection running time, seconds
                        data.overheatingRecoveryTime =
                            (parseInt(commands[i + 1], 16) << 8) | parseInt(commands[i + 2], 16);
                        break;
                    }
                    case 'b1': {
                        command_len = 1;
                        data.relayState = parseInt(commands[i + 1], 16) === 0x01 ? 1 : 0; // FIX D2
                        break;
                    }
                    case 'a0': {
                        command_len = 4;
                        // FIX D11: flat (FUOTA multicast address report)
                        data.fuotaAddress =
                            (parseInt(commands[i + 1], 16) << 24) |
                            (parseInt(commands[i + 2], 16) << 16) |
                            (parseInt(commands[i + 3], 16) << 8)  |
                             parseInt(commands[i + 4], 16);
                        break;
                    }
                    case 'a4': {
                        command_len = 1;
                        // 0 EU868, 1 AS923, 2 AU915, 3 US915 (protocol page order)
                        data.lorawanRegion = parseInt(commands[i + 1], 16);
                        break;
                    }
                    case 'd1': {
                        command_len = 25;
                        // FIX D9: index(1) + DevEUI(8) + AppKey(16)
                        data.d2dDeviceIndex = parseInt(commands[i + 1], 16);
                        var eui = '', key = '', j;
                        for (j = 2; j <= 9; j++)  eui += commands[i + j];
                        for (j = 10; j <= 25; j++) key += commands[i + j];
                        data.d2dDevEui = eui.toUpperCase();
                        data.d2dAppKey = key.toUpperCase();
                        break;
                    }
                    case 'd3': {
                        command_len = 5;
                        // FIX D9: bandwidth(0/1/2) + SF(7-12) + 24-bit freq*100 Hz
                        data.d2dBandwidth       = parseInt(commands[i + 1], 16);
                        data.d2dSpreadingFactor = parseInt(commands[i + 2], 16);
                        data.d2dFrequency =
                            ((parseInt(commands[i + 3], 16) << 16) |
                             (parseInt(commands[i + 4], 16) << 8)  |
                              parseInt(commands[i + 5], 16)) * 100; // Hz
                        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(-3);
            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" || v === "active") return true;
    if (v === "false" || v === "off" || v === "0" || v === "no" || v === "inactive") 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 clamp(v, lo, hi) {
  return Math.max(lo, Math.min(hi, v));
}

function pushU16(bytes, v) {
  bytes.push((v >> 8) & 0xFF);
  bytes.push(v & 0xFF);
}

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

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

      // ── keep-alive / network ─────────────────────────────────────────
      case "setKeepAlive": // 0x02, minutes 1..255 (0x00 not applicable)
        bytes.push(0x02);
        bytes.push(clamp(Math.round(asNumber(data[key], 10)), 1, 255) & 0xFF);
        break;

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

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

      case "setJoinRetryPeriod": { // 0x10, input MINUTES, raw = min*60/5 (FIX E7)
        var raw = clamp(Math.round((asNumber(data[key], 10) * 60) / 5), 1, 255);
        bytes.push(0x10);
        bytes.push(raw & 0xFF);
        break;
      }

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

      case "setUplinkType": // 0x11, 0 unconfirmed / 1 confirmed
        bytes.push(0x11);
        bytes.push(asBool(data[key], true) ? 0x01 : 0x00);
        break;

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

      case "setWatchDogParams": { // 0x1C, JSON {"confirmedUplinks":2,"unconfirmedUplinks":24}
        var wd = parseMaybeJson(data[key]) || {};
        bytes.push(0x1c);
        bytes.push(clamp(Math.round(asNumber(wd.confirmedUplinks, 2)), 0, 255) & 0xFF);
        bytes.push(clamp(Math.round(asNumber(wd.unconfirmedUplinks, 24)), 0, 255) & 0xFF);
        break;
      }

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

      // ── overheating protection ───────────────────────────────────────
      case "setOverheatingThresholds": { // 0x1E, JSON {"trigger":85,"recovery":70}, 30..100 degC
        var ot = parseMaybeJson(data[key]) || {};
        bytes.push(0x1e);
        bytes.push(clamp(Math.round(asNumber(ot.trigger, 85)), 30, 100) & 0xFF);
        bytes.push(clamp(Math.round(asNumber(ot.recovery, 70)), 30, 100) & 0xFF);
        break;
      }

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

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

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

      case "setAfterOverheatingRecovery": // 0x59, 0 last state / 1 force OFF (FIX E9)
      case "setAfterOverheatingProtectionRecovery": // vendor alias
        bytes.push(0x59);
        bytes.push(asBool(data[key], false) ? 0x01 : 0x00);
        break;

      case "getAfterOverheatingRecovery": // 0x5A
      case "getAfterOverheatingProtectionRecovery": // vendor alias
        bytes.push(0x5a);
        break;

      // ── relay ────────────────────────────────────────────────────────
      case "setRelayState": // 0xC1, 0 OFF / 1 ON
        bytes.push(0xc1);
        bytes.push(asBool(data[key], false) ? 0x01 : 0x00);
        break;

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

      case "flipRelayState": // 0xF1, fw>=1.2, guarded one-shot (FIX E1)
        if (asBool(data[key], false)) bytes.push(0xf1);
        break;

      case "getRelayStateChangeReason": // 0x54, fw>=1.1
        bytes.push(0x54);
        break;

      case "setRelayTimerMilliseconds": // 0x55, JSON {"state":1,"time":500}, 50..65535 ms (FIX E4)
      case "setRelayTimerMiliseconds": { // vendor alias (misspelling)
        var tm = parseMaybeJson(data[key]) || {};
        bytes.push(0x55);
        bytes.push(asBool(tm.state, false) ? 0x01 : 0x00);
        pushU16(bytes, clamp(Math.round(asNumber(tm.time, 50)), 50, 65535));
        break;
      }

      case "getRelayTimerMilliseconds": // 0x56
      case "getRelayTimerMiliseconds": // vendor alias
        bytes.push(0x56);
        break;

      case "setRelayTimerSeconds": { // 0x57, JSON {"state":1,"time":3}, 1..65535 s
        var ts = parseMaybeJson(data[key]) || {};
        bytes.push(0x57);
        bytes.push(asBool(ts.state, false) ? 0x01 : 0x00);
        pushU16(bytes, clamp(Math.round(asNumber(ts.time, 1)), 1, 65535));
        break;
      }

      case "getRelayTimerSeconds": // 0x58
        bytes.push(0x58);
        break;

      case "setRelayRecoveryState": // 0x5E, 0 last / 1 ON / 2 OFF (after power return)
        bytes.push(0x5e);
        bytes.push(clamp(Math.round(asNumber(data[key], 0)), 0, 2) & 0xFF);
        break;

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

      // ── LED ──────────────────────────────────────────────────────────
      case "setLedIndicationMode": // 0x5B, 0 off / 1 on
        bytes.push(0x5b);
        bytes.push(asBool(data[key], true) ? 0x01 : 0x00);
        break;

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

      // ── region / restart ─────────────────────────────────────────────
      case "getLoRaWANRegion": // 0xA4 (FIX E6)
        bytes.push(0xa4);
        break;

      case "restartDevice": // 0xA5, guarded one-shot (FIX E2)
        if (asBool(data[key], false)) bytes.push(0xa5);
        break;

      // ── D2D (fw>=1.2) (FIX E5) ───────────────────────────────────────
      case "setD2dCredentials": { // 0xD0, JSON {"index":0,"devEui":"70B3...","appKey":"AA6C..."}
        var d2d = parseMaybeJson(data[key]) || {};
        var eui = String(d2d.devEui || "").replace(/[^0-9a-fA-F]/g, "");
        var akey = String(d2d.appKey || "").replace(/[^0-9a-fA-F]/g, "");
        if (eui.length === 16 && akey.length === 32) {
          bytes.push(0xd0);
          bytes.push(clamp(Math.round(asNumber(d2d.index, 0)), 0, 5) & 0xFF);
          for (i = 0; i < 16; i += 2) bytes.push(parseInt(eui.substr(i, 2), 16));
          for (i = 0; i < 32; i += 2) bytes.push(parseInt(akey.substr(i, 2), 16));
        }
        break;
      }

      case "getD2dCredentials": // 0xD1 + index 0..5
        bytes.push(0xd1);
        bytes.push(clamp(Math.round(asNumber(data[key], 0)), 0, 5) & 0xFF);
        break;

      case "removeD2dCredentials": // 0xD2, guarded one-shot (wipes ALL pairings)
        if (asBool(data[key], false)) bytes.push(0xd2);
        break;

      case "getD2dRadioSettings": // 0xD3
        bytes.push(0xd3);
        break;

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

      default:
        break;
    }
  }

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

function normalizeCall(portOrInput, maybeInput) {
  // Encode(port, input) legacy two-arg style vs Encode(input) UG65/UG67 style.
  // The maybeInput !== undefined guard matters: a falsy-but-present second arg
  // must still be treated as the legacy call (16ASPM empty-payload root cause).
  if (maybeInput !== undefined) {
    var inp = maybeInput;
    if (inp && inp.data === undefined) inp = { data: inp };
    return { legacy: true, fPort: asNumber(portOrInput, 1), data: (inp && inp.data) || {} };
  }
  var input = portOrInput || {};
  if (input.data === undefined) input = { data: input };
  return { legacy: false, fPort: (input && input.fPort) || 1, data: input.data || {} };
}

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

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

function Encoder(portOrInput, maybeInput) {
  return Encode(portOrInput, maybeInput);
}

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

// example downlink commands
// {"setRelayState": 1}                                   --> 0xC101
// {"flipRelayState": 1}                                  --> 0xF1
// {"getDeviceVersions": ""}                              --> 0x04
// {"getKeepAliveTime": ""}                               --> 0x12
// {"setKeepAlive": 15}                                   --> 0x020F
// {"setJoinRetryPeriod": 20}                             --> 0x10F0
// {"setWatchDogParams": {"confirmedUplinks":3,"unconfirmedUplinks":0}} --> 0x1C0300
// {"setOverheatingThresholds": {"trigger":90,"recovery":60}}           --> 0x1E5A3C
// {"setRelayTimerMilliseconds": {"state":0,"time":500}}  --> 0x550001F4
// {"setRelayTimerSeconds": {"state":0,"time":3}}         --> 0x57000003
// {"setAfterOverheatingRecovery": 1}                     --> 0x5901
// {"setRelayRecoveryState": 2}                           --> 0x5E02
// {"setLedIndicationMode": 0}                            --> 0x5B00
// {"getD2dCredentials": 0}                               --> 0xD100
// {"sendCustomHexCommand": "1C0218"}                     --> 0x1C0218

```

#### **Object Mapping Function (JSON Function)**

```json
{
    "object": [
        {
            "id": "internalTemperature",
            "name": "Internal Temp",
            "value": "",
            "unit": "°C",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "INT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 62,
            "bacnet_unit_type": "UNITS_DEGREES_CELSIUS"
        },
        {
            "id": "relayState",
            "name": "Relay State",
            "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": "devHwVer",
            "name": "HW Version",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "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": "FLOAT",
            "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": "joinRetryPeriod",
            "name": "Join Retry",
            "value": "",
            "unit": "min",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 72,
            "bacnet_unit_type": "UNITS_MINUTES"
        },
        {
            "id": "uplinkType",
            "name": "Uplink Type",
            "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": "wdogConfirmed",
            "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": "wdogUnconfirmed",
            "name": "WDP-UC",
            "value": "",
            "unit": "h",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 71,
            "bacnet_unit_type": "UNITS_HOURS"
        },
        {
            "id": "overheatingThresholdTrigger",
            "name": "Overheat Trigger",
            "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": "overheatingThresholdRecovery",
            "name": "Overheat Recovery",
            "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": "relayStateChangeReason",
            "name": "Relay Chg Reason",
            "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": "relayTimerMsState",
            "name": "Timer ms State",
            "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": "relayTimerMsRemaining",
            "name": "Timer ms Left",
            "value": "",
            "unit": "ms",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT16",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 159,
            "bacnet_unit_type": "UNITS_MILLISECONDS"
        },
        {
            "id": "relayTimerSState",
            "name": "Timer s State",
            "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": "relayTimerSRemaining",
            "name": "Timer s Left",
            "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": "afterOverheatingRecovery",
            "name": "After Overheat",
            "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": "ledIndicationMode",
            "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": "manualChangeRelayState",
            "name": "Manual Relay Chg",
            "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": "relayRecoveryState",
            "name": "Relay Recovery",
            "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": "overheatingEventsCount",
            "name": "Overheat Events",
            "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": "overheatingEventsTemperature",
            "name": "Overheat Ev 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": "overheatingRecoveryTime",
            "name": "Overheat Runtime",
            "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": "lorawanRegion",
            "name": "LoRaWAN Region",
            "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": "fuotaAddress",
            "name": "FUOTA Address",
            "value": "",
            "unit": "",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT32",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "d2dBandwidth",
            "name": "D2D Bandwidth",
            "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": "d2dSpreadingFactor",
            "name": "D2D SF",
            "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": "d2dFrequency",
            "name": "D2D Frequency",
            "value": "",
            "unit": "Hz",
            "access_mode": "R",
            "data_type": "NUMBER",
            "value_type": "UINT32",
            "bacnet_type": "analog_input_object",
            "bacnet_unit_type_id": 27,
            "bacnet_unit_type": "UNITS_HERTZ"
        },
        {
            "id": "d2dDeviceIndex",
            "name": "D2D Index",
            "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": "d2dDevEui",
            "name": "D2D DevEUI",
            "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": 16
        },
        {
            "id": "d2dAppKey",
            "name": "D2D AppKey",
            "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": 32
        },
        {
            "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": "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": "min",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "FLOAT",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 72,
            "bacnet_unit_type": "UNITS_MINUTES"
        },
        {
            "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 Overheat Thr",
            "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": "setRelayTimerMilliseconds",
            "name": "Set Timer ms",
            "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": "setRelayTimerSeconds",
            "name": "Set Timer s",
            "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": "setAfterOverheatingRecovery",
            "name": "Set AfterOvht",
            "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": "Last state"
                },
                {
                    "value": 1,
                    "name": "Force Off"
                }
            ]
        },
        {
            "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 Relay Rcv",
            "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": "Last state"
                },
                {
                    "value": 1,
                    "name": "On"
                },
                {
                    "value": 2,
                    "name": "Off"
                }
            ]
        },
        {
            "id": "flipRelayState",
            "name": "Flip 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": "restartDevice",
            "name": "Restart Dev",
            "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": "setD2dCredentials",
            "name": "Set D2D Cred",
            "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": "getD2dCredentials",
            "name": "Get D2D Cred",
            "value": "",
            "unit": "",
            "access_mode": "W",
            "data_type": "NUMBER",
            "value_type": "UINT8",
            "bacnet_type": "analog_output_object",
            "bacnet_unit_type_id": 95,
            "bacnet_unit_type": "UNITS_NO_UNITS"
        },
        {
            "id": "removeD2dCredentials",
            "name": "Del D2D Cred",
            "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
        },
        {
            "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": "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": "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 Overheat Thr",
            "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": "getRelayStateChangeReason",
            "name": "Get Chg Reason",
            "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": "getRelayTimerMilliseconds",
            "name": "Get Timer ms",
            "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": "getRelayTimerSeconds",
            "name": "Get Timer s",
            "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": "getAfterOverheatingRecovery",
            "name": "Get AfterOvht",
            "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 Relay Rcv",
            "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 Ovht Events",
            "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 Ovht Runtime",
            "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": "getLoRaWANRegion",
            "name": "Get Region",
            "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": "getD2dRadioSettings",
            "name": "Get D2D Radio",
            "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"
                }
            ]
        }
    ]
}

```


---

# 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-dry-switch-16ads/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.
