Skip to content

Plugin file

Plugin configuration file
{
  "name": "milesight_iot_wt401",
  "version": "1.0.0",
  "description": "WT401 is a wireless thermostat defined by its split-unit design, delivering unparalleled installation flexibility. Its broad compatibility empowers you to bring intelligent, unified control to a diverse spectrum of HVAC systems",
  "author": "Thinger.io",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/thinger-io/plugins.git",
    "directory": "milesight-iot-wt401"
  },
  "metadata": {
    "name": "Milesight-Iot WT401",
    "description": "WT401 is a wireless thermostat defined by its split-unit design, delivering unparalleled installation flexibility. Its broad compatibility empowers you to bring intelligent, unified control to a diverse spectrum of HVAC systems",
    "image": "assets/wt401.png",
    "category": "devices",
    "vendor": "milesight-iot"
  },
  "resources": {
    "products": [
      {
        "description": "WT401 is a wireless thermostat defined by its split-unit design, delivering unparalleled installation flexibility. Its broad compatibility empowers you to bring intelligent, unified control to a diverse spectrum of HVAC systems",
        "enabled": true,
        "name": "Milesight-Iot WT401",
        "product": "milesight_iot_wt401",
        "profile": {
          "api": {
            "downlink": {
              "enabled": true,
              "handle_connectivity": false,
              "request": {
                "data": {
                  "path": "/downlink",
                  "payload": "{\r\n    \"data\"    : \"{{payload.data=\"\"}}\",\r\n    \"port\"    :  {{payload.port=2}},\r\n    \"priority\":  {{payload.priority=3}},\r\n    \"confirmed\" :  {{payload.confirmed=false}},\r\n    \"uplink\"  :  {{property.uplink}} \r\n}",
                  "payload_function": "",
                  "payload_type": "",
                  "plugin": "{{property.uplink.source}}",
                  "target": "plugin_endpoint"
                }
              }
            },
            "uplink": {
              "enabled": true,
              "handle_connectivity": true,
              "request": {
                "data": {
                  "payload": "{{payload}}",
                  "payload_function": "",
                  "payload_type": "source_payload",
                  "resource_stream": "uplink",
                  "target": "resource_stream"
                }
              }
            }
          },
          "autoprovisions": {
            "device_autoprovisioning": {
              "config": {
                "mode": "pattern",
                "pattern": "wt401_.*"
              },
              "enabled": true
            }
          },
          "buckets": {
            "milesight_wt401_data": {
              "backend": "mongodb",
              "data": {
                "payload": "{{payload}}",
                "payload_function": "",
                "payload_type": "source_payload",
                "resource_stream": "uplink_decoded",
                "source": "resource_stream"
              },
              "enabled": true,
              "retention": {
                "period": 3,
                "unit": "months"
              },
              "tags": []
            }
          },
          "code": {
            "code": "function decodeThingerUplink(thingerData) {\n    // 0. If data has already been decoded, we will return it\n    if (thingerData.decodedPayload) return thingerData.decodedPayload;\n    \n    // 1. Extract and Validate Input\n    // We need 'payload' (hex string) and 'fPort' (integer)\n    const hexPayload = thingerData.payload || \"\";\n    const port = thingerData.fPort || 1;\n\n    // 2. Convert Hex String to Byte Array\n    const bytes = [];\n    for (let i = 0; i < hexPayload.length; i += 2) {\n        bytes.push(parseInt(hexPayload.substr(i, 2), 16));\n    }\n\n    // 3. Dynamic Function Detection and Execution\n    \n    // CASE A: (The Things Stack v3)\n    if (typeof decodeUplink === 'function') {\n        try {\n            const input = {\n                bytes: bytes,\n                fPort: port\n            };\n            var result = decodeUplink(input);\n            \n            if (result.data) return result.data;\n\n            return result; \n        } catch (e) {\n            console.error(\"Error inside decodeUplink:\", e);\n            throw e;\n        }\n    }\n\n    // CASE B: Legacy TTN (v2)\n    else if (typeof Decoder === 'function') {\n        try {\n            return Decoder(bytes, port);\n        } catch (e) {\n            console.error(\"Error inside Decoder:\", e);\n            throw e;\n        }\n    }\n\n    // CASE C: No decoder found\n    else {\n        throw new Error(\"No compatible TTN decoder function (decodeUplink or Decoder) found in scope.\");\n    }\n}\n\n\n// TTN decoder\nfunction decodeUplink(input) {\n    var res = Decoder(input.bytes, input.fPort);\n    if (res.error) {\n        return {\n            errors: [res.error],\n        };\n    }\n    return {\n        data: res,\n    };\n}\n/**\n * Payload Decoder\n *\n * Copyright 2025 Milesight IoT\n *\n * @product WT401\n */\nvar RAW_VALUE = 0x00;\n\n/* eslint no-redeclare: \"off\" */\n/* eslint-disable */\n\n// The Things Network\nfunction Decoder(bytes, port) {\n    return milesightDeviceDecode(bytes);\n}\n/* eslint-enable */\n\nfunction milesightDeviceDecode(bytes) {\n    var decoded = {};\n\n    var unknown_command = 0;\n    for (var i = 0; i < bytes.length; ) {\n        var command_id = bytes[i++];\n\n        switch (command_id) {\n            // attribute\n            case 0xdf:\n                decoded.tsl_version = readProtocolVersion(bytes.slice(i, i + 2));\n                i += 2;\n                break;\n            case 0xde: // ?\n                decoded.product_name = readString(bytes.slice(i, i + 32));\n                i += 32;\n                break;\n            case 0xdd: // ?\n                decoded.product_pn = readString(bytes.slice(i, i + 32));\n                i += 32;\n                break;\n            case 0xdb:\n                decoded.product_sn = readHexString(bytes.slice(i, i + 8));\n                i += 8;\n                break;\n            case 0xda:\n                decoded.version = {};\n                decoded.version.hardware_version = readHardwareVersion(bytes.slice(i, i + 2));\n                decoded.version.firmware_version = readFirmwareVersion(bytes.slice(i + 2, i + 8));\n                i += 8;\n                break;\n            case 0xd9:\n                decoded.oem_id = readHexString(bytes.slice(i, i + 2));\n                i += 2;\n                break;\n            case 0xd8:\n                decoded.product_frequency_band = readString(bytes.slice(i, i + 16));\n                i += 16;\n                break;\n            case 0xee:\n                decoded.device_request = 1;\n                i += 0;\n                break;\n            case 0xc8:\n                decoded.device_status = readDeviceStatus(bytes[i]);\n                i += 1;\n                break;\n            case 0xcf:\n                // skip 1 byte\n                decoded.lorawan_class = readLoRaWANClass(bytes[i + 1]);\n                i += 2;\n                break;\n\n            // telemetry\n            case 0x00:\n                decoded.battery = readUInt8(bytes[i]);\n                i += 1;\n                break;\n            case 0x01:\n                decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 100;\n                i += 2;\n                break;\n            case 0x02:\n                decoded.humidity = readUInt16LE(bytes.slice(i, i + 2)) / 10;\n                i += 2;\n                break;\n            case 0x03:\n                decoded.temperature_control_mode = readTemperatureControlMode(bytes[i]);\n                i += 1;\n                break;\n            case 0x04:\n                decoded.fan_mode = readFanMode(bytes[i]);\n                i += 1;\n                break;\n            case 0x05:\n                decoded.execution_plan = readPlan(readUInt8(bytes[i]));\n                i += 1;\n                break;\n            case 0x06:\n                decoded.target_temperature_1 = readInt16LE(bytes.slice(i, i + 2)) / 100;\n                i += 2;\n                break;\n            case 0x07:\n                decoded.target_temperature_2 = readInt16LE(bytes.slice(i, i + 2)) / 100;\n                i += 2;\n                break;\n            case 0x08:\n                decoded.pir_status = readPIRStatus(bytes[i]);\n                i += 1;\n                break;\n            case 0x09:\n                decoded.ble_event = readBleEvent(bytes[i]);\n                i += 1;\n                break;\n            case 0x0a:\n                decoded.power_bus_event = readPowerBusEvent(bytes[i]);\n                i += 1;\n                break;\n            case 0x0b:\n                decoded.temperature_alarm = readTemperatureAlarm(bytes[i]);\n                i += 1;\n                break;\n            case 0x0c:\n                decoded.humidity_alarm = readHumidityAlarm(bytes[i]);\n                i += 1;\n                break;\n            case 0x0d:\n                decoded.button_event = readButtonEvent(bytes[i]);\n                i += 1;\n                break;\n            case 0x0f:\n                decoded.battery_event = readBatteryEvent(bytes[i]);\n                i += 1;\n                break;\n\n            // config\n            case 0x56:\n                decoded.peer_ble_pair_info = {};\n                decoded.peer_ble_pair_info.address_type = readAddressType(bytes[i]);\n                decoded.peer_ble_pair_info.address = readHexString(bytes.slice(i + 1, i + 1 + 6));\n                decoded.peer_ble_pair_info.name = readString(bytes.slice(i + 7, i + 7 + 32));\n                i += 40;\n                break;\n            case 0x60:\n                var time_unit = readUInt8(bytes[i]);\n                decoded.collection_interval = {};\n                decoded.collection_interval.unit = readTimeUnitType(time_unit);\n                if (time_unit === 0) {\n                    decoded.collection_interval.seconds_of_time = readUInt16LE(bytes.slice(i + 1, i + 3));\n                } else if (time_unit === 1) {\n                    decoded.collection_interval.minutes_of_time = readUInt16LE(bytes.slice(i + 1, i + 3));\n                }\n                i += 3;\n                break;\n            case 0x61:\n                decoded.reporting_interval = {};\n                decoded.reporting_interval.mode = readReportingMode(bytes[i]);\n                decoded.reporting_interval.unit = readTimeUnitType(bytes[i + 1]);\n                var time_unit = readUInt8(bytes[i + 1]);\n                if (time_unit === 0) {\n                    decoded.reporting_interval.seconds_of_time = readUInt16LE(bytes.slice(i + 2, i + 4));\n                } else if (time_unit === 1) {\n                    decoded.reporting_interval.minutes_of_time = readUInt16LE(bytes.slice(i + 2, i + 4));\n                }\n                i += 4;\n                break;\n            case 0x62:\n                decoded.intelligent_display_enable = readEnableStatus(bytes[i]);\n                i += 1;\n                break;\n            case 0x63:\n                decoded.temperature_unit = readTemperatureUnit(bytes[i]);\n                i += 1;\n                break;\n            case 0x64:\n                var data = readUInt8(bytes[i]);\n                decoded.temperature_control_mode_support = {};\n                var mode_bit_offset = { heat: 0, em_heat: 1, cool: 2, auto: 3 };\n                for (var mode in mode_bit_offset) {\n                    decoded.temperature_control_mode_support[mode] = readEnableStatus((data >> mode_bit_offset[mode]) & 0x01);\n                }\n                i += 1;\n                break;\n            case 0x65:\n                decoded.target_temperature_mode = readTargetTemperatureMode(bytes[i]);\n                i += 1;\n                break;\n            case 0x66:\n                decoded.target_temperature_resolution = readTargetTemperatureResolution(bytes[i]);\n                i += 1;\n                break;\n            case 0x67:\n                decoded.system_status = readSystemStatus(bytes[i]);\n                i += 1;\n                break;\n            case 0x68:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.temperature_control_mode = readTemperatureControlMode(bytes[i + 1]);\n                } else if (data === 0x01) {\n                    decoded.temperature_control_mode_in_plan_enable = readEnableStatus(bytes[i + 1]);\n                }\n                i += 2;\n                break;\n            case 0x69:\n                var data = readUInt8(bytes[i]);\n                var temperature = readInt16LE(bytes.slice(i + 1, i + 3)) / 100;\n                // heat\n                if (data === 0x00) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.heat = temperature;\n                }\n                // em heat\n                else if (data === 0x01) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.em_heat = temperature;\n                }\n                // cool\n                else if (data === 0x02) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.cool = temperature;\n                }\n                // auto\n                else if (data === 0x03) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.auto = temperature;\n                }\n                // dual (auto heat)\n                else if (data === 0x04) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.auto_heat = temperature;\n                }\n                // dual (auto cool)\n                else if (data === 0x05) {\n                    decoded.target_temperature_settings = decoded.target_temperature_settings || {};\n                    decoded.target_temperature_settings.auto_cool = temperature;\n                }\n                i += 3;\n                break;\n            case 0x6a:\n                decoded.dead_band = readInt16LE(bytes.slice(i, i + 2)) / 100;\n                i += 2;\n                break;\n            case 0x6b:\n                var data = readUInt8(bytes[i]);\n                var range = {};\n                range.min = readInt16LE(bytes.slice(i + 1, i + 3)) / 100;\n                range.max = readInt16LE(bytes.slice(i + 3, i + 5)) / 100;\n                i += 5;\n                if (data === 0x00) {\n                    decoded.target_temperature_range = decoded.target_temperature_range || {};\n                    decoded.target_temperature_range.heat = range;\n                } else if (data === 0x01) {\n                    decoded.target_temperature_range = decoded.target_temperature_range || {};\n                    decoded.target_temperature_range.em_heat = range;\n                } else if (data === 0x02) {\n                    decoded.target_temperature_range = decoded.target_temperature_range || {};\n                    decoded.target_temperature_range.cool = range;\n                } else if (data === 0x03) {\n                    decoded.target_temperature_range = decoded.target_temperature_range || {};\n                    decoded.target_temperature_range.auto = range;\n                }\n                break;\n            case 0x6c:\n                decoded.communicate_interval = {};\n                decoded.communicate_interval.mode = readReportingMode(bytes[i]);\n                decoded.communicate_interval.unit = readTimeUnitType(bytes[i + 1]);\n                var time_unit = readUInt8(bytes[i + 1]);\n                if (time_unit === 0) {\n                    decoded.communicate_interval.seconds_of_time = readUInt16LE(bytes.slice(i + 2, i + 4));\n                } else if (time_unit === 1) {\n                    decoded.communicate_interval.minutes_of_time = readUInt16LE(bytes.slice(i + 2, i + 4));\n                }\n                i += 4;\n                break;\n            case 0x71:\n                var data = readUInt8(bytes[i]);\n                decoded.button_custom_function = decoded.button_custom_function || {};\n                if (data === 0x00) {\n                    decoded.button_custom_function.enable = readEnableStatus(bytes[i + 1]);\n                }\n                // button 1\n                else if (data === 0x01 || data === 0x02 || data === 0x03) {\n                    var button_name = \"button_\" + data;\n                    decoded.button_custom_function[button_name] = readButtonFunction(bytes[i + 1]);\n                }\n                i += 2;\n                break;\n            case 0x72:\n                var enable = readEnableStatus(bytes[i]);\n                var data = readUInt16LE(bytes.slice(i + 1, i + 3));\n                decoded.child_lock_settings = {};\n                decoded.child_lock_settings.enable = enable;\n                var button_bit_offset = { temperature_up: 0, temperature_down: 1, system_on_off: 2, fan_mode: 3, temperature_control_mode: 4, reboot_reset: 5, power_on_off: 6, cancel_pair: 7, plan_switch: 8, status_report: 9, release_filter_alarm: 10, button_report_1: 11, button_report_2: 12, button_report_3: 13, temperature_unit_switch: 14 };\n                for (var button in button_bit_offset) {\n                    decoded.child_lock_settings[button] = readEnableStatus((data >> button_bit_offset[button]) & 0x01);\n                }\n                i += 3;\n                break;\n            case 0x74:\n                decoded.fan_mode = readFanMode(bytes[i]);\n                i += 1;\n                break;\n            case 0x75:\n                decoded.screen_display_settings = decoded.screen_display_settings || {};\n                var screen_object_data = readUInt8(bytes[i]);\n                var screen_object_bit_offset = { plan_name: 0, ambient_temperature: 1, ambient_humidity: 2, target_temperature: 3 };\n                for (var key in screen_object_bit_offset) {\n                    decoded.screen_display_settings[key] = readEnableStatus((screen_object_data >>> screen_object_bit_offset[key]) & 0x01);\n                }\n                i += 1;\n                break;\n            case 0x76:\n                decoded.temperature_calibration_settings = {};\n                decoded.temperature_calibration_settings.enable = readEnableStatus(bytes[i]);\n                decoded.temperature_calibration_settings.calibration_value = readInt16LE(bytes.slice(i + 1, i + 3)) / 100;\n                i += 3;\n                break;\n            case 0x77:\n                decoded.humidity_calibration_settings = {};\n                decoded.humidity_calibration_settings.enable = readEnableStatus(bytes[i]);\n                decoded.humidity_calibration_settings.calibration_value = readInt16LE(bytes.slice(i + 1, i + 3)) / 10;\n                i += 3;\n                break;\n            case 0x7b:\n                var plan_config = {};\n                plan_config.plan_id = readUInt8(bytes[i]) + 1;\n                var data = readUInt8(bytes[i + 1]);\n                if (data === 0x00) {\n                    plan_config.enable = readEnableStatus(bytes[i + 2]);\n                    i += 3;\n                } else if (data === 0x01) {\n                    plan_config.name_first = readString(bytes.slice(i + 2, i + 8));\n                    i += 8;\n                } else if (data === 0x02) {\n                    plan_config.name_last = readString(bytes.slice(i + 2, i + 6));\n                    i += 6;\n                } else if (data === 0x03) {\n                    plan_config.temperature_control_mode = readTemperatureControlMode(bytes[i + 2]);\n                    plan_config.heat_target_temperature = readInt16LE(bytes.slice(i + 3, i + 5)) / 100;\n                    plan_config.em_heat_target_temperature = readInt16LE(bytes.slice(i + 5, i + 7)) / 100;\n                    plan_config.cool_target_temperature = readInt16LE(bytes.slice(i + 7, i + 9)) / 100;\n                    i += 9;\n                } else if (data === 0x04) {\n                    plan_config.fan_mode = readFanMode(bytes[i + 2]);\n                    plan_config.auto_target_temperature = readInt16LE(bytes.slice(i + 3, i + 5)) / 100;\n                    plan_config.auto_heat_target_temperature = readInt16LE(bytes.slice(i + 5, i + 7)) / 100;\n                    plan_config.auto_cool_target_temperature = readInt16LE(bytes.slice(i + 7, i + 9)) / 100;\n                    i += 9;\n                }\n                decoded.plan_config = decoded.plan_config || [];\n                decoded.plan_config.push(plan_config);\n                break;\n            case 0x7d:\n                decoded.data_sync_to_peer = readDataSource(bytes[i]);\n                i += 1;\n                break;\n            case 0x7e:\n                decoded.data_sync_timeout = readUInt8(bytes[i]);\n                i += 1;\n                break;\n            case 0x80:\n                var data = readUInt8(bytes[i]);\n                decoded.unlock_combination_button_settings = {};\n                var button_bit_offset = { button_1: 0, button_2: 1, button_3: 2, button_4: 3, button_5: 4 };\n                for (var button in button_bit_offset) {\n                    decoded.unlock_combination_button_settings[button] = readEnableStatus((data >> button_bit_offset[button]) & 0x01);\n                }\n                i += 1;\n                break;\n            case 0x81:\n                decoded.temporary_unlock_settings = decoded.temporary_unlock_settings || {};\n                decoded.temporary_unlock_settings.enable = readEnableStatus(bytes[i]);\n                decoded.temporary_unlock_settings.timeout = readUInt16LE(bytes.slice(i + 1, i + 3));\n                i += 3;\n                break;\n            case 0x82:\n                var data = readUInt8(bytes[i]);\n                decoded.pir_config = decoded.pir_config || {};\n                if (data === 0x01) {\n                    decoded.pir_config.enable = readEnableStatus(bytes[i + 1]);\n                    i += 2;\n                } else if (data === 0x02) {\n                    decoded.pir_config.release_time = readUInt16LE(bytes.slice(i + 1, i + 3));\n                    i += 3;\n                } else if (data === 0x03) {\n                    decoded.pir_config.general_mode = decoded.pir_config.general_mode || {};\n                    decoded.pir_config.general_mode.detection_mode = readPIRDetectionMode(bytes[i + 1]);\n                    i += 2;\n                } else if (data === 0x04) {\n                    decoded.pir_config.general_mode = decoded.pir_config.general_mode || {};\n                    decoded.pir_config.general_mode.period = readUInt8(bytes[i + 1]);\n                    decoded.pir_config.general_mode.rate = readUInt8(bytes[i + 2]);\n                    i += 3;\n                }\n                break;\n            case 0x83:\n                var data = readUInt8(bytes[i]);\n                decoded.pir_config = decoded.pir_config || {};\n                if (data === 0x01) {\n                    decoded.pir_config.eco_mode = decoded.pir_config.eco_mode || {};\n                    decoded.pir_config.eco_mode.enable = readEnableStatus(bytes[i + 1]);\n                    i += 2;\n                } else if (data === 0x02) {\n                    decoded.pir_config.eco_mode = decoded.pir_config.eco_mode || {};\n                    decoded.pir_config.eco_mode.occupied_plan = readPlan(readUInt8(bytes[i + 1]));\n                    decoded.pir_config.eco_mode.vacant_plan = readPlan(readUInt8(bytes[i + 2]));\n                    i += 3;\n                }\n                break;\n            case 0x84:\n                var data = readUInt8(bytes[i]);\n                decoded.pir_config = decoded.pir_config || {};\n                if (data === 0x01) {\n                    decoded.pir_config.night_mode = decoded.pir_config.night_mode || {};\n                    decoded.pir_config.night_mode.enable = readEnableStatus(bytes[i + 1]);\n                    i += 2;\n                } else if (data === 0x02) {\n                    decoded.pir_config.night_mode = decoded.pir_config.night_mode || {};\n                    decoded.pir_config.night_mode.detection_mode = readPIRDetectionMode(bytes[i + 1]);\n                    i += 2;\n                } else if (data === 0x03) {\n                    decoded.pir_config.night_mode = decoded.pir_config.night_mode || {};\n                    decoded.pir_config.night_mode.period = readUInt8(bytes[i + 1]);\n                    decoded.pir_config.night_mode.rate = readUInt8(bytes[i + 2]);\n                    i += 3;\n                } else if (data === 0x04) {\n                    decoded.pir_config.night_mode = decoded.pir_config.night_mode || {};\n                    decoded.pir_config.night_mode.start_time = readUInt16LE(bytes.slice(i + 1, i + 3));\n                    decoded.pir_config.night_mode.end_time = readUInt16LE(bytes.slice(i + 3, i + 5));\n                    i += 5;\n                } else if (data === 0x05) {\n                    decoded.pir_config.night_mode = decoded.pir_config.night_mode || {};\n                    decoded.pir_config.night_mode.occupied_plan = readPlan(readUInt8(bytes[i + 1]));\n                    i += 2;\n                }\n                break;\n            case 0x85:\n                decoded.ble_enable = readEnableStatus(bytes[i]);\n                i += 1;\n                break;\n            case 0x86:\n                decoded.external_temperature = readInt16LE(bytes.slice(i, i + 2)) / 100;\n                i += 2;\n                break;\n            case 0x87:\n                decoded.external_humidity = readInt16LE(bytes.slice(i, i + 2)) / 10;\n                i += 2;\n                break;\n            case 0x88:\n                var data = readUInt8(bytes[i]);\n                decoded.fan_support_mode = {};\n                var mode_bit_offset = { auto: 0, circulate: 1, on: 2, low: 3, medium: 4, high: 5 };\n                for (var mode in mode_bit_offset) {\n                    decoded.fan_support_mode[mode] = readEnableStatus((data >> mode_bit_offset[mode]) & 0x01);\n                }\n                i += 1;\n                break;\n            case 0x8b:\n                decoded.ble_name = readString(bytes.slice(i, i + 32));\n                i += 32;\n                break;\n            case 0x8c:\n                decoded.ble_pair_info = {};\n                decoded.ble_pair_info.address_type = readAddressType(bytes[i]);\n                decoded.ble_pair_info.address = readHexString(bytes.slice(i + 1, i + 1 + 6));\n                decoded.ble_pair_info.name = readString(bytes.slice(i + 7, i + 7 + 32));\n                i += 40;\n                break;\n            case 0x8d:\n                decoded.communication_mode = readCommunicationMode(bytes[i]);\n                i += 1;\n                break;\n            case 0xc6:\n                decoded.daylight_saving_time = {};\n                decoded.daylight_saving_time.enable = readEnableStatus(bytes[i]);\n                decoded.daylight_saving_time.offset = readUInt8(bytes[i + 1]);\n                decoded.daylight_saving_time.start_month = readUInt8(bytes[i + 2]);\n                var start_day_value = readUInt8(bytes[i + 3]);\n                decoded.daylight_saving_time.start_week_num = (start_day_value >>> 4) & 0x0f;\n                decoded.daylight_saving_time.start_week_day = (start_day_value >>> 0) & 0x0f;\n                decoded.daylight_saving_time.start_hour_min = readUInt16LE(bytes.slice(i + 4, i + 6));\n                decoded.daylight_saving_time.end_month = readUInt8(bytes[i + 6]);\n                var end_day_value = readUInt8(bytes[i + 7]);\n                decoded.daylight_saving_time.end_week_num = (end_day_value >>> 4) & 0x0f;\n                decoded.daylight_saving_time.end_week_day = (end_day_value >>> 0) & 0x0f;\n                decoded.daylight_saving_time.end_hour_min = readUInt16LE(bytes.slice(i + 8, i + 10));\n                i += 10;\n                break;\n            case 0xc7:\n                decoded.time_zone = readTimeZone(readInt16LE(bytes.slice(i, i + 2)));\n                i += 2;\n                break;\n\n            // service\n            case 0x54:\n                decoded.reset_ble_name = readYesNoStatus(1);\n                break;\n            case 0x55:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.release_fan_alarm = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_fan_alarm = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x57:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.release_freeze_alarm = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_freeze_alarm = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x58:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.release_no_wire_alarm = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_no_wire_alarm = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x5a:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.release_window_open_alarm = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_window_open_alarm = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x5b:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.release_filter_alarm = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_filter_alarm = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x5c:\n                decoded.insert_plan = readPlan(readUInt8(bytes[i]));\n                i += 1;\n                break;\n            case 0x5e:\n                var data = readUInt8(bytes[i]);\n                if (data === 0x00) {\n                    decoded.cancel_ble_pair = readYesNoStatus(1);\n                } else if (data === 0x01) {\n                    decoded.trigger_ble_pair = readYesNoStatus(1);\n                }\n                i += 1;\n                break;\n            case 0x5f:\n                decoded.remove_plan = decoded.remove_plan || {};\n                var plan_data = readUInt8(bytes[i]);\n                var plan_offset = { 0: \"plan_1\", 1: \"plan_2\", 2: \"plan_3\", 3: \"plan_4\", 4: \"plan_5\", 5: \"plan_6\", 6: \"plan_7\", 7: \"plan_8\", 8: \"plan_9\", 9: \"plan_10\", 10: \"plan_11\", 11: \"plan_12\", 12: \"plan_13\", 13: \"plan_14\", 14: \"plan_15\", 15: \"plan_16\", 255: \"reset\" };\n                decoded.remove_plan[plan_offset[plan_data]] = readYesNoStatus(1);\n                i += 1;\n                break;\n            case 0xb6:\n                decoded.reconnect = readYesNoStatus(1);\n                break;\n            case 0xb8:\n                decoded.synchronize_time = readYesNoStatus(1);\n                break;\n            case 0xb9:\n                decoded.query_device_status = readYesNoStatus(1);\n                break;\n            case 0xbe:\n                decoded.reboot = readYesNoStatus(1);\n                break;\n            case 0x59:\n                decoded.system_status_control = decoded.system_status_control || {};\n                // 0:system close, 1:system open\n                decoded.system_status_control.on_off = readUInt8(bytes[i]);\n                // 0:heat, 1:em heat, 2:cool, 3:auto\n                decoded.system_status_control.mode = readUInt8(bytes.slice(i + 1, i + 2));\n                decoded.system_status_control.temperature1 = readInt16LE(bytes.slice(i + 2, i + 4)) / 100;\n                decoded.system_status_control.temperature2 = readInt16LE(bytes.slice(i + 4, i + 6)) / 100;\n                i += 6;\n                break;\n\n            // control frame\n            case 0xef:\n                var cmd_data = readUInt8(bytes[i]);\n                var cmd_result = (cmd_data >>> 4) & 0x0f;\n                var cmd_length = cmd_data & 0x0f;\n                var cmd_id = readHexString(bytes.slice(i + 1, i + 1 + cmd_length));\n                var cmd_header = readHexString(bytes.slice(i + 1, i + 2));\n                i += 1 + cmd_length;\n\n                var response = {};\n                response.result = readCmdResult(cmd_result);\n                response.cmd_id = cmd_id;\n                response.cmd_name = readCmdName(cmd_header);\n\n                decoded.request_result = decoded.request_result || [];\n                decoded.request_result.push(response);\n                break;\n            case 0xfe:\n                decoded.frame = readUInt8(bytes[i]);\n                i += 1;\n                break;\n            default:\n                unknown_command = 1;\n                break;\n        }\n\n        if (unknown_command) {\n            throw new Error(\"unknown command: \" + command_id);\n        }\n    }\n\n    return decoded;\n}\n\nfunction readProtocolVersion(bytes) {\n    var major = (bytes[0] & 0xff).toString(16);\n    var minor = (bytes[1] & 0xff).toString(16);\n    return \"v\" + major + \".\" + minor;\n}\n\nfunction readHardwareVersion(bytes) {\n    var major = (bytes[0] & 0xff).toString(16);\n    var minor = (bytes[1] & 0xff).toString(16);\n    return \"v\" + major + \".\" + minor;\n}\n\nfunction readFirmwareVersion(bytes) {\n    var major = (bytes[0] & 0xff).toString(16);\n    var minor = (bytes[1] & 0xff).toString(16);\n    var release = (bytes[2] & 0xff).toString(16);\n    var alpha = (bytes[3] & 0xff).toString(16);\n    var unit_test = (bytes[4] & 0xff).toString(16);\n    var test = (bytes[5] & 0xff).toString(16);\n\n    var version = \"v\" + major + \".\" + minor;\n    if (release !== \"0\") version += \"-r\" + release;\n    if (alpha !== \"0\") version += \"-a\" + alpha;\n    if (unit_test !== \"0\") version += \"-u\" + unit_test;\n    if (test !== \"0\") version += \"-t\" + test;\n    return version;\n}\n\nfunction readDeviceStatus(type) {\n    var device_status_map = { 0: \"off\", 1: \"on\" };\n    return getValue(device_status_map, type);\n}\n\nfunction readLoRaWANClass(type) {\n    var lorawan_class_map = {\n        0: \"Class A\",\n        1: \"Class B\",\n        2: \"Class C\",\n        3: \"Class CtoB\",\n    };\n    return getValue(lorawan_class_map, type);\n}\n\nfunction readYesNoStatus(type) {\n    var yes_no_map = { 0: \"no\", 1: \"yes\" };\n    return getValue(yes_no_map, type);\n}\n\nfunction readEnableStatus(status) {\n    var status_map = { 0: \"disable\", 1: \"enable\" };\n    return getValue(status_map, status);\n}\n\nfunction readSystemStatus(status) {\n    var status_map = { 0: \"off\", 1: \"on\" };\n    return getValue(status_map, status);\n}\n\nfunction readTemperatureControlMode(mode) {\n    var mode_map = { 0: \"heat\", 1: \"em_heat\", 2: \"cool\", 3: \"auto\", 10: \"off\", 11: \"NA\" };\n    return getValue(mode_map, mode);\n}\n\nfunction readFanMode(mode) {\n    var mode_map = { 0: \"auto\", 1: \"circulate\", 2: \"on\", 3: \"low\", 4: \"medium\", 5: \"high\", 10: \"off\", 11: \"NA\" };\n    return getValue(mode_map, mode);\n}\n\nfunction readPIRStatus(status) {\n    var status_map = { 0: \"vacant\", 1: \"occupied\", 2: \"night_occupied\" };\n    return getValue(status_map, status);\n}\n\nfunction readBleEvent(event) {\n    var event_map = { 0: \"none\", 1: \"peer_cancel\", 2: \"disconnect\" };\n    return getValue(event_map, event);\n}\n\nfunction readPowerBusEvent(event) {\n    var event_map = { 0: \"none\", 1: \"communication_error\" };\n    return getValue(event_map, event);\n}\n\nfunction readTemperatureAlarm(type) {\n    var type_map = { 0: \"collection_error\", 1: \"lower_range_error\", 2: \"over_range_error\", 3: \"no_data\" };\n    return getValue(type_map, type);\n}\n\nfunction readHumidityAlarm(type) {\n    var type_map = { 0: \"collection_error\", 1: \"lower_range_error\", 2: \"over_range_error\", 3: \"no_data\" };\n    return getValue(type_map, type);\n}\n\nfunction readButtonEvent(event) {\n    var event_map = { 0: \"F1\", 1: \"F2\", 2: \"F3\" };\n    return getValue(event_map, event);\n}\n\nfunction readBatteryEvent(event) {\n    var event_map = { 0: \"recover\", 1: \"low_voltage\" };\n    return getValue(event_map, event);\n}\n\nfunction readTimeUnitType(type) {\n    var unit_map = { 0: \"second\", 1: \"minute\" };\n    return getValue(unit_map, type);\n}\n\nfunction readReportingMode(mode) {\n    var mode_map = { 0: \"ble\", 1: \"lora\", 2: \"ble_and_lora\", 3: \"power_bus_and_lora\" };\n    return getValue(mode_map, mode);\n}\n\nfunction readTemperatureUnit(type) {\n    var unit_map = { 0: \"celsius\", 1: \"fahrenheit\" };\n    return getValue(unit_map, type);\n}\n\nfunction readTargetTemperatureMode(type) {\n    var mode_map = { 0: \"single_point\", 1: \"dual_point\" };\n    return getValue(mode_map, type);\n}\n\nfunction readTargetTemperatureResolution(type) {\n    var resolution_map = { 0: \"0.5\", 1: \"1\" };\n    return getValue(resolution_map, type);\n}\n\nfunction readButtonFunction(type) {\n    var function_map = { 0: \"system_status\", 1: \"temperature_control_mode\", 2: \"fan_mode\", 3: \"plan_switch\", 4: \"status_report\", 5: \"release_filter_alarm\", 6: \"button_value\", 7: \"temperature_unit_switch\" };\n    return getValue(function_map, type);\n}\n\nfunction readDataSource(type) {\n    var data_source_map = { 0: \"embedded_data\", 1: \"external_receive\" };\n    return getValue(data_source_map, type);\n}\n\nfunction readTimeZone(time_zone) {\n    var timezone_map = { \"-720\": \"UTC-12\", \"-660\": \"UTC-11\", \"-600\": \"UTC-10\", \"-570\": \"UTC-9:30\", \"-540\": \"UTC-9\", \"-480\": \"UTC-8\", \"-420\": \"UTC-7\", \"-360\": \"UTC-6\", \"-300\": \"UTC-5\", \"-240\": \"UTC-4\", \"-210\": \"UTC-3:30\", \"-180\": \"UTC-3\", \"-120\": \"UTC-2\", \"-60\": \"UTC-1\", 0: \"UTC\", 60: \"UTC+1\", 120: \"UTC+2\", 180: \"UTC+3\", 210: \"UTC+3:30\", 240: \"UTC+4\", 270: \"UTC+4:30\", 300: \"UTC+5\", 330: \"UTC+5:30\", 345: \"UTC+5:45\", 360: \"UTC+6\", 390: \"UTC+6:30\", 420: \"UTC+7\", 480: \"UTC+8\", 540: \"UTC+9\", 570: \"UTC+9:30\", 600: \"UTC+10\", 630: \"UTC+10:30\", 660: \"UTC+11\", 720: \"UTC+12\", 765: \"UTC+12:45\", 780: \"UTC+13\", 840: \"UTC+14\" };\n    return getValue(timezone_map, time_zone);\n}\n\nfunction readAddressType(type) {\n    var address_type_map = { 0: \"public\", 1: \"random\" };\n    return getValue(address_type_map, type);\n}\n\nfunction readCommunicationMode(mode) {\n    var mode_map = { 0: \"ble\", 1: \"lora\", 2: \"ble_and_lora\", 3: \"power_bus_and_lora\" };\n    return getValue(mode_map, mode);\n}\n\nfunction readPIRDetectionMode(mode) {\n    var mode_map = { 0: \"single\", 1: \"multiple\" };\n    return getValue(mode_map, mode);\n}\n\nfunction readPlan(id) {\n    var id_map = { 0: \"plan_1\", 1: \"plan_2\", 2: \"plan_3\", 3: \"plan_4\", 4: \"plan_5\", 5: \"plan_6\", 6: \"plan_7\", 7: \"plan_8\", 8: \"plan_9\", 9: \"plan_10\", 10: \"plan_11\", 11: \"plan_12\", 12: \"plan_13\", 13: \"plan_14\", 14: \"plan_15\", 15: \"plan_16\", 255: \"none\" };\n    return getValue(id_map, id);\n}\n\n//\n//\n//\n//\n//\nfunction readCmdResult(type) {\n    var result_map = { 0: \"success\", 1: \"parsing error\", 2: \"order error\", 3: \"password error\", 4: \"read params error\", 5: \"write params error\", 6: \"read execution error\", 7: \"write execution error\", 8: \"read apply error\", 9: \"write apply error\", 10: \"associative error\" };\n    return getValue(result_map, type);\n}\n\nfunction readCmdName(type) {\n    var name_map = {\n        56: { level: 1, name: \"combine_command\" },\n        60: { level: 1, name: \"collection_interval\" },\n        61: { level: 1, name: \"reporting_interval\" },\n        62: { level: 1, name: \"intelligent_display_enable\" },\n        63: { level: 1, name: \"temperature_unit\" },\n        64: { level: 1, name: \"temperature_control_mode_support\" },\n        65: { level: 1, name: \"target_temperature_mode\" },\n        66: { level: 1, name: \"target_temperature_resolution\" },\n        67: { level: 1, name: \"system_status\" },\n        68: { level: 2, name: \"temperature_control_mode\" },\n        69: { level: 2, name: \"target_temperature_settings\" },\n        \"6a\": { level: 1, name: \"dead_band\" },\n        \"6b\": { level: 2, name: \"target_temperature_range\" },\n        71: { level: 2, name: \"button_custom_function\" },\n        72: { level: 1, name: \"child_lock_settings\" },\n        74: { level: 1, name: \"fan_mode\" },\n        75: { level: 1, name: \"screen_display_settings\" },\n        76: { level: 1, name: \"temperature_calibration_settings\" },\n        77: { level: 1, name: \"humidity_calibration_settings\" },\n        \"7d\": { level: 1, name: \"data_sync_to_peer\" },\n        \"7e\": { level: 1, name: \"data_sync_timeout\" },\n        80: { level: 1, name: \"unlock_combination_button_settings\" },\n        81: { level: 1, name: \"temporary_unlock_settings\" },\n        82: { level: 2, name: \"pir_config\" },\n        85: { level: 1, name: \"ble_enable\" },\n        86: { level: 1, name: \"external_temperature\" },\n        87: { level: 1, name: \"external_humidity\" },\n        88: { level: 1, name: \"fan_support_mode\" },\n        \"8b\": { level: 1, name: \"ble_name\" },\n        \"8c\": { level: 1, name: \"ble_pair_info\" },\n        \"8d\": { level: 1, name: \"communication_mode\" },\n        c6: { level: 1, name: \"daylight_saving_time\" },\n        c7: { level: 1, name: \"time_zone\" },\n    };\n\n    var data = name_map[type];\n    if (data === undefined) return \"unknown\";\n    return data.name;\n}\n\n/* eslint-disable */\nfunction readUInt8(bytes) {\n    return bytes & 0xff;\n}\n\nfunction readInt8(bytes) {\n    var ref = readUInt8(bytes);\n    return ref > 0x7f ? ref - 0x100 : ref;\n}\n\nfunction readUInt16LE(bytes) {\n    var value = (bytes[1] << 8) + bytes[0];\n    return value & 0xffff;\n}\n\nfunction readInt16LE(bytes) {\n    var ref = readUInt16LE(bytes);\n    return ref > 0x7fff ? ref - 0x10000 : ref;\n}\n\nfunction readUInt32LE(bytes) {\n    var value = (bytes[3] << 24) + (bytes[2] << 16) + (bytes[1] << 8) + bytes[0];\n    return (value & 0xffffffff) >>> 0;\n}\n\nfunction readInt32LE(bytes) {\n    var ref = readUInt32LE(bytes);\n    return ref > 0x7fffffff ? ref - 0x100000000 : ref;\n}\n\nfunction readFloat16LE(bytes) {\n    var bits = (bytes[1] << 8) | bytes[0];\n    var sign = bits >>> 15 === 0 ? 1.0 : -1.0;\n    var e = (bits >>> 10) & 0x1f;\n    var m = e === 0 ? (bits & 0x3ff) << 1 : (bits & 0x3ff) | 0x400;\n    var f = sign * m * Math.pow(2, e - 25);\n\n    var n = Number(f.toFixed(2));\n    return n;\n}\n\nfunction readFloatLE(bytes) {\n    var bits = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];\n    var sign = bits >>> 31 === 0 ? 1.0 : -1.0;\n    var e = (bits >>> 23) & 0xff;\n    var m = e === 0 ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;\n    var f = sign * m * Math.pow(2, e - 150);\n    return f;\n}\n\nfunction readString(bytes) {\n    var str = \"\";\n    var i = 0;\n    var byte1, byte2, byte3, byte4;\n    while (i < bytes.length) {\n        byte1 = bytes[i++];\n        if (byte1 <= 0x7f) {\n            str += String.fromCharCode(byte1);\n        } else if (byte1 <= 0xdf) {\n            byte2 = bytes[i++];\n            str += String.fromCharCode(((byte1 & 0x1f) << 6) | (byte2 & 0x3f));\n        } else if (byte1 <= 0xef) {\n            byte2 = bytes[i++];\n            byte3 = bytes[i++];\n            str += String.fromCharCode(((byte1 & 0x0f) << 12) | ((byte2 & 0x3f) << 6) | (byte3 & 0x3f));\n        } else if (byte1 <= 0xf7) {\n            byte2 = bytes[i++];\n            byte3 = bytes[i++];\n            byte4 = bytes[i++];\n            var codepoint = ((byte1 & 0x07) << 18) | ((byte2 & 0x3f) << 12) | ((byte3 & 0x3f) << 6) | (byte4 & 0x3f);\n            codepoint -= 0x10000;\n            str += String.fromCharCode((codepoint >> 10) + 0xd800);\n            str += String.fromCharCode((codepoint & 0x3ff) + 0xdc00);\n        }\n    }\n    return str;\n}\n\nfunction readHexString(bytes) {\n    var temp = [];\n    for (var idx = 0; idx < bytes.length; idx++) {\n        temp.push((\"0\" + (bytes[idx] & 0xff).toString(16)).slice(-2));\n    }\n    return temp.join(\"\");\n}\n\nfunction readHexStringLE(bytes) {\n    var temp = [];\n    for (var idx = bytes.length - 1; idx >= 0; idx--) {\n        temp.push((\"0\" + (bytes[idx] & 0xff).toString(16)).slice(-2));\n    }\n    return temp.join(\"\");\n}\n\nfunction getValue(map, key) {\n    if (RAW_VALUE) return key;\n    var value = map[key];\n    if (!value) value = \"unknown\";\n    return value;\n}",
            "environment": "javascript",
            "storage": "",
            "version": "1.0"
          },
          "flows": {
            "milesight_wt401_decoder": {
              "data": {
                "payload": "{{payload}}",
                "payload_function": "decodeThingerUplink",
                "payload_type": "source_payload",
                "resource": "uplink",
                "source": "resource",
                "update": "events"
              },
              "enabled": true,
              "sink": {
                "payload": "{{payload}}",
                "payload_function": "",
                "payload_type": "source_payload",
                "resource_stream": "uplink_decoded",
                "target": "resource_stream"
              },
              "split_data": false
            }
          },
          "properties": {
            "uplink": {
              "data": {
                "payload": "{{payload}}",
                "payload_function": "",
                "payload_type": "source_payload",
                "resource": "uplink",
                "source": "resource",
                "update": "events"
              },
              "default": {
                "source": "value"
              },
              "enabled": true
            }
          }
        },
        "_resources": {
          "properties": [
            {
              "property": "dashboard",
              "value": {
                "tabs": [
                  {
                    "name": "Overview",
                    "widgets": [
                      {
                        "layout": {
                          "col": 0,
                          "row": 0,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Temperature"
                        },
                        "properties": {
                          "decimalPlaces": 1,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "65px",
                          "textWeight": "font-light",
                          "unit": "°C",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "temperature",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#d1311f",
                            "name": "Temperature",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 2,
                          "row": 0,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Humidity"
                        },
                        "properties": {
                          "decimalPlaces": 1,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "65px",
                          "textWeight": "font-light",
                          "unit": "%",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "humidity",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#329fcd",
                            "name": "Humidity",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 4,
                          "row": 0,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Target Temperature"
                        },
                        "properties": {
                          "decimalPlaces": 1,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "65px",
                          "textWeight": "font-light",
                          "unit": "°C",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "target_temperature_1",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#e67e22",
                            "name": "Target Temp",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 0,
                          "row": 5,
                          "sizeX": 6,
                          "sizeY": 10
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Temperature & Humidity (24h)"
                        },
                        "properties": {
                          "alignTimeSeries": false,
                          "dataAppend": false,
                          "options": "var options = {\n    chart: {\n        type: 'line',\n        stacked: false\n    },\n    dataLabels: {\n        enabled: false\n    },\n    stroke: {\n        curve: 'smooth',\n        width: 2\n    },\n    xaxis: {\n        type: 'datetime',\n        labels: {\n            datetimeUTC: false\n        },\n        tooltip: {\n            enabled: false\n        }\n    },\n    yaxis: [\n        {\n            title: {\n                text: 'Temperature (°C)'\n            },\n            labels: {\n                formatter: function (val) {\n                    if (val !== null && typeof val !== 'undefined')\n                        return val.toFixed(1);\n                }\n            }\n        },\n        {\n            opposite: true,\n            title: {\n                text: 'Humidity (%)'\n            },\n            labels: {\n                formatter: function (val) {\n                    if (val !== null && typeof val !== 'undefined')\n                        return val.toFixed(1);\n                }\n            }\n        }\n    ],\n    tooltip: {\n        x: {\n            format: 'dd/MM/yyyy HH:mm:ss'\n        }\n    }\n};\n",
                          "realTimeUpdate": true
                        },
                        "sources": [
                          {
                            "aggregation": {},
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "temperature",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#d1311f",
                            "name": "Temperature",
                            "source": "bucket",
                            "timespan": {
                              "magnitude": "hour",
                              "mode": "relative",
                              "period": "latest",
                              "value": 24
                            }
                          },
                          {
                            "aggregation": {},
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "humidity",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#329fcd",
                            "name": "Humidity",
                            "source": "bucket",
                            "timespan": {
                              "magnitude": "hour",
                              "mode": "relative",
                              "period": "latest",
                              "value": 24
                            }
                          }
                        ],
                        "type": "apex_charts"
                      },
                      {
                        "layout": {
                          "col": 0,
                          "row": 15,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "System Status"
                        },
                        "properties": {
                          "decimalPlaces": 0,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "40px",
                          "textWeight": "font-bold",
                          "unit": "",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "system_status",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#2ecc71",
                            "name": "System Status",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 2,
                          "row": 15,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Control Mode"
                        },
                        "properties": {
                          "decimalPlaces": 0,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "40px",
                          "textWeight": "font-bold",
                          "unit": "",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "temperature_control_mode",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#9b59b6",
                            "name": "Control Mode",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 4,
                          "row": 15,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Fan Mode"
                        },
                        "properties": {
                          "decimalPlaces": 0,
                          "enableExtraTextColor": false,
                          "enableIconColor": false,
                          "enableIconSize": false,
                          "extraText": "",
                          "extraTextColor": "#1E313E",
                          "extraTextColorConditions": [],
                          "extraTextConditions": [],
                          "extraTextPosition": "above-value",
                          "extraTextSize": "20px",
                          "extraTextWeight": "font-light",
                          "icon": "",
                          "iconColor": "#1E313E",
                          "iconColorConditions": [],
                          "iconConditions": [],
                          "iconGap": "8px",
                          "iconPosition": "before-value",
                          "iconSize": "75px",
                          "iconVerticalOffset": "0px",
                          "link": "",
                          "textAlign": "center",
                          "textColor": "#1E313E",
                          "textColorConditions": [],
                          "textSize": "40px",
                          "textWeight": "font-bold",
                          "unit": "",
                          "unitSize": "20px"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "fan_mode",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#3498db",
                            "name": "Fan Mode",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "text"
                      },
                      {
                        "layout": {
                          "col": 0,
                          "row": 20,
                          "sizeX": 2,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Battery"
                        },
                        "properties": {
                          "color": "#2ebd59",
                          "gradient": false,
                          "max": 100,
                          "min": 0,
                          "unit": "%"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "battery",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#2ebd59",
                            "name": "Battery",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "gauge"
                      },
                      {
                        "layout": {
                          "col": 2,
                          "row": 20,
                          "sizeX": 4,
                          "sizeY": 5
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Battery (24h)"
                        },
                        "properties": {
                          "alignTimeSeries": false,
                          "dataAppend": false,
                          "options": "var options = {\n    chart: {\n        type: 'area'\n    },\n    dataLabels: {\n        enabled: false\n    },\n    stroke: {\n        curve: 'smooth'\n    },\n    xaxis: {\n        type: 'datetime',\n        labels: {\n            datetimeUTC: false\n        },\n        tooltip: {\n            enabled: false\n        }\n    },\n    yaxis: {\n        min: 0,\n        max: 100,\n        labels: {\n            formatter: function (val) {\n                if (val !== null && typeof val !== 'undefined')\n                    return val.toFixed(0);\n            }\n        }\n    },\n    tooltip: {\n        x: {\n            format: 'dd/MM/yyyy HH:mm:ss'\n        }\n    }\n};\n",
                          "realTimeUpdate": true
                        },
                        "sources": [
                          {
                            "aggregation": {},
                            "bucket": {
                              "backend": "mongodb",
                              "id": "milesight_wt401_data",
                              "mapping": "battery",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#2ebd59",
                            "name": "Battery",
                            "source": "bucket",
                            "timespan": {
                              "magnitude": "hour",
                              "mode": "relative",
                              "period": "latest",
                              "value": 24
                            }
                          }
                        ],
                        "type": "apex_charts"
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
}