Skip to content

Plugin file

Plugin configuration file
{
    "name": "arwin-technology-lrs20600",
    "version": "1.0.0",
    "description": "Open Close Sensor",
    "author": "Thinger.io",
    "license": "MIT",
    "repository": {
        "type": "git",
        "url": "https://github.com/thinger-io/plugins.git",
        "directory": "arwin-technology-lrs20600"
    },
    "metadata": {
        "name": "Arwin-Technology LRS20600",
        "description": "Open Close Sensor",
        "image": "assets/lrs20600.png",
        "category": "devices",
        "vendor": "arwin-technology"
    },
    "resources": {
        "products": [
            {
                "description": "Open Close Sensor",
                "enabled": true,
                "name": "Arwin-Technology LRS20600",
                "product": "arwin_technology_lrs20600",
                "profile": {
                    "api": {
                        "downlink": {
                            "enabled": true,
                            "handle_connectivity": false,
                            "request": {
                                "data": {
                                    "path": "/downlink",
                                    "payload": "{\n    \"data\"    : \"{{payload.data=\"\"}}\",\n    \"port\"    :  {{payload.port=85}},\n    \"priority\":  {{payload.priority=3}},\n    \"confirmed\" :  {{payload.confirmed=false}},\n    \"uplink\"  :  {{property.uplink}} \n}",
                                    "payload_function": "",
                                    "payload_type": "",
                                    "plugin": "{{property.uplink.source}}",
                                    "target": "plugin_endpoint"
                                }
                            }
                        },
                        "uplink": {
                            "device_id_resolver": "getId",
                            "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": "lrs20600-.*"
                            },
                            "enabled": true
                        }
                    },
                    "buckets": {
                        "arwin_technology_lrs20600_data": {
                            "backend": "mongodb",
                            "data": {
                                "payload": "{{payload}}",
                                "payload_function": "decodeThingerUplink",
                                "payload_type": "source_payload",
                                "resource": "uplink",
                                "source": "resource",
                                "update": "events"
                            },
                            "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\nvar lrs20600_events = ['heartbeat'];\n\nfunction hex2dec(hex) {\n  var dec = hex&0xFFFF;\n  if (dec & 0x8000)\n    dec = -(0x10000-dec)\n  return dec;\n}\n\nfunction decodeUplink(input) {\n  switch (input.fPort) {\n    case 10: // sensor data\n      switch (input.bytes[0]) {\n        case 4:\n          var evt= \"\";\n          for (let i=0; i<8; i++) {\n            if ((0x01<<i)&input.bytes[1]) \n              if (evt===\"\")\n                evt=lrs20600_events[i];\n              else\n                evt=evt+\",\"+lrs20600_events[i];\n          }\n          return {\n            data: {\n              event: evt,\n              battery: input.bytes[2],\n              inputStatus: input.bytes[3] ? \"close\" : \"open\",\n              eventCount: hex2dec(input.bytes[4]<<8|input.bytes[5]),\n            },\n          };\n        default:\n          return {\n            errors: ['unknown sensor type']\n          };\n      }\n      break;\n    case 8: // version\n      var ver = input.bytes[0]+\".\"+(\"00\"+input.bytes[1]).slice(-2)+\".\"+(\"000\"+(input.bytes[2]<<8|input.bytes[3])).slice(-3);    \n      return {\n        data: {\n          firmwareVersion: ver,\n        }\n      };\n    case 12: // device settings\n      switch (input.bytes[0]) {\n        case 4:\n          return {\n            data: {\n              dataUploadInterval: hex2dec(input.bytes[1]<<8|input.bytes[2]),\n              triggerMode: input.bytes[3],\n              triggerDeafTime: hex2dec(input.bytes[4]<<8|input.bytes[5]),\n            }\n          };\n        default:\n          return {\n            errors: ['unknown sensor type']\n          }\n      }\n      case 13: // threshold settings\n      switch (input.bytes[0]) {\n        case 4:\n          var state = input.bytes[1] ? 'enable': 'disable'\n          return {\n            data: {\n              inputEnabled: state,\n            }\n          }\n        default:\n          return {\n            errors: ['unknown sensor type']\n          }\n      }\n    default:\n      return {\n        errors: ['unknown FPort'],\n      };\n  }\n}\n",
                        "environment": "javascript",
                        "storage": "",
                        "version": "1.0"
                    },
                    "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": {
                                "name": "lrs20600",
                                "placeholders": {
                                    "sources": []
                                },
                                "tabs": [
                                    {
                                        "name": "Main",
                                        "widgets": [
                                            {
                                                "layout": {
                                                    "col": 0,
                                                    "row": 0,
                                                    "sizeX": 2,
                                                    "sizeY": 6
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Contact Status"
                                                },
                                                "properties": {
                                                    "source": "code",
                                                    "template": "<div style=\"width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:48px; font-weight:bold;\">\n  <span ng-if=\"value == 'open'\" style=\"color:#e74c3c;\">🔓 OPEN</span>\n  <span ng-if=\"value == 'close'\" style=\"color:#27ae60;\">🔒 CLOSED</span>\n  <span ng-if=\"!value || (value != 'open' && value != 'close')\" style=\"color:#95a5a6;\">— NO DATA</span>\n</div>"
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "inputStatus",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#1abc9c",
                                                        "name": "Contact Status",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    }
                                                ],
                                                "type": "html_time"
                                            },
                                            {
                                                "layout": {
                                                    "col": 2,
                                                    "row": 0,
                                                    "sizeX": 1,
                                                    "sizeY": 6
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Battery Level"
                                                },
                                                "properties": {
                                                    "color": "#f39c12",
                                                    "max": 255,
                                                    "min": 0,
                                                    "unit": "%"
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "battery",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#f39c12",
                                                        "name": "Battery",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    }
                                                ],
                                                "type": "donutchart"
                                            },
                                            {
                                                "layout": {
                                                    "col": 3,
                                                    "row": 0,
                                                    "sizeX": 1,
                                                    "sizeY": 6
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Event Count"
                                                },
                                                "properties": {
                                                    "source": "code",
                                                    "template": "<div style=\"width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:36px; font-weight:bold; color:#3498db;\">\n  <span>{{ value || 0 }}</span>\n</div>"
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "eventCount",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#3498db",
                                                        "name": "Event Count",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    }
                                                ],
                                                "type": "html_time"
                                            },
                                            {
                                                "layout": {
                                                    "col": 0,
                                                    "row": 6,
                                                    "sizeX": 4,
                                                    "sizeY": 8
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Contact Status History (24h)"
                                                },
                                                "properties": {
                                                    "axis": true,
                                                    "fill": false,
                                                    "legend": true,
                                                    "multiple_axes": false
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "inputStatus",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#3498db",
                                                        "name": "Status",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "hour",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 24
                                                        }
                                                    }
                                                ],
                                                "type": "chart"
                                            },
                                            {
                                                "layout": {
                                                    "col": 4,
                                                    "row": 0,
                                                    "sizeX": 2,
                                                    "sizeY": 8
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Event Log (Last 50)"
                                                },
                                                "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>Timestamp</th>\n        <th>Status</th>\n        <th>Event Count</th>\n        <th>Battery</th>\n      </tr>\n    </thead>\n    <tbody>\n      <tr ng-repeat=\"entry in value | orderBy:'-ts' | limitTo:50\">\n        <td>{{ entry.ts | date:'short' }}</td>\n        <td>\n          <span ng-if=\"entry.inputStatus == 'open'\" style=\"color:#e74c3c; font-weight:bold;\">OPEN</span>\n          <span ng-if=\"entry.inputStatus == 'close'\" style=\"color:#27ae60; font-weight:bold;\">CLOSED</span>\n        </td>\n        <td>{{ entry.eventCount || '—' }}</td>\n        <td>{{ entry.battery || '—' }}</td>\n      </tr>\n    </tbody>\n  </table>\n</div>"
                                                },
                                                "sources": [
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "ts",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#95a5a6",
                                                        "name": "timestamp",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "inputStatus",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#3498db",
                                                        "name": "status",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "eventCount",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#9b59b6",
                                                        "name": "eventCount",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "battery",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#f39c12",
                                                        "name": "battery",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    }
                                                ],
                                                "type": "html_time"
                                            },
                                            {
                                                "layout": {
                                                    "col": 0,
                                                    "row": 14,
                                                    "sizeX": 3,
                                                    "sizeY": 8
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Battery Trend (7 days)"
                                                },
                                                "properties": {
                                                    "axis": true,
                                                    "fill": false,
                                                    "legend": true,
                                                    "multiple_axes": false
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "battery",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#f39c12",
                                                        "name": "Battery",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    }
                                                ],
                                                "type": "chart"
                                            },
                                            {
                                                "layout": {
                                                    "col": 3,
                                                    "row": 14,
                                                    "sizeX": 3,
                                                    "sizeY": 8
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Event Count Trend (7 days)"
                                                },
                                                "properties": {
                                                    "axis": true,
                                                    "fill": false,
                                                    "legend": true,
                                                    "multiple_axes": false
                                                },
                                                "sources": [
                                                    {
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "eventCount",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#9b59b6",
                                                        "name": "Event Count",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "magnitude": "day",
                                                            "mode": "relative",
                                                            "period": "latest",
                                                            "value": 7
                                                        }
                                                    }
                                                ],
                                                "type": "chart"
                                            },
                                            {
                                                "layout": {
                                                    "col": 4,
                                                    "row": 8,
                                                    "sizeX": 2,
                                                    "sizeY": 6
                                                },
                                                "panel": {
                                                    "color": "#ffffff",
                                                    "currentColor": "#ffffff",
                                                    "showOffline": {
                                                        "type": "none"
                                                    },
                                                    "title": "Device Information"
                                                },
                                                "properties": {
                                                    "source": "code",
                                                    "template": "<div style=\"padding:15px; font-size:14px; line-height:1.8;\">\n  <p><strong>Firmware Version:</strong> {{ value.firmwareVersion || 'N/A' }}</p>\n  <p><strong>Upload Interval:</strong> {{ value.dataUploadInterval || 'N/A' }} sec</p>\n  <p><strong>Trigger Mode:</strong> {{ value.triggerMode || 'N/A' }}</p>\n  <p><strong>Trigger Deaf Time:</strong> {{ value.triggerDeafTime || 'N/A' }} sec</p>\n  <p><strong>Input Enabled:</strong> {{ value.inputEnabled || 'N/A' }}</p>\n  <p><strong>Last Event:</strong> {{ value.event || 'N/A' }}</p>\n</div>"
                                                },
                                                "sources": [
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "firmwareVersion",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "firmware",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "dataUploadInterval",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "uploadInterval",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "triggerMode",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "triggerMode",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "triggerDeafTime",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "deafTime",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "inputEnabled",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "inputEnabled",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    },
                                                    {
                                                        "aggregation": {},
                                                        "bucket": {
                                                            "backend": "mongodb",
                                                            "id": "arwin_technology_lrs20600_data",
                                                            "mapping": "event",
                                                            "tags": {
                                                                "device": [],
                                                                "group": []
                                                            }
                                                        },
                                                        "color": "#34495e",
                                                        "name": "event",
                                                        "source": "bucket",
                                                        "timespan": {
                                                            "mode": "latest"
                                                        }
                                                    }
                                                ],
                                                "type": "html_time"
                                            }
                                        ]
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}