Skip to content

Instantly share code, notes, and snippets.

@jtp10181
Created September 29, 2022 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtp10181/ad665deb2e572fd33236db2dc454f439 to your computer and use it in GitHub Desktop.
Save jtp10181/ad665deb2e572fd33236db2dc454f439 to your computer and use it in GitHub Desktop.
[
{
"id": "6dce1bddbac14e48",
"type": "tab",
"label": "Hubitat and Tuya",
"disabled": true,
"info": "",
"env": []
},
{
"id": "7a29e7bd4231297b",
"type": "tuya-smart-device",
"z": "6dce1bddbac14e48",
"deviceName": "Den Ceiling Lights",
"disableAutoStart": false,
"deviceId": "",
"deviceKey": "",
"deviceIp": "",
"retryTimeout": "2000",
"findTimeout": 1000,
"tuyaVersion": "3.1",
"eventMode": "event-both",
"x": 550,
"y": 280,
"wires": [
[
"e79665eed75b26e4",
"3fbb6b833559be32"
],
[
"b1ec47561dbf861c"
]
]
},
{
"id": "ab165609b6dfa6ee",
"type": "catch",
"z": "6dce1bddbac14e48",
"name": "",
"scope": null,
"uncaught": false,
"x": 120,
"y": 60,
"wires": [
[
"ddba5b3efa6b40e4"
]
]
},
{
"id": "ddba5b3efa6b40e4",
"type": "debug",
"z": "6dce1bddbac14e48",
"name": "On Error",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 330,
"y": 60,
"wires": []
},
{
"id": "53ae750d6d3ec5a8",
"type": "function",
"z": "6dce1bddbac14e48",
"name": "Convert to Tuya",
"func": "var dpsVal;\nvar setVal;\n\n//Setup variables\nif (msg.payload.name == \"switch\") {\n dpsVal = 20;\n setVal = (msg.payload.value == \"on\" ? true : false);\n}\n\nif (msg.payload.name == \"level\") {\n \n}\n\n//Build payload\nif (dpsVal) {\n var msgTuya = { payload: [] };\n msgTuya.payload = {\n dps: dpsVal,\n set: setVal\n }\n \n return msgTuya;\n}\n\nreturn false;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 280,
"wires": [
[
"7a29e7bd4231297b"
]
]
},
{
"id": "e79665eed75b26e4",
"type": "debug",
"z": "6dce1bddbac14e48",
"name": "Device Data",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 440,
"wires": []
},
{
"id": "b1ec47561dbf861c",
"type": "debug",
"z": "6dce1bddbac14e48",
"name": "Node State",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 810,
"y": 480,
"wires": []
},
{
"id": "28e1e622c817f829",
"type": "hubitat device",
"z": "6dce1bddbac14e48",
"deviceLabel": "Den Ceiling Lights",
"name": "",
"server": "3b6080dc.a2527",
"deviceId": "1943",
"attribute": "",
"sendEvent": true,
"x": 130,
"y": 280,
"wires": [
[
"53ae750d6d3ec5a8"
]
]
},
{
"id": "dde86694fb24e2ec",
"type": "debug",
"z": "6dce1bddbac14e48",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 410,
"y": 400,
"wires": []
},
{
"id": "7bb2ede9f31f99d1",
"type": "hubitat command",
"z": "6dce1bddbac14e48",
"deviceLabel": "Den Ceiling LED",
"name": "Turn On",
"server": "3b6080dc.a2527",
"deviceId": "1943",
"command": "on",
"commandArgs": "",
"x": 1180,
"y": 120,
"wires": [
[]
]
},
{
"id": "88bbd024b713af57",
"type": "switch",
"z": "6dce1bddbac14e48",
"name": "on/off",
"property": "payload.data.dps.20",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 990,
"y": 180,
"wires": [
[
"7bb2ede9f31f99d1"
],
[
"af326163782a9cef"
]
]
},
{
"id": "af326163782a9cef",
"type": "hubitat command",
"z": "6dce1bddbac14e48",
"deviceLabel": "Den Ceiling LED",
"name": "Turn Off",
"server": "3b6080dc.a2527",
"deviceId": "1943",
"command": "off",
"commandArgs": "",
"x": 1180,
"y": 180,
"wires": [
[]
]
},
{
"id": "3fbb6b833559be32",
"type": "switch",
"z": "6dce1bddbac14e48",
"name": "check dps",
"property": "payload.data.dps",
"propertyType": "msg",
"rules": [
{
"t": "hask",
"v": "20",
"vt": "str"
},
{
"t": "hask",
"v": "21",
"vt": "str"
},
{
"t": "hask",
"v": "24",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 800,
"y": 240,
"wires": [
[
"88bbd024b713af57"
],
[],
[
"92896b2c0f69553a"
]
]
},
{
"id": "92896b2c0f69553a",
"type": "function",
"z": "6dce1bddbac14e48",
"name": "Color Code",
"func": " //24:00f403e801fe (0 0f4 0 3e8 0 1fe)\n //value:{\"h\":244,\"s\":1000,\"v\":510}]\n\nvar dpsVal = msg.payload.data.dps['24'];\n\nvar h = Math.round((parseInt(dpsVal.substr(1,3),16) / 360) * 100);\nvar s = parseInt(dpsVal.substr(5,3),16) / 10;\nvar v = parseInt(dpsVal.substr(9,3),16) / 10;\n\nvar colorMap = {};\ncolorMap.arguments = '{\"hue\":'+h+',\"saturation\":'+s+',\"level\":'+v+'}'\n\nreturn colorMap;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 990,
"y": 340,
"wires": [
[
"136665d79e46e848"
]
]
},
{
"id": "136665d79e46e848",
"type": "hubitat command",
"z": "6dce1bddbac14e48",
"deviceLabel": "Den Ceiling Lights TEST",
"name": "Set Color",
"server": "3b6080dc.a2527",
"deviceId": "1943",
"command": "setColor",
"commandArgs": "",
"x": 1180,
"y": 340,
"wires": [
[]
]
},
{
"id": "3b6080dc.a2527",
"type": "hubitat config",
"name": "Hubitat Hub",
"usetls": false,
"host": "192.168.1.4",
"port": "80",
"appId": "678",
"nodeRedServer": "http://192.168.1.8:1880",
"webhookPath": "/hubitat/webhook",
"autoRefresh": true,
"useWebsocket": false,
"colorEnabled": false,
"color": "#000000"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment