Last active
August 17, 2021 01:04
-
-
Save sstratoti/50c3a412bbe6f610fc66972c85370971 to your computer and use it in GitHub Desktop.
HA Alert Queue Subflow
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": "eec8b4376623cc26", | |
"type": "subflow", | |
"name": "HA Alert Queue", | |
"info": "", | |
"category": "", | |
"in": [ | |
{ | |
"x": 180, | |
"y": 200, | |
"wires": [ | |
{"id": "7cee9c204a758557"} | |
] | |
} | |
], | |
"out": [ | |
{ | |
"x": 900, | |
"y": 200, | |
"wires": [ | |
{ | |
"id": "7cee9c204a758557", | |
"port": 0 | |
} | |
] | |
} | |
], | |
"env": [ | |
{ | |
"name": "id", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "ID"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "name", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Name"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "label", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Label"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "icon", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Icon"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "textColor", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Text Color"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "backgroundColor", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Background Color"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
}, | |
{ | |
"name": "entityName", | |
"type": "str", | |
"value": "", | |
"ui": { | |
"label": {"en-US": "Entity Name"}, | |
"type": "input", | |
"opts": { | |
"types": ["str"] | |
} | |
} | |
} | |
], | |
"meta": {}, | |
"color": "#FF4C4C", | |
"icon": "font-awesome/fa-bell-o" | |
}, | |
{ | |
"id": "7cee9c204a758557", | |
"type": "function", | |
"z": "eec8b4376623cc26", | |
"name": "Add Message to Global Queue", | |
"func": "var alertArray = global.get('alertArray') || {\"alerts\":[]};\n\nif (typeof msg.clear !== 'undefined' && msg.clear !== null) {\n if (msg.clear && alertArray.alerts.length > 0) {\n alertArray.alerts = alertArray.alerts.filter(e => e.id !== env.get('id') );\n }\n} else {\n msg = {};\n msg.id = env.get('id');\n msg.payload = 'on';\n msg.name = env.get('name');\n msg.label = env.get('label');\n msg.backgroundColor = env.get('backgroundColor');\n msg.textColor = env.get('textColor');\n msg.icon = env.get('icon');\n msg.animation = 'none';\n msg.entity = env.get('entityName');\n var searchIndex = -1;\n if (alertArray.alerts.length > 0){\n for (i=0; i < alertArray.alerts.length; i++) {\n if (alertArray.alerts[i].id === env.get('id')){\n searchIndex = i;\n break;\n }\n }\n }\n if (searchIndex !== -1) {\n alertArray.alerts[searchIndex] = msg;\n } else {\n alertArray.alerts.push(msg);\n }\n}\nglobal.set(\"alertArray\", alertArray);\n\nmsg = alertArray;\nreturn msg;", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 490, | |
"y": 200, | |
"wires": [ | |
[] | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment