Created
August 17, 2021 00:59
-
-
Save sstratoti/76347e688737f435c1efa3ece3b5edd4 to your computer and use it in GitHub Desktop.
HA Active Alert Update Flow
This file contains hidden or 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": "90e68c3c3bca25ff", | |
"type": "ha-entity", | |
"z": "eff29b39482d7ed4", | |
"name": "Active Alert", | |
"server": "74f36281.ae094c", | |
"version": 1, | |
"debugenabled": false, | |
"outputs": 1, | |
"entityType": "sensor", | |
"config": [ | |
{ | |
"property": "name", | |
"value": "Active Alerts" | |
}, | |
{ | |
"property": "device_class", | |
"value": "" | |
}, | |
{ | |
"property": "icon", | |
"value": "" | |
}, | |
{ | |
"property": "unit_of_measurement", | |
"value": "" | |
} | |
], | |
"state": "payload", | |
"stateType": "msg", | |
"attributes": [ | |
{ | |
"property": "name", | |
"value": "name", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "label", | |
"value": "label", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "backgroundColor", | |
"value": "backgroundColor", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "icon", | |
"value": "icon", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "id", | |
"value": "id", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "textColor", | |
"value": "textColor", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "alertCount", | |
"value": "alertCount", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "animation", | |
"value": "animation", | |
"valueType": "msg" | |
}, | |
{ | |
"property": "entity", | |
"value": "entity", | |
"valueType": "msg" | |
} | |
], | |
"resend": true, | |
"outputLocation": "", | |
"outputLocationType": "none", | |
"inputOverride": "allow", | |
"outputOnStateChange": false, | |
"outputPayload": "$entity().state ? \"on\": \"off\"", | |
"outputPayloadType": "jsonata", | |
"x": 1990, | |
"y": 280, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "8bc0952c69e7f0c1", | |
"type": "function", | |
"z": "eff29b39482d7ed4", | |
"name": "clear global var", | |
"func": "global.set('alertArray', undefined);\nnode.warn('variable cleared.');", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 1540, | |
"y": 400, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "316b9dd4b8ce97f9", | |
"type": "inject", | |
"z": "eff29b39482d7ed4", | |
"name": "", | |
"props": [ | |
{"p": "payload"}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "", | |
"crontab": "", | |
"once": false, | |
"onceDelay": 0.1, | |
"topic": "", | |
"payload": "", | |
"payloadType": "date", | |
"x": 1340, | |
"y": 400, | |
"wires": [ | |
["8bc0952c69e7f0c1"] | |
] | |
}, | |
{ | |
"id": "2899f133dd8775a4", | |
"type": "inject", | |
"z": "eff29b39482d7ed4", | |
"name": "", | |
"props": [ | |
{"p": "payload"}, | |
{ | |
"p": "topic", | |
"vt": "str" | |
} | |
], | |
"repeat": "5", | |
"crontab": "", | |
"once": true, | |
"onceDelay": "3", | |
"topic": "", | |
"payloadType": "date", | |
"x": 1050, | |
"y": 300, | |
"wires": [ | |
["9982fa6a24e8bdc4"] | |
] | |
}, | |
{ | |
"id": "a159cbdada55e952", | |
"type": "function", | |
"z": "eff29b39482d7ed4", | |
"name": "No Alert Active? Check queue and send one if found.", | |
"func": "var alertArray = global.get('alertArray') || {\"alerts\":[]};\nmsg = {};\n \nif (alertArray.alerts.length > 0){\n // an alert is active, but not set. Get the first one and send it in.\n msg = alertArray.alerts[0];\n if (alertArray.alerts.length === 1) {\n msg.alertCount = \"1\";\n } else {\n msg.alertCount = alertArray.alerts.length;\n }\n msg.animation = 'none';\n return msg;\n} else {\n return null; //stop further execution of flow. No need to set payload to off if it's already off.\n}\n", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 1660, | |
"y": 320, | |
"wires": [ | |
["90e68c3c3bca25ff"] | |
] | |
}, | |
{ | |
"id": "9982fa6a24e8bdc4", | |
"type": "api-current-state", | |
"z": "eff29b39482d7ed4", | |
"name": "Get Current Alert", | |
"server": "74f36281.ae094c", | |
"version": 2, | |
"outputs": 2, | |
"halt_if": "on", | |
"halt_if_type": "str", | |
"halt_if_compare": "is", | |
"entity_id": "sensor.active_alerts", | |
"state_type": "str", | |
"blockInputOverrides": false, | |
"outputProperties": [ | |
{ | |
"property": "payload", | |
"propertyType": "msg", | |
"value": "", | |
"valueType": "entityState" | |
}, | |
{ | |
"property": "activeAlert", | |
"propertyType": "msg", | |
"value": "", | |
"valueType": "entity" | |
} | |
], | |
"override_topic": false, | |
"state_location": "payload", | |
"override_payload": "msg", | |
"entity_location": "data", | |
"override_data": "msg", | |
"x": 1310, | |
"y": 300, | |
"wires": [ | |
["765a6d3b84bbe72b"], | |
["a159cbdada55e952"] | |
] | |
}, | |
{ | |
"id": "765a6d3b84bbe72b", | |
"type": "function", | |
"z": "eff29b39482d7ed4", | |
"name": "Alert Active! Check queue and send next one.", | |
"func": "var alertArray = global.get('alertArray') || {\"alerts\":[]};\n\n// find current message.\nvar currSearchIndex = -1\n\nif (alertArray.alerts.length > 0){\n for (i=0; i < alertArray.alerts.length; i++) {\n if (alertArray.alerts[i].id === msg.activeAlert.attributes.id){\n currSearchIndex = i;\n break;\n }\n }\n if (currSearchIndex != -1) {\n previousMsg = alertArray.alerts[currSearchIndex];\n if (previousMsg.animation == 'none' || previousMsg.animation == '') {\n previousMsg.animation = 'blink 3s ease infinite';\n return previousMsg;\n } else {\n previousMsg.animation = 'none';\n //continue below...\n }\n }\n}\n\n\n\nif (alertArray.alerts.length > 1){\n // more than one alert is active\n var searchIndex = -1;\n var thisAlertNumber = 1;\n for (i=0; i < alertArray.alerts.length; i++) {\n if (alertArray.alerts[i].id === msg.activeAlert.attributes.id){\n searchIndex = i;\n break;\n }\n }\n // look for the next message. \n if (searchIndex === -1) {\n // message must have been cleared from global. Start at beginning of loop.\n msg = alertArray.alerts[0];\n } else if (searchIndex >= 0) {\n if (searchIndex+2 > alertArray.alerts.length){\n // At the end of the array, loop back to first message.\n msg = alertArray.alerts[0]; \n } else {\n \n msg = alertArray.alerts[searchIndex+1]; \n thisAlertNumber = searchIndex+2;\n }\n }\n // set total alert count\n msg.alertCount = alertArray.alerts.length;\n return msg;\n} else if (alertArray.alerts.length === 1){\n if (alertArray.alerts[0].id === msg.activeAlert.attributes.id){\n if (msg.activeAlert.attributes.alertcount !== '1'){\n msg = alertArray.alerts[0];\n msg.alertCount = 1;\n return msg; \n } else {\n return null; //no need to update or continue in flow.\n }\n\n } else {\n // alerts dont match. Reset to remaining alert.\n msg.alertCount = 1;\n msg = alertArray.alerts[0];\n return msg;\n }\n} else {\n msg = {};\n msg.payload = 'off';\n return msg;\n}\n\n", | |
"outputs": 1, | |
"noerr": 0, | |
"initialize": "", | |
"finalize": "", | |
"libs": [], | |
"x": 1640, | |
"y": 260, | |
"wires": [ | |
["90e68c3c3bca25ff"] | |
] | |
}, | |
{ | |
"id": "51316047608fbcb6", | |
"type": "server-state-changed", | |
"z": "eff29b39482d7ed4", | |
"name": "Trigger Update?", | |
"server": "74f36281.ae094c", | |
"version": 3, | |
"exposeToHomeAssistant": false, | |
"haConfig": [ | |
{ | |
"property": "name", | |
"value": "" | |
}, | |
{ | |
"property": "icon", | |
"value": "" | |
} | |
], | |
"entityidfilter": "input_boolean.trigger_alert_update", | |
"entityidfiltertype": "exact", | |
"outputinitially": true, | |
"state_type": "str", | |
"haltifstate": "on", | |
"halt_if_type": "str", | |
"halt_if_compare": "is", | |
"outputs": 2, | |
"output_only_on_state_change": true, | |
"for": "1", | |
"forType": "num", | |
"forUnits": "seconds", | |
"ignorePrevStateNull": true, | |
"ignorePrevStateUnknown": false, | |
"ignorePrevStateUnavailable": false, | |
"ignoreCurrentStateUnknown": false, | |
"ignoreCurrentStateUnavailable": false, | |
"outputProperties": [], | |
"x": 1140, | |
"y": 140, | |
"wires": [ | |
[ | |
"9d4755144fcde940", | |
"4ace29780628a374" | |
], | |
[] | |
] | |
}, | |
{ | |
"id": "9d4755144fcde940", | |
"type": "delay", | |
"z": "eff29b39482d7ed4", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "1", | |
"timeoutUnits": "seconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"allowrate": false, | |
"x": 1330, | |
"y": 120, | |
"wires": [ | |
["a3055f698d963fce"] | |
] | |
}, | |
{ | |
"id": "a3055f698d963fce", | |
"type": "api-call-service", | |
"z": "eff29b39482d7ed4", | |
"name": "Turn off Trigger", | |
"server": "74f36281.ae094c", | |
"version": 3, | |
"debugenabled": false, | |
"service_domain": "homeassistant", | |
"service": "turn_off", | |
"entityId": "input_boolean.trigger_alert_update", | |
"data": "", | |
"dataType": "jsonata", | |
"mergecontext": "", | |
"mustacheAltTags": false, | |
"outputProperties": [], | |
"queue": "none", | |
"x": 1520, | |
"y": 100, | |
"wires": [ | |
[] | |
] | |
}, | |
{ | |
"id": "4ace29780628a374", | |
"type": "delay", | |
"z": "eff29b39482d7ed4", | |
"name": "", | |
"pauseType": "delay", | |
"timeout": "500", | |
"timeoutUnits": "milliseconds", | |
"rate": "1", | |
"nbRateUnits": "1", | |
"rateUnits": "second", | |
"randomFirst": "1", | |
"randomLast": "5", | |
"randomUnits": "seconds", | |
"drop": false, | |
"allowrate": false, | |
"x": 1330, | |
"y": 200, | |
"wires": [ | |
["9982fa6a24e8bdc4"] | |
] | |
}, | |
{ | |
"id": "74f36281.ae094c", | |
"type": "server", | |
"name": "Home Assistant", | |
"version": 1, | |
"legacy": false, | |
"addon": false, | |
"rejectUnauthorizedCerts": true, | |
"ha_boolean": "y|yes|true|on|home|open", | |
"connectionDelay": true, | |
"cacheJson": true | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment