Simplify messaging flows with function nodes

This commit is contained in:
2023-03-27 21:06:16 -04:00
parent fa85a9e62a
commit 52ffbb42ba

View File

@ -685,9 +685,7 @@
"37f1c11c59a6ce16"
],
"x": 94,
"y": 339,
"w": 1872,
"h": 622
"y": 339
},
{
"id": "39a7ac02f2727f1d",
@ -734,7 +732,9 @@
"1c98de289e42377f"
],
"x": 14,
"y": 719
"y": 719,
"w": 1292,
"h": 642
},
{
"id": "e065b1ed4938b477",
@ -806,7 +806,9 @@
"a3ef2faca9922113"
],
"x": 14,
"y": 19
"y": 19,
"w": 2112,
"h": 682
},
{
"id": "5c50443a84910fb7",
@ -846,18 +848,16 @@
},
"nodes": [
"a4c477269b22f766",
"155b26ba197473e4",
"3153371fe2de6f8e",
"9cafa6212280b2d5",
"5095d45c90d5304f",
"3ae21589dd88c080",
"93b7bee28a7e896e",
"91c224b7d6f0d32e",
"b2bc83c9195efe0f"
"b2bc83c9195efe0f",
"f4bfbaca4d7fb1df"
],
"x": 14,
"y": 39,
"w": 872,
"w": 792,
"h": 142
},
{
@ -870,8 +870,6 @@
},
"nodes": [
"f803c6af3a30eb66",
"c3dc3b15f1261b9f",
"3c0e9baa492b618a",
"3bd7704103dbfc20",
"a6234b2047ba3116",
"788eb0a1551db9b8",
@ -880,9 +878,9 @@
"3c03edd9c35f85f8"
],
"x": 14,
"y": 219,
"w": 1012,
"h": 202
"y": 199,
"w": 712,
"h": 142
},
{
"id": "fbbe69a14cbe0236",
@ -930,7 +928,9 @@
"febc179b34c8cf71"
],
"x": 34,
"y": 39
"y": 39,
"w": 692,
"h": 682
},
{
"id": "46275dd0f9461013",
@ -948,7 +948,9 @@
"ca88f85ba00a6744"
],
"x": 34,
"y": 739
"y": 739,
"w": 472,
"h": 202
},
{
"id": "ff6d8150e8d5e606",
@ -1108,26 +1110,18 @@
"nodes": [
"98626a8f2b59bde3",
"47bc783fd78f5aa8",
"95652a59518e2767",
"3d5448e57ef666a0",
"5de6d772e1ecdd22",
"c684d82a2abea389",
"ba18895fef9810bd",
"20666f8c1488d423",
"db6d955c039873be",
"e3ef7fe6bcad3b74",
"d2fec32d385dae8c",
"0145961e8276c53e",
"fd623c46a558a01a",
"926fc60ea00ddfb0",
"c52cae79eb97bcc0",
"b2d2662449cd647d",
"6b039ef7895476e2"
"6b039ef7895476e2",
"f44427c5a493c428"
],
"x": 14,
"y": 499,
"w": 1252,
"h": 362
"y": 359,
"w": 1012,
"h": 222
},
{
"id": "eeafd13be593ae69",
@ -1197,9 +1191,7 @@
"37bdac2c9a4e2837"
],
"x": 54,
"y": 39,
"w": 1652,
"h": 382
"y": 39
},
{
"id": "8aee4d340a136bac",
@ -1219,9 +1211,7 @@
"b281061a4b08d2eb"
],
"x": 14,
"y": 539,
"w": 612,
"h": 202
"y": 539
},
{
"id": "550e5b2d99316b12",
@ -1362,7 +1352,9 @@
"51d05298561cfddb"
],
"x": 754,
"y": 39
"y": 39,
"w": 672,
"h": 262
},
{
"id": "b708cb6d93f40dee",
@ -1378,9 +1370,7 @@
"e59180a1a6ae0a90"
],
"x": 1094,
"y": 839,
"w": 632,
"h": 82
"y": 839
},
{
"id": "a705cecb0997a43a",
@ -23163,85 +23153,7 @@
"y": 80,
"wires": [
[
"155b26ba197473e4"
]
]
},
{
"id": "155b26ba197473e4",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "477e752fcd2e2a19",
"name": "Message",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_text.tts_message",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 280,
"y": 80,
"wires": [
[
"3153371fe2de6f8e"
]
]
},
{
"id": "3153371fe2de6f8e",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "477e752fcd2e2a19",
"name": "Destination",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.tts_devices",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 450,
"y": 80,
"wires": [
[
"91c224b7d6f0d32e"
"f4bfbaca4d7fb1df"
]
]
},
@ -23349,51 +23261,12 @@
"z": "ee67610b4a0578d2",
"g": "477e752fcd2e2a19",
"name": "",
"x": 780,
"x": 500,
"y": 80,
"wires": [
[]
]
},
{
"id": "91c224b7d6f0d32e",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "477e752fcd2e2a19",
"name": "Voice",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.announcement_voice",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "voice",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 610,
"y": 80,
"wires": [
[
"93b7bee28a7e896e"
]
]
},
{
"id": "b2bc83c9195efe0f",
"type": "api-call-service",
@ -23434,85 +23307,7 @@
"entityConfig": "675dd216a61c575b",
"outputProperties": [],
"x": 110,
"y": 260,
"wires": [
[
"c3dc3b15f1261b9f"
]
]
},
{
"id": "c3dc3b15f1261b9f",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "50e4d951ee7b3e54",
"name": "Get Text",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_text.report_system",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "text",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 280,
"y": 260,
"wires": [
[
"3c0e9baa492b618a"
]
]
},
{
"id": "3c0e9baa492b618a",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "50e4d951ee7b3e54",
"name": "Get Type",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.report_type",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "type",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 440,
"y": 260,
"y": 240,
"wires": [
[
"a6234b2047ba3116"
@ -23531,8 +23326,8 @@
"syntax": "mustache",
"template": "{\n \"content\": \"{{text}}\",\n \"project_id\": 2285967948,\n \"section_id\": {{type}}\n}",
"output": "str",
"x": 760,
"y": 260,
"x": 460,
"y": 240,
"wires": [
[]
]
@ -23542,15 +23337,15 @@
"type": "function",
"z": "ee67610b4a0578d2",
"g": "50e4d951ee7b3e54",
"name": "",
"func": "if (msg.type === \"New Idea\") {\n msg.type = \"81234669\"\n} else if (msg.type === \"Bug Report\") {\n msg.type = \"94865633\"\n}\nreturn msg;",
"name": "Processing",
"func": "var states = global.get('homeassistant.homeAssistant.states')\nvar text = states['input_text.report_system'].state\nvar type = states['input_select.report_type'].state\n\nmsg.text = text\n\nif (type === \"New Idea\") {\n msg.type = \"81234669\"\n} else if (type === \"Bug Report\") {\n msg.type = \"94865633\"\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 260,
"x": 290,
"y": 240,
"wires": [
[
"3bd7704103dbfc20"
@ -23582,11 +23377,10 @@
}
],
"x": 110,
"y": 320,
"y": 300,
"wires": [
[
"7674185d1e5ee489",
"427cc2991454bbf0"
"7674185d1e5ee489"
]
]
},
@ -23613,9 +23407,11 @@
"outputProperties": [],
"queue": "none",
"x": 290,
"y": 320,
"y": 300,
"wires": [
[]
[
"427cc2991454bbf0"
]
]
},
{
@ -23640,8 +23436,8 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 290,
"y": 380,
"x": 470,
"y": 300,
"wires": [
[]
]
@ -23677,10 +23473,10 @@
}
],
"x": 120,
"y": 580,
"y": 440,
"wires": [
[
"e3ef7fe6bcad3b74"
"f44427c5a493c428"
]
]
},
@ -23715,204 +23511,10 @@
}
],
"x": 140,
"y": 640,
"wires": [
[
"d2fec32d385dae8c",
"0145961e8276c53e",
"fd623c46a558a01a",
"6b039ef7895476e2"
]
]
},
{
"id": "95652a59518e2767",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Message",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_text.text_notification",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 440,
"y": 580,
"wires": [
[
"b2d2662449cd647d"
]
]
},
{
"id": "3d5448e57ef666a0",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Phones",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.select_phones",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "phones",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 760,
"y": 540,
"wires": [
[
"c684d82a2abea389"
]
]
},
{
"id": "5de6d772e1ecdd22",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "TVs",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.select_tvs",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "tvs",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 750,
"y": 620,
"wires": [
[
"ba18895fef9810bd"
]
]
},
{
"id": "c684d82a2abea389",
"type": "switch",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "",
"property": "phones",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "None",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 875,
"y": 540,
"wires": [
[
"20666f8c1488d423"
]
],
"l": false
},
{
"id": "ba18895fef9810bd",
"type": "switch",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "",
"property": "tvs",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "None",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 875,
"y": 620,
"wires": [
[
"926fc60ea00ddfb0"
]
],
"l": false
},
{
"id": "20666f8c1488d423",
"type": "function",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Formatting",
"func": "var phones = msg.phones.toLowerCase()\n\nmsg.phones = phones\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 990,
"y": 540,
"wires": [
[
"db6d955c039873be"
"d2fec32d385dae8c"
]
]
},
@ -23936,51 +23538,12 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1170,
"y": 540,
"x": 490,
"y": 400,
"wires": [
[]
]
},
{
"id": "e3ef7fe6bcad3b74",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Title",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_text.text_notification_title",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "title",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 290,
"y": 580,
"wires": [
[
"95652a59518e2767"
]
]
},
{
"id": "d2fec32d385dae8c",
"type": "api-call-service",
@ -24004,9 +23567,11 @@
"outputProperties": [],
"queue": "none",
"x": 350,
"y": 640,
"y": 540,
"wires": [
[]
[
"0145961e8276c53e"
]
]
},
{
@ -24031,10 +23596,12 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 350,
"y": 700,
"x": 530,
"y": 540,
"wires": [
[]
[
"fd623c46a558a01a"
]
]
},
{
@ -24060,29 +23627,11 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 360,
"y": 760,
"wires": [
[]
]
},
{
"id": "926fc60ea00ddfb0",
"type": "function",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Formatting",
"func": "const str = msg.tvs\nvar tvs = str.replaceAll(\" \", \"_\")\nvar tvLower = tvs.toLowerCase()\n\nmsg.tvs = tvLower\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 990,
"y": 620,
"x": 720,
"y": 540,
"wires": [
[
"c52cae79eb97bcc0"
"6b039ef7895476e2"
]
]
},
@ -24106,52 +23655,12 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1160,
"y": 620,
"x": 480,
"y": 480,
"wires": [
[]
]
},
{
"id": "b2d2662449cd647d",
"type": "api-current-state",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Priority",
"server": "9e87348d.9c1c48",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_select.text_notification_priority_level",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "priority",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 600,
"y": 580,
"wires": [
[
"3d5448e57ef666a0",
"5de6d772e1ecdd22"
]
]
},
{
"id": "6b039ef7895476e2",
"type": "api-call-service",
@ -24174,8 +23683,8 @@
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 360,
"y": 820,
"x": 920,
"y": 540,
"wires": [
[]
]
@ -24187,10 +23696,53 @@
"g": "50e4d951ee7b3e54",
"name": "Create Task",
"info": "",
"x": 930,
"y": 260,
"x": 630,
"y": 240,
"wires": []
},
{
"id": "f4bfbaca4d7fb1df",
"type": "function",
"z": "ee67610b4a0578d2",
"g": "477e752fcd2e2a19",
"name": "Processing",
"func": "var states = global.get('homeassistant.homeAssistant.states')\nvar message = states['input_text.tts_message'].state\nvar who = states['input_select.tts_devices'].state\nvar voice = states['input_select.announcement_voice'].state\n\nmsg.payload = message\nmsg.topic = who\nmsg.voice = voice\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 290,
"y": 80,
"wires": [
[
"93b7bee28a7e896e"
]
]
},
{
"id": "f44427c5a493c428",
"type": "function",
"z": "ee67610b4a0578d2",
"g": "5595964c8367c984",
"name": "Processing",
"func": "var states = global.get('homeassistant.homeAssistant.states')\nvar title = states['input_text.text_notification_title'].state\nvar message = states['input_text.text_notification'].state\nvar priority = states['input_select.text_notification_priority_level'].state\nvar phones = states['input_select.select_phones'].state.toLowerCase()\nvar tvs = states['input_select.select_tvs'].state.toLowerCase()\n\nvar phoneMsg = {\n \"title\": title,\n \"payload\": message,\n \"priority\": priority,\n \"phones\": phones\n}\nvar tvsMsg = {\n \"title\": title,\n \"payload\": message,\n \"priority\": priority,\n \"tvs\": tvs\n}\n\nif (phones != 'none' && tvs != 'none') {\n return[phoneMsg,tvsMsg]\n} else if (phones === 'none' && tvs != 'none') {\n return[null,tvsMsg]\n} else if (phones != 'none' && tvs === 'none') {\n return[phoneMsg,null]\n} else {\n return null\n}",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 310,
"y": 440,
"wires": [
[
"db6d955c039873be"
],
[
"c52cae79eb97bcc0"
]
]
},
{
"id": "5d7c63526234945e",
"type": "api-render-template",