|
[{"id":"ec22fd2d9a498086","type":"tab","label":"Color Loop","disabled":false,"info":"","env":[]},{"id":"5c960d526cfff1b2","type":"link in","z":"ec22fd2d9a498086","name":"","links":["dd2114c718df4892","5085829335ba248c","ac68dbc399f99fd1","f23f2d6854efbe20","2764c38f9e14979d"],"x":115,"y":60,"wires":[["8e09f9d06493bcb6"]]},{"id":"651e1d7c5572c654","type":"link out","z":"ec22fd2d9a498086","name":"","mode":"return","links":[],"x":1195,"y":60,"wires":[]},{"id":"8e09f9d06493bcb6","type":"change","z":"ec22fd2d9a498086","name":"Store RGB Color","rules":[{"t":"set","p":"status","pt":"flow","to":"status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":60,"wires":[["c15001e6c435dbed"]]},{"id":"c15001e6c435dbed","type":"function","z":"ec22fd2d9a498086","name":"Set Flow Var","func":"if(!msg.entity) {\n node.status({\n text: 'No Light defined',\n shape: 'ring',\n fill: 'red'\n });\n return; \n}\n\nflow.set(\"i\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":60,"wires":[["e6d566226c87b354"]]},{"id":"e6d566226c87b354","type":"function","z":"ec22fd2d9a498086","name":"Control Light","func":"setNodeStatus()\nswitch(flow.get(\"status\")){\n case(\"on\"):\n msg.payload = startColorFlow();\n break;\n case(\"stop\"):\n // msg.payload = stopColorFlow();\n break;\n case(\"off\"):\n msg.payload = turnOff();\n break;\n default:\n msg.payload = turnOff();\n}\n\nreturn msg;\n\nfunction startColorFlow(){\n var i = flow.get(\"i\");\n var red = Math.round(Math.sin(0.3*i + 0) * 127 + 128);\n var green = Math.round(Math.sin(0.3*i + 2) * 127 + 128);\n var blue = Math.round(Math.sin(0.3*i + 4) * 127 + 128);\n var rgb_array = null;\n \n if(flow.get(\"rgb_color\") && i==0) rgb_array = flow.get(\"rgb_color\")\n else {\n rgb_array = [red, green, blue]\n flow.set(\"rgb_color\", rgb_array)\n }\n \n i++;\n if (i>=32) i = 0;\n\n flow.set(\"i\", i);\n \n return {\n domain: 'light',\n service: 'turn_on',\n data: {\n entity_id: msg.entity, \n rgb_color: rgb_array,\n transition: 2\n }\n };\n}\n\nfunction stopColorFlow(){\n node.warn(\"rgbcolor\", flow.get(\"rgb_color\"))\n return {\n domain: 'light',\n service: 'turn_on',\n data: {\n rgb_color: flow.get(\"rgb_color\") || [253, 244, 220],\n entity_id: msg.entity\n }\n };\n}\n\nfunction turnOff(){\n return {\n domain: 'light',\n service: 'turn_off',\n data: {\n entity_id: msg.entity, \n transition: 1\n }\n };\n}\n\nfunction setNodeStatus(){\n const data = {};\n if(flow.get(\"status\") === \"on\") {\n data.text = \"Color Loop Enabled\",\n data.fill = \"green\"\n }\n if(flow.get(\"status\") === \"off\") {\n data.text = \"Color Loop Off\",\n data.fill = \"grey\"\n }\n if(flow.get(\"status\") === \"stop\") {\n data.text = \"Color Loop Stopped\",\n data.fill = \"red\"\n }\n node.status({\n text: data.text,\n shape: 'dot',\n fill: data.fill\n});\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":60,"wires":[["bdd4747a8b340a58","57cb4465d1220e9d"]]},{"id":"57cb4465d1220e9d","type":"delay","z":"ec22fd2d9a498086","name":"Delay","pauseType":"delayv","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":590,"y":160,"wires":[["5e81bbe30f142018"]]},{"id":"2ab77f2d250180d5","type":"api-call-service","z":"ec22fd2d9a498086","name":"Call Service Node","server":"68b1f3b6.69c6ac","version":3,"debugenabled":true,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1050,"y":60,"wires":[["651e1d7c5572c654"]]},{"id":"bdd4747a8b340a58","type":"switch","z":"ec22fd2d9a498086","name":"","property":"status","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":850,"y":60,"wires":[["2ab77f2d250180d5"],["2ab77f2d250180d5"]]},{"id":"5e81bbe30f142018","type":"switch","z":"ec22fd2d9a498086","name":"","property":"status","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":710,"y":160,"wires":[["e6d566226c87b354"]]},{"id":"68b1f3b6.69c6ac","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}] |