@Cheerlights to various RGB devices

This flow shows an example of how to parse a Twitter stream for the @Cheerlights supported colours and creates an output for each one found.

These are then passed to a rate limiting node to allow each colour to be shown in turn. A trigger node is then used to add "black" to turn off the LEDs after 4 minutes if not re-triggered beforehand.

The colour name to r,g,b and hex values can be used to drive other RGB LED type devices as appropriate.

[{"id":"55005fc7.aaffa","type":"twitter in","twitter":"","tags":"cheerlights","user":"false","name":"cheerlights","topic":"tweets","x":109,"y":562,"z":"c098fa53.5e7928","wires":[["6c7e8105.93818","c7068058.38f98"]]},{"id":"6c7e8105.93818","type":"function","name":"parse @Cheerlight colours","func":"msg.payload = msg.payload.toLowerCase();\n\nvar result = msg.payload.match(\n/red|green|blue|cyan|white|warmwhite|purple|magenta|yellow|orange|black|pink|oldlace/g);\n\n//    red (#FF0000)\n//    green (#008000)\n//    blue (#0000FF)\n//    cyan (#00FFFF)\n//    white (#FFFFFF)\n//    warmwhite (#FDF5E6)\n//    purple (#800080)\n//    magenta (#FF00FF)\n//    yellow (#FFFF00)\n//    orange (#FFA500)\n\nconsole.log(result);\n\nmsg = [];\nfor (var colour in result) {\n  msg.push({payload:result[colour]});\n}\n// and clear down to black afterwards\n//msg.push({payload:\"black\"});\n\n//console.log(msg);\nreturn [msg];","outputs":1,"x":229.0000114440918,"y":461.9999809265137,"z":"c098fa53.5e7928","wires":[["2571f114.da8e0e"]]},{"id":"c7068058.38f98","type":"debug","name":"","active":false,"complete":false,"x":303.9999694824219,"y":534,"z":"c098fa53.5e7928","wires":[]},{"id":"2571f114.da8e0e","type":"delay","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"2","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","x":442.0000305175781,"y":463,"z":"c098fa53.5e7928","wires":[["a468cfa0.5b973"]]},{"id":"a468cfa0.5b973","type":"trigger","op1":"1","op2":"black","op1type":"pay","op2type":"val","duration":"4","extend":"true","units":"min","name":"","x":510,"y":532,"z":"c098fa53.5e7928","wires":[["4ce12ff1.b31ed","d7567a7d.28a988","b64775a2.49b888"]]},{"id":"4ce12ff1.b31ed","type":"function","name":"Convert CSS Colour Name to hex and r,g,b values","func":"// outputs: 1\n\nvar colors = {\n  \"aqua\": \"#00ffff\",\n  \"aliceblue\": \"#f0f8ff\",\n  \"antiquewhite\": \"#faebd7\",\n  \"black\": \"#000000\",\n  \"off\": \"#000000\",\n  \"blue\": \"#0000ff\",\n  \"cyan\": \"#00ffff\",\n  \"darkblue\": \"#00008b\",\n  \"darkcyan\": \"#008b8b\",\n  \"darkgreen\": \"#006400\",\n  \"darkturquoise\": \"#00ced1\",\n  \"deepskyblue\": \"#00bfff\",\n  \"green\": \"#008000\",\n  \"lime\": \"#00ff00\",\n  \"mediumblue\": \"#0000cd\",\n  \"mediumspringgreen\": \"#00fa9a\",\n  \"navy\": \"#000080\",\n  \"springgreen\": \"#00ff7f\",\n  \"teal\": \"#008080\",\n  \"midnightblue\": \"#191970\",\n  \"dodgerblue\": \"#1e90ff\",\n  \"lightseagreen\": \"#20b2aa\",\n  \"forestgreen\": \"#228b22\",\n  \"seagreen\": \"#2e8b57\",\n  \"darkslategray\": \"#2f4f4f\",\n  \"darkslategrey\": \"#2f4f4f\",\n  \"limegreen\": \"#32cd32\",\n  \"mediumseagreen\": \"#3cb371\",\n  \"turquoise\": \"#40e0d0\",\n  \"royalblue\": \"#4169e1\",\n  \"steelblue\": \"#4682b4\",\n  \"darkslateblue\": \"#483d8b\",\n  \"mediumturquoise\": \"#48d1cc\",\n  \"indigo\": \"#4b0082\",\n  \"darkolivegreen\": \"#556b2f\",\n  \"cadetblue\": \"#5f9ea0\",\n  \"cornflowerblue\": \"#6495ed\",\n  \"mediumaquamarine\": \"#66cdaa\",\n  \"dimgray\": \"#696969\",\n  \"dimgrey\": \"#696969\",\n  \"slateblue\": \"#6a5acd\",\n  \"olivedrab\": \"#6b8e23\",\n  \"slategray\": \"#708090\",\n  \"slategrey\": \"#708090\",\n  \"lightslategray\": \"#778899\",\n  \"lightslategrey\": \"#778899\",\n  \"mediumslateblue\": \"#7b68ee\",\n  \"lawngreen\": \"#7cfc00\",\n  \"aquamarine\": \"#7fffd4\",\n  \"chartreuse\": \"#7fff00\",\n  \"gray\": \"#808080\",\n  \"grey\": \"#808080\",\n  \"maroon\": \"#800000\",\n  \"olive\": \"#808000\",\n  \"purple\": \"#800080\",\n  \"lightskyblue\": \"#87cefa\",\n  \"skyblue\": \"#87ceeb\",\n  \"blueviolet\": \"#8a2be2\",\n  \"darkmagenta\": \"#8b008b\",\n  \"darkred\": \"#8b0000\",\n  \"saddlebrown\": \"#8b4513\",\n  \"darkseagreen\": \"#8fbc8f\",\n  \"lightgreen\": \"#90ee90\",\n  \"mediumpurple\": \"#9370db\",\n  \"darkviolet\": \"#9400d3\",\n  \"palegreen\": \"#98fb98\",\n  \"darkorchid\": \"#9932cc\",\n  \"yellowgreen\": \"#9acd32\",\n  \"sienna\": \"#a0522d\",\n  \"brown\": \"#a52a2a\",\n  \"darkgray\": \"#a9a9a9\",\n  \"darkgrey\": \"#a9a9a9\",\n  \"greenyellow\": \"#adff2f\",\n  \"lightblue\": \"#add8e6\",\n  \"paleturquoise\": \"#afeeee\",\n  \"lightsteelblue\": \"#b0c4de\",\n  \"powderblue\": \"#b0e0e6\",\n  \"firebrick\": \"#b22222\",\n  \"darkgoldenrod\": \"#b8860b\",\n  \"mediumorchid\": \"#ba55d3\",\n  \"rosybrown\": \"#bc8f8f\",\n  \"darkkhaki\": \"#bdb76b\",\n  \"silver\": \"#c0c0c0\",\n  \"mediumvioletred\": \"#c71585\",\n  \"indianred\": \"#cd5c5c\",\n  \"peru\": \"#cd853f\",\n  \"chocolate\": \"#d2691e\",\n  \"tan\": \"#d2b48c\",\n  \"lightgray\": \"#d3d3d3\",\n  \"lightgrey\": \"#d3d3d3\",\n  \"thistle\": \"#d8bfd8\",\n  \"goldenrod\": \"#daa520\",\n  \"orchid\": \"#da70d6\",\n  \"palevioletred\": \"#db7093\",\n  \"crimson\": \"#dc143c\",\n  \"gainsboro\": \"#dcdcdc\",\n  \"plum\": \"#dda0dd\",\n  \"burlywood\": \"#deb887\",\n  \"lightcyan\": \"#e0ffff\",\n  \"lavender\": \"#e6e6fa\",\n  \"darksalmon\": \"#e9967a\",\n  \"palegoldenrod\": \"#eee8aa\",\n  \"violet\": \"#ee82ee\",\n  \"azure\": \"#f0ffff\",\n  \"honeydew\": \"#f0fff0\",\n  \"khaki\": \"#f0e68c\",\n  \"lightcoral\": \"#f08080\",\n  \"sandybrown\": \"#f4a460\",\n  \"beige\": \"#f5f5dc\",\n  \"mintcream\": \"#f5fffa\",\n  \"wheat\": \"#f5deb3\",\n  \"whitesmoke\": \"#f5f5f5\",\n  \"ghostwhite\": \"#f8f8ff\",\n  \"lightgoldenrodyellow\": \"#fafad2\",\n  \"linen\": \"#faf0e6\",\n  \"salmon\": \"#fa8072\",\n  \"oldlace\": \"#fdf5e6\",\n  \"warmwhite\": \"#fdf5e6\",\n  \"bisque\": \"#ffe4c4\",\n  \"blanchedalmond\": \"#ffebcd\",\n  \"coral\": \"#ff7f50\",\n  \"cornsilk\": \"#fff8dc\",\n  \"darkorange\": \"#ff8c00\",\n  \"deeppink\": \"#ff1493\",\n  \"floralwhite\": \"#fffaf0\",\n  \"fuchsia\": \"#ff00ff\",\n  \"gold\": \"#ffd700\",\n  \"hotpink\": \"#ff69b4\",\n  \"ivory\": \"#fffff0\",\n  \"lavenderblush\": \"#fff0f5\",\n  \"lemonchiffon\": \"#fffacd\",\n  \"lightpink\": \"#ffb6c1\",\n  \"lightsalmon\": \"#ffa07a\",\n  \"lightyellow\": \"#ffffe0\",\n  \"magenta\": \"#ff00ff\",\n  \"mistyrose\": \"#ffe4e1\",\n  \"moccasin\": \"#ffe4b5\",\n  \"navajowhite\": \"#ffdead\",\n  \"orange\": \"#ffa500\",\n  \"orangered\": \"#ff4500\",\n  \"papayawhip\": \"#ffefd5\",\n  \"peachpuff\": \"#ffdab9\",\n  \"pink\": \"#ffc0cb\",\n  \"red\": \"#ff0000\",\n  \"seashell\": \"#fff5ee\",\n  \"snow\": \"#fffafa\",\n  \"tomato\": \"#ff6347\",\n  \"white\": \"#ffffff\",\n  \"yellow\": \"#ffff00\"\n}\n\nif (msg.payload.toLowerCase() in colors) {\n\tmsg.payload = colors[msg.payload.toLowerCase()];\n\tvar r = parseInt(msg.payload.slice(1,3),16);\n\tvar g = parseInt(msg.payload.slice(3,5),16);\n\tvar b = parseInt(msg.payload.slice(5),16);\n\tmsg2 = { payload:r.toString()+\",\"+ g.toString()+\",\"+ b.toString() };\n\treturn [msg,msg2];\n}\n\nreturn null;","outputs":"2","x":613,"y":609,"z":"c098fa53.5e7928","wires":[[],[]]},{"id":"d7567a7d.28a988","type":"debug","name":"","active":true,"complete":false,"x":733.0001831054688,"y":530.0000305175781,"z":"c098fa53.5e7928","wires":[]},{"id":"b64775a2.49b888","type":"blinkstick","name":"","x":712.0000610351562,"y":472.0000305175781,"z":"c098fa53.5e7928","wires":[]}]

Flow Info

Created 11 years, 9 months ago
Updated 9 years, 7 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x2)
  • delay (x1)
  • function (x2)
  • trigger (x1)
Other

Tags

  • cheerlights
  • rgb
  • led
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option