Snippets

Peter Scargill test imperiihome

Created by Peter Scargill
[{"id":"9b6ee235.64912","type":"http in","z":"43f4b595.bc0b4c","name":"","url":"/test1/system","method":"get","swaggerDoc":"","x":130,"y":80,"wires":[["412f364f.bed0c8"]]},{"id":"3bfad6cb.c4052a","type":"http in","z":"43f4b595.bc0b4c","name":"","url":"/test1/devices","method":"get","swaggerDoc":"","x":130,"y":120,"wires":[["6a6be476.95941c"]]},{"id":"bdca914d.42357","type":"http in","z":"43f4b595.bc0b4c","name":"","url":"/test1/rooms","method":"get","swaggerDoc":"","x":130,"y":160,"wires":[["f9eda3e8.06126"]]},{"id":"53b59832.ac4a68","type":"http response","z":"43f4b595.bc0b4c","name":"","x":470,"y":120,"wires":[]},{"id":"412f364f.bed0c8","type":"function","z":"43f4b595.bc0b4c","name":"","func":"msg.payload = { \"id\": \"ISS:Test:01\", \"apiversion\": 1};\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":80,"wires":[["53b59832.ac4a68"]]},{"id":"6a6be476.95941c","type":"function","z":"43f4b595.bc0b4c","name":"","func":"\nvar rgbState = global.get('rgbState') || 0;\nvar rgbLevel = global.get('rgbLevel') || 0;\nvar rgbColour = global.get('rgbColour') || \"AAAAAAAA\";\n\n\n\nmsg.payload = {\"devices\": [\n{ \"id\": \"dev01\", \"name\": \"RGB Light\", \"type\": \"DevRGBLight\", \"room\": \"roomID1\", \"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":310,"y":120,"wires":[["53b59832.ac4a68"]]},{"id":"f9eda3e8.06126","type":"function","z":"43f4b595.bc0b4c","name":"","func":"msg.payload = {\"rooms\": [{ \"id\": \"roomID1\", \"name\": \"Test Room\" }]};\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":160,"wires":[["53b59832.ac4a68"]]},{"id":"d236e67c.2dc918","type":"http in","z":"43f4b595.bc0b4c","name":"ISS Rest Actions","url":"/test1/devices/:deviceID/action/:actionName/:actionParameter","method":"get","swaggerDoc":"","x":140,"y":240,"wires":[["f5071863.0af8e8"]]},{"id":"f5071863.0af8e8","type":"switch","z":"43f4b595.bc0b4c","name":"","property":"req.params.deviceID","propertyType":"msg","rules":[{"t":"eq","v":"dev01","vt":"str"}],"checkall":"true","outputs":1,"x":310,"y":240,"wires":[["f4630890.0b9cf8","a25c036b.5da4"]]},{"id":"a25c036b.5da4","type":"function","z":"43f4b595.bc0b4c","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\n\nswitch (msg.req.params.actionName){\n case \"setStatus\": global.set('rgbState', msg.req.params.actionParameter);  break;  \n case \"setColor\":  global.set('rgbColour', msg.req.params.actionParameter);  break; \n case \"setLevel\":  global.set('rgbLevel', msg.req.params.actionParameter);  break;\n default: break;\n}\nif (global.get('rgbState') == '0' || global.get('rgbLevel') == '0') {\n    msg.payload = 'RGB = 0,0,0';\n} else {\n\n    hexColor = colorLuminance(global.get('rgbColour').slice(2), -1+(parseInt(global.get('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":470,"y":280,"wires":[["2cf6a69d.d3095a"]]},{"id":"2cf6a69d.d3095a","type":"debug","z":"43f4b595.bc0b4c","name":"","active":true,"console":"false","complete":"payload","x":610,"y":280,"wires":[]},{"id":"ee4870dd.11b79","type":"http response","z":"43f4b595.bc0b4c","name":"","x":590,"y":240,"wires":[]},{"id":"f4630890.0b9cf8","type":"function","z":"43f4b595.bc0b4c","name":"","func":"msg.payload = { \"success\": true, \"errormsg\": \"ok\" };\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":240,"wires":[["ee4870dd.11b79"]]}]

Comments (0)