Plugin file
Plugin configuration file
{
"name": "milesight-iot-vs341",
"version": "1.0.0",
"description": "VS341 is an occupancy sensor designed to detect whether desks or seats in a workspace are occupied, allowing for better management and optimization of space usage.",
"author": "Thinger.io",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/thinger-io/plugins.git",
"directory": "milesight-iot-vs341"
},
"metadata": {
"name": "Milesight-Iot VS341",
"description": "VS341 is an occupancy sensor designed to detect whether desks or seats in a workspace are occupied, allowing for better management and optimization of space usage.",
"image": "assets/vs340.png",
"category": "devices",
"vendor": "milesight-iot"
},
"resources": {
"products": [
{
"config": {
"icons": []
},
"description": "VS341 is an occupancy sensor designed to detect whether desks or seats in a workspace are occupied, allowing for better management and optimization of space usage.",
"enabled": true,
"name": "Milesight-Iot VS341",
"product": "milesight_iot_vs341",
"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": "vs341_.*"
},
"enabled": true
}
},
"buckets": {
"milesight_vs341_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 for The Things Network\n *\n * Copyright 2023 Milesight IoT\n *\n * @product VS340 / VS341\n */\nfunction Decoder(bytes, port) {\n return milesight(bytes);\n}\n\nfunction milesight(bytes) {\n var decoded = {};\n\n for (var i = 0; i < bytes.length; ) {\n var channel_id = bytes[i++];\n var channel_type = bytes[i++];\n // BATTERY\n if (channel_id === 0x01 && channel_type === 0x75) {\n decoded.battery = bytes[i];\n i += 1;\n }\n // OCCUPANCY\n else if (channel_id === 0x03 && channel_type === 0x00) {\n decoded.occupancy = bytes[i] === 0 ? \"vacant\" : \"occupied\";\n i += 1;\n } else {\n break;\n }\n }\n\n return decoded;\n}\n",
"environment": "javascript",
"storage": "",
"version": "1.0"
},
"flows": {
"milesight_vs341_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": "Occupancy 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": "60px",
"textWeight": "font-light",
"unit": "",
"unitSize": "20px"
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "milesight_vs341_data",
"mapping": "occupancy",
"tags": {
"device": [],
"group": []
}
},
"color": "#1abc9c",
"name": "Occupancy",
"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": "Status Indicator"
},
"properties": {
"color": "#2ecc71",
"colors": [
{
"blink": false,
"color": "#2ecc71",
"max": 0,
"min": 0
},
{
"blink": true,
"color": "#e74c3c",
"max": 1,
"min": 1
}
],
"size": "120px"
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "milesight_vs341_data",
"mapping": "occupancy",
"tags": {
"device": [],
"group": []
}
},
"color": "#1abc9c",
"name": "Status",
"processing": {
"input": "occupancyToCode"
},
"source": "bucket",
"timespan": {
"mode": "latest"
}
}
],
"type": "led"
},
{
"layout": {
"col": 0,
"row": 5,
"sizeX": 2,
"sizeY": 7
},
"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_vs341_data",
"mapping": "battery",
"tags": {
"device": [],
"group": []
}
},
"color": "#2ebd59",
"name": "Battery",
"source": "bucket",
"timespan": {
"mode": "latest"
}
}
],
"type": "gauge"
},
{
"layout": {
"col": 4,
"row": 0,
"sizeX": 2,
"sizeY": 12
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Occupancy History (24h)"
},
"properties": {
"alignTimeSeries": false,
"dataAppend": false,
"options": "var options = {\n chart: {\n type: 'area',\n stacked: false\n },\n dataLabels: {\n enabled: false\n },\n stroke: {\n curve: 'stepline'\n },\n xaxis: {\n type: 'datetime',\n labels: {\n datetimeUTC: false\n },\n tooltip: {\n enabled: false\n }\n },\n yaxis: {\n labels: {\n formatter: function (val) {\n if (val !== null && typeof val !== 'undefined')\n return val === 1 ? 'Occupied' : 'Vacant';\n }\n },\n min: 0,\n max: 1\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_vs341_data",
"mapping": "occupancy",
"tags": {
"device": [],
"group": []
}
},
"color": "#3498db",
"name": "Occupancy",
"processing": {
"input": "occupancyToCode"
},
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
}
],
"type": "apex_charts"
},
{
"layout": {
"col": 2,
"row": 5,
"sizeX": 2,
"sizeY": 7
},
"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 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_vs341_data",
"mapping": "battery",
"tags": {
"device": [],
"group": []
}
},
"color": "#2ebd59",
"name": "Battery",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
}
],
"type": "apex_charts"
},
{
"layout": {
"col": 0,
"row": 12,
"sizeX": 6,
"sizeY": 7
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Recent Events (7 days)"
},
"properties": {
"source": "code",
"template": "<div style=\"width:100%; height:100%; overflow-y:auto\">\n <table class=\"table table-striped table-condensed\">\n <thead>\n <tr>\n <th>Date</th>\n <th>Battery (%)</th>\n <th>Occupancy</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"entry in value\">\n <td>{{ entry.ts | date:'medium' }}</td>\n <td>{{ entry.battery || '—' }}</td>\n <td>{{ entry.occupancy || '—' }}</td>\n </tr>\n </tbody>\n </table>\n</div>"
},
"sources": [
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "milesight_vs341_data",
"mapping": "ts",
"tags": {
"device": [],
"group": []
}
},
"color": "#1abc9c",
"name": "ts",
"source": "bucket",
"timespan": {
"magnitude": "day",
"mode": "relative",
"period": "latest",
"value": 7
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "milesight_vs341_data",
"mapping": "battery",
"tags": {
"device": [],
"group": []
}
},
"color": "#2ecc71",
"name": "battery",
"source": "bucket",
"timespan": {
"magnitude": "day",
"mode": "relative",
"period": "latest",
"value": 7
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "milesight_vs341_data",
"mapping": "occupancy",
"tags": {
"device": [],
"group": []
}
},
"color": "#3498db",
"name": "occupancy",
"source": "bucket",
"timespan": {
"magnitude": "day",
"mode": "relative",
"period": "latest",
"value": 7
}
}
],
"type": "html_time"
}
]
}
]
}
}
]
}
}
]
}
}