Cheerlights Node-Red flow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"52247c3a.addb84","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"1041920c.efbe6e","type":"twitter in","twitter":"","tags":"cheerlights","user":"false","name":"","topic":"tweets","x":130,"y":136,"z":"edece394.12132","wires":[["d15fbafe.2ea048","ad98649a.526798"]]},{"id":"d15fbafe.2ea048","type":"debug","name":"","active":true,"complete":false,"x":542,"y":125,"z":"edece394.12132","wires":[]},{"id":"5d084303.a2f7bc","type":"mqtt out","name":"","topic":"smartstar/in","broker":"52247c3a.addb84","x":547,"y":240,"z":"edece394.12132","wires":[]},{"id":"ad98649a.526798","type":"function","name":"Cheerlights","func":"// Extract colours from Twitter String\n\nvar input = msg.payload;\nvar colours = input.toUpperCase().match(/\\b(red|blue|green|purple)\\b/ig);\nif (colours == null) { return }\n//console.log(\"colours:\" + colours);\n\nvar pattern = [];\ncolours.forEach(function(colour) {\n var cc = (colour == \"RED\") ? \"P\" : colour.charAt(0);\n \n console.log(\"Colour:\" + colour + \":\" + cc);\n \n if (pattern[pattern.length-1] == cc) {\n pattern.push(\" \");\n }\n \n pattern.push(cc);\n});\n\nif (pattern.length > 0) {\n msg.payload = \"CHEER \" + pattern.join(\"\");\n msg.input = input;\n return msg;\n}\n\n","outputs":1,"x":332,"y":221,"z":"edece394.12132","wires":[["ba2cd485.45d328","5d084303.a2f7bc"]]},{"id":"ba2cd485.45d328","type":"debug","name":"","active":true,"complete":false,"x":541,"y":176,"z":"edece394.12132","wires":[]},{"id":"f22b8f33.0dd47","type":"inject","name":"Test","topic":"","payload":"first #cheerlights of the year is Purple Red, Blue, Red and Green 1234567","repeat":"","crontab":"","once":false,"x":148,"y":273,"z":"edece394.12132","wires":[["ad98649a.526798"]]},{"id":"3b39377e.c4c6c8","type":"inject","name":"","topic":"Test (simple)","payload":"red","repeat":"","crontab":"","once":false,"x":158,"y":213,"z":"edece394.12132","wires":[["ad98649a.526798"]]},{"id":"635cf5b.f9ca30c","type":"inject","name":"ON (am)","topic":"","payload":"ON","repeat":"","crontab":"00 07 * * *","once":false,"x":151,"y":336,"z":"edece394.12132","wires":[["875ea232.78a16"]]},{"id":"d6375ba0.29c8a8","type":"inject","name":"OFF (am)","topic":"","payload":"OFF","repeat":"","crontab":"30 08 * * *","once":false,"x":153,"y":452,"z":"edece394.12132","wires":[["875ea232.78a16"]]},{"id":"ad91c998.526e38","type":"inject","name":"empty","topic":"","payload":"here is some text","repeat":"","crontab":"","once":false,"x":151,"y":178,"z":"edece394.12132","wires":[["ad98649a.526798"]]},{"id":"886c428c.7793c","type":"inject","name":"ON (pm)","topic":"","payload":"ON","repeat":"","crontab":"45 15 * * *","once":false,"x":152,"y":381,"z":"edece394.12132","wires":[["875ea232.78a16"]]},{"id":"875ea232.78a16","type":"function","name":"MQTT settings","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n// console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n// context = {};\n\nmsg.retain = true;\nreturn msg;","outputs":1,"x":344,"y":389,"z":"edece394.12132","wires":[["5d084303.a2f7bc"]]},{"id":"f0cf7026.0f309","type":"inject","name":"OFF (pm)","topic":"","payload":"OFF","repeat":"","crontab":"30 22 * * *","once":false,"x":150,"y":497,"z":"edece394.12132","wires":[["875ea232.78a16"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment