HARDWARIO IoT Kit Light Control of LED Strip

Control colored lights in your room with HARDWARIO IoT Kit. Lights are controlled by orientation of Push button kit or by button itself.

IntermediateFull instructions provided1 hour1,330
HARDWARIO IoT Kit Light Control of LED Strip

Things used in this project

Story

Read more

Code

NODE-Red function

JSON
[{"id":"f338a06e.5e96e","type":"mqtt out","z":"e4e45972.f3d738","name":"","topic":"node/power-controller:0/led-strip/-/effect/set","qos":"","retain":"","broker":"d8ce0546.a191c8","x":1090,"y":240,"wires":[]},{"id":"8bdcc125.a549b","type":"change","z":"e4e45972.f3d738","name":"Effects without specific color","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"{\"type\":\"rainbow\", \"wait\":20}","tot":"json"},{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"num","to":"{\"type\":\"rainbow-cycle\",\"wait\":20}","tot":"json"},{"t":"change","p":"payload","pt":"msg","from":"3","fromt":"num","to":"{\"type\":\"theater-chase-rainbow\",\"wait\":0}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":240,"wires":[["f338a06e.5e96e"]]},{"id":"1beff53a.87590b","type":"mqtt in","z":"e4e45972.f3d738","name":"","topic":"node/push-button:0/orientation","qos":"2","broker":"d8ce0546.a191c8","x":150,"y":240,"wires":[["9b2d59c8.d1d4f8"]]},{"id":"9f485068.45baf","type":"mqtt in","z":"e4e45972.f3d738","name":"","topic":"node/push-button:0/push-button/-/event-count","qos":"2","broker":"d8ce0546.a191c8","x":200,"y":320,"wires":[["8d07aff0.1f888"]]},{"id":"8d07aff0.1f888","type":"function","z":"e4e45972.f3d738","name":"brightness adjust","func":"var brightness = flow.get(\"brightness\") || 0;\nbrightness += 10;\nif(brightness > 100)\n{\n    brightness = 0;\n    flow.set(\"brightness\", 0);\n}\nmsg.payload = brightness;\nflow.set(\"brightness\", brightness);\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":320,"wires":[["1802739c.8b8e5c"]]},{"id":"1802739c.8b8e5c","type":"mqtt out","z":"e4e45972.f3d738","name":"","topic":"node/power-controller:0/led-strip/-/brightness/set","qos":"","retain":"","broker":"d8ce0546.a191c8","x":860,"y":320,"wires":[]},{"id":"4e4aac7d.d3a5f4","type":"mqtt in","z":"e4e45972.f3d738","name":"","topic":"node/push-button:0/push-button/-/hold-count","qos":"2","broker":"d8ce0546.a191c8","x":200,"y":400,"wires":[["534eb20e.5124cc"]]},{"id":"534eb20e.5124cc","type":"function","z":"e4e45972.f3d738","name":"color swap","func":"var colors = [0x0000ff, 0xff0000, 0xffff00, 0x00ff00, 0xff1493, 0xffffff, 0xff4500, 0x800080, 0x8B4513];\nvar index = Math.floor(Math.random(colors.length) * 10);\n\nvar color = colors[index].toString(16);\n\n\n\nvar zeros = \"\";\nif(color.length != 6)\n{\n    for(var i = 0; i < 6 - color.length; i++)\n    {\n        zeros += \"0\";\n    }\n}\n\ncolor = zeros + color;\nflow.set(\"color\", color);\n\nmsg.payload = \"\\\"#\";\n\nmsg.payload += color + \"(00)\";\n\nmsg.payload += \"\\\"\";\n\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":400,"wires":[["2f2d39e4.08f946"]]},{"id":"2f2d39e4.08f946","type":"mqtt out","z":"e4e45972.f3d738","name":"","topic":"node/power-controller:0/led-strip/-/color/set","qos":"","retain":"","broker":"d8ce0546.a191c8","x":850,"y":400,"wires":[]},{"id":"9b2d59c8.d1d4f8","type":"switch","z":"e4e45972.f3d738","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"}],"checkall":"false","repair":false,"outputs":6,"x":350,"y":240,"wires":[["8bdcc125.a549b"],["8bdcc125.a549b"],["8bdcc125.a549b"],["55859fd.452786"],["55859fd.452786"],["55859fd.452786"]]},{"id":"53d9dff2.3de15","type":"json","z":"e4e45972.f3d738","name":"","property":"payload","action":"obj","pretty":false,"x":910,"y":140,"wires":[["f338a06e.5e96e"]]},{"id":"55e34bb3.286db4","type":"function","z":"e4e45972.f3d738","name":"color parse","func":"var color = flow.get(\"color\") || 0xff0000;\nmsg.payload += \"#\" + color + \"\\\"}\";\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":140,"wires":[["53d9dff2.3de15"]]},{"id":"55859fd.452786","type":"change","z":"e4e45972.f3d738","name":"Effects with specific color","rules":[{"t":"change","p":"payload","pt":"msg","from":"4","fromt":"num","to":"{\"type\":\"icicle\", \"wait\":80, \"color\":\"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"5","fromt":"num","to":"{\"type\":\"pulse-color\", \"wait\":80, \"color\":\"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"6","fromt":"num","to":"{\"type\":\"color-wipe\", \"wait\":50, \"color\":\"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":140,"wires":[["55e34bb3.286db4"]]},{"id":"d8ce0546.a191c8","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Credits

Jakub Smejkal

Jakub Smejkal

79 projects • 13 followers
Martin Hubáček

Martin Hubáček

65 projects • 56 followers
Lukáš Fabik

Lukáš Fabik

43 projects • 12 followers
Alan Fabik

Alan Fabik

43 projects • 11 followers
Pavel Hübner

Pavel Hübner

19 projects • 17 followers
I am a hardware engineer, firmware developer, and open-source enthusiast.

Comments