Control WLED neopixels from Twitter

Connects a Twitter search (in this example for "#DoESTheLiverbirdPlay") to an ESP8266/ESP32 running the WLED software so that you can tweet a colour and/or a lighting effect and have the RGB LEDs react accordingly

[{"id":"db1d65be.42f728","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8c94ab52.90aa9","type":"inject","z":"db1d65be.42f728","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"on\": true }","payloadType":"json","x":110,"y":560,"wires":[["bf7b8d1d.9fbfa"]]},{"id":"bdd8bf72.6a1eb8","type":"debug","z":"db1d65be.42f728","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":240,"wires":[]},{"id":"c21a01f5.502cd","type":"twitter in","z":"db1d65be.42f728","twitter":"","tags":"#DoesTheLiverbirdPlay","user":"false","name":"","inputs":0,"x":90,"y":40,"wires":[["bdd8bf72.6a1eb8","408a98a3.c56498","527a3d89.209aac","8c068bb4.446258"]]},{"id":"bf7b8d1d.9fbfa","type":"wled2","z":"db1d65be.42f728","address":"10.0.33.231","brightness":128,"delay":0,"color1":"#ffffff","color2":"#ffffff","color3":"#ffffff","effect":0,"effectIntensity":128,"effectSpeed":128,"name":"Liverbird","palette":"0","preset":0,"state":"on","x":360,"y":560,"wires":[["bdd8bf72.6a1eb8"]]},{"id":"8a8488eb.866b1","type":"inject","z":"db1d65be.42f728","name":"Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"state\": \"off\" }","payloadType":"json","x":110,"y":600,"wires":[["bf7b8d1d.9fbfa"]]},{"id":"4d705230.c36f04","type":"node-red-contrib-colorspace","z":"db1d65be.42f728","name":"","target":"payload","x":160,"y":440,"wires":[["bdd8bf72.6a1eb8","bf798744.8bb978"]]},{"id":"bf798744.8bb978","type":"template","z":"db1d65be.42f728","name":"Turn colour into a message for WLED","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \n  \"color1\": [\n    {{payload.rgb.red}}, \n    {{payload.rgb.green}}, \n    {{payload.rgb.blue}}\n  ],\n  \"color2\": [0,0,0],\n  \"color3\": [0,0,0],\n  \"effect\": {{effect}}\n}","output":"json","x":230,"y":500,"wires":[["bf7b8d1d.9fbfa","bdd8bf72.6a1eb8"]]},{"id":"83d007bb.ede018","type":"delay","z":"db1d65be.42f728","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":150,"y":380,"wires":[["4d705230.c36f04"]]},{"id":"408a98a3.c56498","type":"function","z":"db1d65be.42f728","name":"Choose the effect","func":"var effects = [\n    { \"name\": \"TWO DOTS\", \"value\":  50 },\n    { \"name\": \"TWO AREAS\", \"value\":  51 },\n    { \"name\": \"TWINKLE\", \"value\":  17 },  \n    { \"name\": \"TWINKLEUP\", \"value\": 106 },\n    { \"name\": \"TWINKLEFOX\", \"value\":  80 },\n    { \"name\": \"TWINKLECAT\", \"value\":  81 },\n    { \"name\": \"TRI STATIC PATTERN\", \"value\":  84 },\n    { \"name\": \"TRICOLOR WIPE\", \"value\":  55 },\n    { \"name\": \"TRICOLOR FADE\", \"value\":  56 },\n    { \"name\": \"TRICOLOR CHASE\", \"value\":  54 },\n    { \"name\": \"TRAFFIC LIGHT\", \"value\":  35 },\n    { \"name\": \"THEATER CHASE\", \"value\":  13 },\n    { \"name\": \"THEATER CHASE RAINBOW\", \"value\":  14 },\n    { \"name\": \"SUNRISE\", \"value\": 104 },\n    { \"name\": \"STROBE\", \"value\":  23 },\n    { \"name\": \"STROBE RAINBOW\", \"value\":  24 },\n    { \"name\": \"STATIC\", \"value\":   0 },\n    { \"name\": \"STATIC PATTERN\", \"value\":  83 },\n    { \"name\": \"STARBURST\", \"value\":  89 },\n    { \"name\": \"SPOTS\", \"value\":  85 },\n    { \"name\": \"SPOTS FADE\", \"value\":  86 },\n    { \"name\": \"SPARKLE\", \"value\":  20 },\n    { \"name\": \"SOLID GLITTER\", \"value\": 103 },\n    { \"name\": \"SINEWAVE\", \"value\": 108 },\n    { \"name\": \"SINELON\", \"value\":  92 },\n    { \"name\": \"SINELON RAINBOW\", \"value\":  94 },\n    { \"name\": \"SINELON DUAL\", \"value\":  93 },\n    { \"name\": \"SCAN\", \"value\":  10 }, \n    { \"name\": \"SAW\", \"value\":  16 },\n    { \"name\": \"RUNNING RED BLUE\", \"value\":  38 },\n    { \"name\": \"RUNNING RANDOM\", \"value\":  39 },\n    { \"name\": \"RUNNING LIGHTS\", \"value\":  15 },\n    { \"name\": \"RUNNING COLOR\", \"value\":  37 },\n    { \"name\": \"RIPPLE\", \"value\":  79 },\n    { \"name\": \"RIPPLE RAINBOW\", \"value\":  99 },\n    { \"name\": \"RANDOM COLOR\", \"value\":   5 },\n    { \"name\": \"RANDOM CHASE\", \"value\":  61 },\n    { \"name\": \"RAIN\", \"value\":  43 },\n    { \"name\": \"RAINBOW\", \"value\":   8 },\n    { \"name\": \"RAINBOW CYCLE\", \"value\":   9 },\n    { \"name\": \"RAILWAY\", \"value\":  78 },\n    { \"name\": \"PRIDE 2015\", \"value\":  63 },\n    { \"name\": \"POPCORN\", \"value\":  95 },\n    { \"name\": \"POLICE\", \"value\":  48 },\n    { \"name\": \"POLICE ALL\", \"value\":  49 },\n    { \"name\": \"PLASMA\", \"value\":  97 },\n    { \"name\": \"PHASED\", \"value\": 105 },\n    { \"name\": \"PHASEDNOISE\", \"value\": 109 },\n    { \"name\": \"PERCENT\", \"value\":  98 },\n    { \"name\": \"PALETTE\", \"value\":  65 },\n    { \"name\": \"PACIFICA\", \"value\": 101 },\n    { \"name\": \"OSCILLATE\", \"value\":  62 },\n    { \"name\": \"NOISEPAL\", \"value\": 107 },\n    { \"name\": \"NOISE16 4\", \"value\":  73 },\n    { \"name\": \"NOISE16 3\", \"value\":  72 },\n    { \"name\": \"NOISE16 2\", \"value\":  71 },\n    { \"name\": \"NOISE16 1\", \"value\":  70 },\n    { \"name\": \"MULTI STROBE\", \"value\":  25 },\n    { \"name\": \"MULTI COMET\", \"value\":  59 },\n    { \"name\": \"METEOR\", \"value\":  76 },\n    { \"name\": \"METEOR SMOOTH\", \"value\":  77 },\n    { \"name\": \"MERRY CHRISTMAS\", \"value\":  44 },\n    { \"name\": \"LOADING\", \"value\":  47 },\n    { \"name\": \"LIGHTNING\", \"value\":  57 },\n    { \"name\": \"LARSON SCANNER\", \"value\":  40 },\n    { \"name\": \"LAKE\", \"value\":  75 },\n    { \"name\": \"JUGGLE\", \"value\":  64 },\n    { \"name\": \"ICU\", \"value\":  58 },\n    { \"name\": \"HYPER SPARKLE\", \"value\":  22 },\n    { \"name\": \"HEARTBEAT\", \"value\": 100 },\n    { \"name\": \"HALLOWEEN\", \"value\":  53 },\n    { \"name\": \"HALLOWEEN EYES\", \"value\":  82 },\n    { \"name\": \"GRADIENT\", \"value\":  46 },\n    { \"name\": \"GLITTER\", \"value\":  87 },\n    { \"name\": \"FLOW\", \"value\": 110 },\n    { \"name\": \"FLASH SPARKLE\", \"value\":  21 },\n    { \"name\": \"FIREWORKS\", \"value\":  42 },\n    { \"name\": \"FIRE FLICKER\", \"value\":  45 },\n    { \"name\": \"FIRE 2012\", \"value\":  66 },\n    { \"name\": \"FILLNOISE8\", \"value\":  69 },\n    { \"name\": \"FADE\", \"value\":  12 },\n    { \"name\": \"EXPLODING FIREWORKS\", \"value\":  90 },\n    { \"name\": \"DYNAMIC\", \"value\":   7 },\n    { \"name\": \"DUAL SCAN\", \"value\":  11 }, \n    { \"name\": \"DUAL LARSON SCANNER\", \"value\":  60 },\n    { \"name\": \"DRIP\", \"value\":  96 },\n    { \"name\": \"DISSOLVE\", \"value\":  18 },\n    { \"name\": \"DISSOLVE RANDOM\", \"value\":  19 },\n    { \"name\": \"COMET\", \"value\":  41 },\n    { \"name\": \"COLOR WIPE\", \"value\":   3 },\n    { \"name\": \"COLOR WIPE RANDOM\", \"value\":   4 },\n    { \"name\": \"COLORWAVES\", \"value\":  67 },\n    { \"name\": \"COLORTWINKLE\", \"value\":  74 },\n    { \"name\": \"COLOR SWEEP\", \"value\":   6 },\n    { \"name\": \"COLOR SWEEP RANDOM\", \"value\":  36 },\n    { \"name\": \"COLORFUL\", \"value\":  34 },\n    { \"name\": \"CIRCUS COMBUSTUS\", \"value\":  52 },\n    { \"name\": \"CHUNCHUN\", \"value\": 111 },\n    { \"name\": \"CHASE RANDOM\", \"value\":  29 },\n    { \"name\": \"CHASE RAINBOW WHITE\", \"value\":  33 },\n    { \"name\": \"CHASE RAINBOW\", \"value\":  30 },\n    { \"name\": \"CHASE FLASH\", \"value\":  31 },\n    { \"name\": \"CHASE FLASH RANDOM\", \"value\":  32 },\n    { \"name\": \"CHASE COLOR\", \"value\":  28 },\n    { \"name\": \"CANDLE\", \"value\":  88 },\n    { \"name\": \"CANDLE MULTI\", \"value\": 102 },\n    { \"name\": \"BREATH\", \"value\":   2 },\n    { \"name\": \"BPM\", \"value\":  68 },\n    { \"name\": \"BOUNCINGBALLS\", \"value\":  91 },\n    { \"name\": \"BLINK\", \"value\":   1 },\n    { \"name\": \"BLINK RAINBOW\", \"value\":  26 },\n    { \"name\": \"ANDROID\", \"value\":  27 }\n];\n// Work out if this is a super long tweet and pull out\n// the longer text\nif (msg.tweet.truncated) {\n    // It's a long tweet\n    msg.payload = msg.tweet.extended_tweet.full_text;\n}\n\nvar chosen_effect = 18;\nvar p = msg.payload.toUpperCase();\nfor (var i =0; i < effects.length; i++) {\n    if (p.search(effects[i].name) >= 0) {\n        chosen_effect = effects[i].value;\n    }\n}\n\nreturn { \"payload\": msg.payload, \"effect\": chosen_effect };","outputs":1,"noerr":0,"initialize":"","finalize":"","x":170,"y":100,"wires":[["d3c56657.ab91b"]]},{"id":"d3c56657.ab91b","type":"split","z":"db1d65be.42f728","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":130,"y":160,"wires":[["a2a00151.6d05b"]]},{"id":"eb2e1fdc.5490f","type":"string","z":"db1d65be.42f728","name":"Strip out any punctuation","methods":[{"name":"stripPunctuation","params":[]},{"name":"toLowerCase","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":190,"y":320,"wires":[["83d007bb.ede018"]]},{"id":"a2a00151.6d05b","type":"switch","z":"db1d65be.42f728","name":"","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"#DoesTheLiverbirdPlay","vt":"str","case":true},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":200,"wires":[["8fe4221f.7745d"],["d59fdff6.35ea"]]},{"id":"8fe4221f.7745d","type":"change","z":"db1d65be.42f728","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"blueviolet","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":200,"wires":[["83d007bb.ede018","bdd8bf72.6a1eb8"]]},{"id":"8b8fc3c7.fc4bd8","type":"twitter out","z":"db1d65be.42f728","twitter":"","name":"Tweet","x":790,"y":160,"wires":[]},{"id":"561afa77.b9a72c","type":"template","z":"db1d65be.42f728","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"@{{tweet.user.screen_name}} Nice! See it live here: https://www.youtube.com/watch?v=UXvZNb_OVQw\n\n(unless someone else has played with the liver bird since!)\n\nInspired by Love To Play 2021: https://lovetoplay.fun - check it out!","output":"str","x":660,"y":100,"wires":[["8b8fc3c7.fc4bd8","527a3d89.209aac"]]},{"id":"9d1702cb.7ff41","type":"change","z":"db1d65be.42f728","name":"","rules":[{"t":"set","p":"params","pt":"msg","to":"{ \"in_reply_to_status_id\": \"1380557517529485300\"}","tot":"json"},{"t":"set","p":"params.in_reply_to_status_id","pt":"msg","to":"tweet.id_str","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":100,"wires":[["561afa77.b9a72c","527a3d89.209aac"]]},{"id":"527a3d89.209aac","type":"debug","z":"db1d65be.42f728","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":180,"wires":[]},{"id":"8c068bb4.446258","type":"switch","z":"db1d65be.42f728","name":"Discard RTs","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"^RT ","vt":"str","case":false},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":40,"wires":[["527a3d89.209aac"],["9d1702cb.7ff41"]]},{"id":"d59fdff6.35ea","type":"function","z":"db1d65be.42f728","name":"Catch HEX colours","func":"if (msg.payload.match(/#[0-9a-fA-F]+/)) {\n    // It's a HEX colour\n    // Extract the relevant bit...\n    msg.payload = { \"hex\": msg.payload.match(/#([0-9a-fA-F]+)/)[1] };\n    return [msg, null];\n} else {\n    return [null, msg];\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":170,"y":260,"wires":[["83d007bb.ede018"],["eb2e1fdc.5490f"]]}]

Flow Info

Created 3 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • debug (x2)
  • delay (x1)
  • function (x2)
  • inject (x2)
  • split (x1)
  • switch (x2)
  • template (x2)
Other

Tags

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