Skip to content

Instantly share code, notes, and snippets.

@daffster
Last active December 17, 2021 00:03
Show Gist options
  • Save daffster/93b3c8d282e0b1f35138fd34bd05358a to your computer and use it in GitHub Desktop.
Save daffster/93b3c8d282e0b1f35138fd34bd05358a to your computer and use it in GitHub Desktop.
My Cheerlights HEX to RGB process in Node-RED
[
{
"id": "4ad8321e.b6550c",
"type": "tab",
"label": "CheerlightMQTT",
"disabled": false,
"info": "Manipulates incoming Cheerlight colours so we can use it with Home Assistant.\n\nConvert from HEX to RGB and keep the last two colours for WLED pallet usage."
},
{
"id": "8680abed92dbfabe",
"type": "mqtt in",
"z": "4ad8321e.b6550c",
"name": "CheerlightRGB",
"topic": "cheerlightsRGB",
"qos": "2",
"datatype": "auto",
"broker": "aa514acb.c5ac38",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 80,
"y": 300,
"wires": [
[
"124a1283fe27f5c1"
]
]
},
{
"id": "516a8ca4b640f4ab",
"type": "function",
"z": "4ad8321e.b6550c",
"name": "CheckNewRGB",
"func": "hex = msg.payload\nvar result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n\nvar r = parseInt(result[1], 16)\nvar g = parseInt(result[2], 16)\nvar b = parseInt(result[3], 16)\n\nprimaryRGB = flow.get(\"primaryRGB\")\nsecondaryRGB = flow.get(\"secondaryRGB\")\n\nAPICol1 = [r,g,b]\nAPICol2 = [primaryRGB.r, primaryRGB.g, primaryRGB.b]\nAPICol3 = [secondaryRGB.r, secondaryRGB.g, secondaryRGB.b]\nflow.set('tertiaryRGB', secondaryRGB)\nflow.set('secondaryRGB', primaryRGB)\nflow.set('primaryRGB', {'r':r, 'g':g, 'b':b})\n\n// Shift everything down one \"slot\"\nvar primarypayload = {payload: {'r':r, 'g':g, 'b': b}}\nvar secondarypayload = {payload: primaryRGB}\nvar tertiarypayload = { payload: secondaryRGB}\n\nvar APIpayload = {seg:[{'id':0,'pal':5,'col':[APICol1,APICol2,APICol3]}]}\nreturn [ primarypayload, secondarypayload, tertiarypayload, APIpayload]",
"outputs": 4,
"noerr": 0,
"initialize": "// Code added here will be run once\n// whenever the node is started.\nvar black = {r: 0, g: 0,b: 0}\nflow.set('secondaryRGB', black)\nflow.set('primaryRGB', black)\nflow.set('tertiaryRGB', black)\n",
"finalize": "",
"libs": [],
"x": 440,
"y": 480,
"wires": [
[
"bfe55059920de131"
],
[
"d3466a424e1fd215"
],
[
"95a2bf2da479f854"
],
[
"d98875e840ab8b2b"
]
],
"outputLabels": [
"NewRGB",
"",
"",
""
]
},
{
"id": "bfe55059920de131",
"type": "mqtt out",
"z": "4ad8321e.b6550c",
"name": "CheerLightsPrimaryRGB",
"topic": "cheerlightsPrimary",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa514acb.c5ac38",
"x": 750,
"y": 420,
"wires": []
},
{
"id": "124a1283fe27f5c1",
"type": "rbe",
"z": "4ad8321e.b6550c",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": true,
"property": "payload",
"topi": "topic",
"x": 270,
"y": 400,
"wires": [
[
"516a8ca4b640f4ab"
]
]
},
{
"id": "d3466a424e1fd215",
"type": "mqtt out",
"z": "4ad8321e.b6550c",
"name": "CheerLightsSecondaryRGB",
"topic": "cheerlightsSecondary",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa514acb.c5ac38",
"x": 760,
"y": 500,
"wires": []
},
{
"id": "95a2bf2da479f854",
"type": "mqtt out",
"z": "4ad8321e.b6550c",
"name": "CheerLightsTertiaryRGB",
"topic": "cheerlightTertiary",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "aa514acb.c5ac38",
"x": 760,
"y": 600,
"wires": []
},
{
"id": "d98875e840ab8b2b",
"type": "websocket out",
"z": "4ad8321e.b6550c",
"name": "CandyWS",
"server": "",
"client": "ea3b2cc02adac10d",
"x": 740,
"y": 720,
"wires": []
},
{
"id": "aa514acb.c5ac38",
"type": "mqtt-broker",
"name": "HA",
"broker": "192.168.30.33",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "ea3b2cc02adac10d",
"type": "websocket-client",
"path": "ws://100.64.1.107/ws",
"tls": "",
"wholemsg": "true",
"hb": "0"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment