Snippets

Pete Matthews M8KGG: Untitled snippet

Updated by Pete Matthews

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
-[{"id":"bf506593.9dc8","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":150,"y":119,"wires":[["83dee4ee.25f0c"]]},{"id":"2b59a386.1bfac4","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":151,"y":205,"wires":[["3d4fb466.89833c"]]},{"id":"23a60cfb.c750e4","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":140,"y":161,"wires":[["9d36703c.58ae5"]]},{"id":"5d13de0c.5582f8","type":"http response","z":"9d003537.400d5","name":"","x":490,"y":159,"wires":[]},{"id":"83dee4ee.25f0c","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":119,"wires":[["5d13de0c.5582f8"]]},{"id":"3d4fb466.89833c","type":"function","z":"9d003537.400d5","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n//{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\"}, {\"key\": \"whitechannel\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":331,"y":205,"wires":[["5d13de0c.5582f8","3b867e4b.aba5c2"]]},{"id":"9d36703c.58ae5","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":331,"y":160,"wires":[["5d13de0c.5582f8"]]},{"id":"f7fe5b0f.a0c348","type":"http in","z":"9d003537.400d5","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":160,"y":279,"wires":[["8895f490.9b595"]]},{"id":"8895f490.9b595","type":"switch","z":"9d003537.400d5","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":330,"y":279,"wires":[["3a013137.565c46","78ee000d.0a6fd"]]},{"id":"764e3767.f29158","type":"debug","z":"9d003537.400d5","name":"","active":false,"console":"false","complete":"payload","x":636,"y":328,"wires":[]},{"id":"75f4d0b1.77d08","type":"http response","z":"9d003537.400d5","name":"","x":610,"y":279,"wires":[]},{"id":"3a013137.565c46","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":279,"wires":[["75f4d0b1.77d08"]]},{"id":"3b867e4b.aba5c2","type":"debug","z":"9d003537.400d5","name":"","active":false,"console":"false","complete":"false","x":560,"y":212,"wires":[]},{"id":"78ee000d.0a6fd","type":"function","z":"9d003537.400d5","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 100 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter; \n if (context.global.rgbState == 0) {context.global.rgbLevel = 0 } \n else {context.global.rgbLevel = 100 } break; \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  \n if (context.global.rgbLevel == 0) {context.global.rgbState = 0 }\n else {context.global.rgbState = 1 } break;\n default: break;\n}\nif (context.global.rgbState == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":455,"y":328,"wires":[["764e3767.f29158"]]}]
+[{"id":"916f2a42.8e3","type":"function","z":"75293b5b.80b7f4","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": \n    context.global.rgbState  = msg.req.params.actionParameter; \n    if (context.global.rgbState == \"0\") {context.global.rgbLevel = 0 } \n    else {context.global.rgbLevel = 100 } \n    break; \n case \"setColor\":  \n    context.global.rgbColour = msg.req.params.actionParameter;  \n    break; \n case \"setLevel\":  \n    context.global.rgbLevel  = msg.req.params.actionParameter;  \n    if (context.global.rgbLevel == \"0\") {context.global.rgbState = 0 }\n    else {context.global.rgbState = 1 } \n    break;\n default: \n break;\n}\nif (context.global.rgbState == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":477,"y":267,"wires":[["f6911e6f.1c69a"]]},{"id":"7719fdf3.bdddcc","type":"http in","z":"75293b5b.80b7f4","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":172,"y":58,"wires":[["ebe296fb.dd86d8"]]},{"id":"dc1a490e.b06c","type":"http in","z":"75293b5b.80b7f4","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":173,"y":144,"wires":[["b907ccdc.a65f7"]]},{"id":"5d0cd67e.a82748","type":"http in","z":"75293b5b.80b7f4","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":162,"y":100,"wires":[["17e0313b.1a60cf"]]},{"id":"5f3ed3fa.5ecf74","type":"http response","z":"75293b5b.80b7f4","name":"","x":512,"y":98,"wires":[]},{"id":"ebe296fb.dd86d8","type":"function","z":"75293b5b.80b7f4","name":"","func":"msg.payload = { \"id\": \"Fred2\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":352,"y":58,"wires":[["5f3ed3fa.5ecf74"]]},{"id":"b907ccdc.a65f7","type":"function","z":"75293b5b.80b7f4","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1_fred2\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n//{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\"}, {\"key\": \"whitechannel\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":353,"y":144,"wires":[["5f3ed3fa.5ecf74","6d4676ba.732e08"]]},{"id":"17e0313b.1a60cf","type":"function","z":"75293b5b.80b7f4","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1_fred2\", \"name\": \"Fred2 RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":353,"y":99,"wires":[["5f3ed3fa.5ecf74"]]},{"id":"4d671c8e.dd9dac","type":"http in","z":"75293b5b.80b7f4","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":182,"y":218,"wires":[["e61362a1.26c17","4ff5ff8f.85e1c","9d2b0adf.5a1d7"]]},{"id":"e61362a1.26c17","type":"switch","z":"75293b5b.80b7f4","name":"","property":"req.params.deviceID","rules":[{"t":"eq","v":"rgb01"}],"checkall":"true","outputs":1,"x":352,"y":218,"wires":[["d29f1206.c54b28","916f2a42.8e3"]]},{"id":"f6911e6f.1c69a","type":"debug","z":"75293b5b.80b7f4","name":"","active":true,"console":"false","complete":"payload","x":658,"y":267,"wires":[]},{"id":"3e063f95.909e2","type":"http response","z":"75293b5b.80b7f4","name":"","x":632,"y":218,"wires":[]},{"id":"d29f1206.c54b28","type":"function","z":"75293b5b.80b7f4","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":512,"y":218,"wires":[["3e063f95.909e2"]]},{"id":"6d4676ba.732e08","type":"debug","z":"75293b5b.80b7f4","name":"","active":false,"console":"false","complete":"false","x":582,"y":151,"wires":[]},{"id":"3e1b642d.5edcfc","type":"inject","z":"75293b5b.80b7f4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":149,"y":303.5,"wires":[["f13e5a54.a07cd"]]},{"id":"f13e5a54.a07cd","type":"function","z":"75293b5b.80b7f4","name":"","func":"context.global.rgbState = \"0\";\ncontext.global.rgbLevel = \"45\";\nreturn msg;","outputs":1,"noerr":0,"x":327,"y":408.5,"wires":[[]]},{"id":"4ff5ff8f.85e1c","type":"debug","z":"75293b5b.80b7f4","name":"","active":true,"console":"false","complete":"req.params.actionName","x":551,"y":328,"wires":[]},{"id":"9d2b0adf.5a1d7","type":"debug","z":"75293b5b.80b7f4","name":"","active":true,"console":"false","complete":"req.params.actionParameter","x":583,"y":376,"wires":[]}]
Updated by Pete Matthews

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
-[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n//{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\"}, {\"key\": \"whitechannel\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":false,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (context.global.rgbState == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
+[{"id":"bf506593.9dc8","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":150,"y":119,"wires":[["83dee4ee.25f0c"]]},{"id":"2b59a386.1bfac4","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":151,"y":205,"wires":[["3d4fb466.89833c"]]},{"id":"23a60cfb.c750e4","type":"http in","z":"9d003537.400d5","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":140,"y":161,"wires":[["9d36703c.58ae5"]]},{"id":"5d13de0c.5582f8","type":"http response","z":"9d003537.400d5","name":"","x":490,"y":159,"wires":[]},{"id":"83dee4ee.25f0c","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":119,"wires":[["5d13de0c.5582f8"]]},{"id":"3d4fb466.89833c","type":"function","z":"9d003537.400d5","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n//{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\"}, {\"key\": \"whitechannel\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":331,"y":205,"wires":[["5d13de0c.5582f8","3b867e4b.aba5c2"]]},{"id":"9d36703c.58ae5","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":331,"y":160,"wires":[["5d13de0c.5582f8"]]},{"id":"f7fe5b0f.a0c348","type":"http in","z":"9d003537.400d5","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":160,"y":279,"wires":[["8895f490.9b595"]]},{"id":"8895f490.9b595","type":"switch","z":"9d003537.400d5","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":330,"y":279,"wires":[["3a013137.565c46","78ee000d.0a6fd"]]},{"id":"764e3767.f29158","type":"debug","z":"9d003537.400d5","name":"","active":false,"console":"false","complete":"payload","x":636,"y":328,"wires":[]},{"id":"75f4d0b1.77d08","type":"http response","z":"9d003537.400d5","name":"","x":610,"y":279,"wires":[]},{"id":"3a013137.565c46","type":"function","z":"9d003537.400d5","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":279,"wires":[["75f4d0b1.77d08"]]},{"id":"3b867e4b.aba5c2","type":"debug","z":"9d003537.400d5","name":"","active":false,"console":"false","complete":"false","x":560,"y":212,"wires":[]},{"id":"78ee000d.0a6fd","type":"function","z":"9d003537.400d5","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 100 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter; \n if (context.global.rgbState == 0) {context.global.rgbLevel = 0 } \n else {context.global.rgbLevel = 100 } break; \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  \n if (context.global.rgbLevel == 0) {context.global.rgbState = 0 }\n else {context.global.rgbState = 1 } break;\n default: break;\n}\nif (context.global.rgbState == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":455,"y":328,"wires":[["764e3767.f29158"]]}]
Updated by Pete Matthews

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
-[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"dev01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (global.get('rgbState') == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
+[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n//{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n{ \"id\": \"rgb01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\"}, {\"key\": \"whitechannel\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":false,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (context.global.rgbState == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
Updated by Pete Matthews

File snippet.txt Modified

  • Ignore whitespace
  • Hide word diff
-[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"dev01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":false,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 };\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 };\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" };\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (global.get('rgbState') == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
+[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"dev01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 }\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 }\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" }\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (global.get('rgbState') == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
Created by Pete Matthews

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+[{"id":"5d4c444.91d4c3c","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":160,"y":142,"wires":[["9f730310.859a08"]]},{"id":"35bef56a.eb535a","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":161,"y":228,"wires":[["bef7567e.26ce1"]]},{"id":"c9701390.f99ec","type":"http in","z":"17cb4244.7c3e06","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":150,"y":184,"wires":[["6b26d587.7708c4"]]},{"id":"6382c1fb.7a8e48","type":"http response","z":"17cb4244.7c3e06","name":"","x":500,"y":182,"wires":[]},{"id":"9f730310.859a08","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":142,"wires":[["6382c1fb.7a8e48"]]},{"id":"bef7567e.26ce1","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nvar rgbState  = context.global.rgbState  || 0;\nvar rgbLevel  = context.global.rgbLevel  || 0;\nvar rgbColour = context.global.rgbColour || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"dev01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1ps\", \"params\": [{\"key\": \"dimmable\", \"value\": \"1\"}, {\"key\": \"whitechannel\", \"value\": \"0\"}, {\"key\": \"Status\", \"value\": rgbState}, {\"key\": \"Level\", \"value\": rgbLevel}, {\"key\": \"color\", \"value\": rgbColour}]}\n]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":228,"wires":[["6382c1fb.7a8e48","834aeb05.955108"]]},{"id":"6b26d587.7708c4","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1ps\", \"name\": \"RGB Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":341,"y":183,"wires":[["6382c1fb.7a8e48"]]},{"id":"812f0d5a.cd9df8","type":"http in","z":"17cb4244.7c3e06","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":170,"y":302,"wires":[["1b86cc98.e954eb"]]},{"id":"1b86cc98.e954eb","type":"switch","z":"17cb4244.7c3e06","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":340,"y":302,"wires":[["30ac57e8.fb2bb","81ad3ba5.237ca8"]]},{"id":"49283e22.33fe68","type":"debug","z":"17cb4244.7c3e06","name":"","active":true,"console":"false","complete":"payload","x":646,"y":351,"wires":[]},{"id":"2f4e5c21.a0782c","type":"http response","z":"17cb4244.7c3e06","name":"","x":620,"y":302,"wires":[]},{"id":"30ac57e8.fb2bb","type":"function","z":"17cb4244.7c3e06","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":302,"wires":[["2f4e5c21.a0782c"]]},{"id":"834aeb05.955108","type":"debug","z":"17cb4244.7c3e06","name":"","active":false,"console":"false","complete":"false","x":570,"y":235,"wires":[]},{"id":"81ad3ba5.237ca8","type":"function","z":"17cb4244.7c3e06","name":"","func":"\nfunction colorLuminance(hex, lum) {\n    // Validate hex string\n    hex = String(hex).replace(/[^0-9a-f]/gi, \"\");\n    if (hex.length < 6) {\n        hex = hex.replace(/(.)/g, '$1$1');\n    }\n    lum = lum || 0;\n    // Convert to decimal and change luminosity\n    var rgb = \"#\",\n        c;\n    for (var i = 0; i < 3; ++i) {\n        c = parseInt(hex.substr(i * 2, 2), 16);\n        c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);\n        rgb += (\"00\" + c).substr(c.length);\n    }\n    return rgb;\n}\n\nif (typeof context.global.rgbState === \"undefined\") {\ncontext.global.rgbState = 0 };\nif (typeof context.global.rgbLevel === \"undefined\") {\ncontext.global.rgbLevel = 0 };\nif (typeof context.global.rgbColour === \"undefined\") {\ncontext.global.rgbColour = \"AAAAAAAA\" };\nswitch (msg.req.params.actionName){\n case \"setStatus\": context.global.rgbState  = msg.req.params.actionParameter;  break;  \n case \"setColor\":  context.global.rgbColour = msg.req.params.actionParameter;  break; \n case \"setLevel\":  context.global.rgbLevel  = msg.req.params.actionParameter;  break;\n default: break;\n}\nif (global.get('rgbState') == '0' || context.global.rgbLevel == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(context.global.rgbColour.slice(2), -1+(parseInt(context.global.rgbLevel)*0.01));\n\n    msg.payload = 'RGB = ' + parseInt(hexColor.substr(1,2), 16) + ',' + parseInt(hexColor.substr(3,2), 16) + ',' + parseInt(hexColor.substr(5,2), 16); \n    } \nreturn msg;\n","outputs":1,"noerr":0,"x":465,"y":351,"wires":[["49283e22.33fe68"]]}]
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.