Hallo zusammen,
habe mich mal dran gemacht eine Funktion zusammen zu schreiben um die HG’s als Klartext zu exportieren.
Benötigt wird das HomeeApi Node dafür mit eingestellten Globalen Variablen.
Hier ist der Code zum Importieren.
[
{
"id": "48503768.be4538",
"type": "function",
"z": "3ec260ca.c6f27",
"name": "Fuctionsaufbau mit Rückgabe",
"func": "// Variablen\nconst nodes = global.get(\"homee.nodes\");\nconst homeegrams = global.get(\"homee.homeegrams\");\nconst attributes = global.get(\"homee.attributes\");\nconst groups = global.get(\"homee.groups\");\nvar z=\"\";\n\n// Ausgaben\nconst f_node = x => nodes.find(no => no.id === x);\nconst f_hg = x => homeegrams.find(hg => hg.id === x);\nconst f_attribut = x => attributes.find(at => at.id === x);\nconst f_group = x => groups.find(no => no.id === x);\nconst trigger_hg_event = x => {\n switch (x) {\n case 0: return \"none\";\n case 1: return \"aktiviert\";\n case 2: return \"deaktiviert\";\n case 3: return \"abgespielt\";\n case 4: return \"gestoppt\";\n default: return '';\n }\n};\nconst trigger_operator = x => {\n switch (x) {\n case 0: return \"none\";\n case 1: return \"steigt über\";\n case 2: return \"fällt unter\";\n case 3: return \"wechselt zu\";\n case 4: return \"ändert sich um\";\n default: return '';\n }\n};\nconst h_value = (x, y) => {\n const attributeType = f_attribut(x).type;\n if (attributeType === 1 ) {\n return y === 1 ? \"eingeschaltet\" : \"ausgeschaltet\";\n } else if (attributeType === 25) {\n return y === 1 ? \"meldet Bewegung\" : \"keine Bewegung\";\n } else if (attributeType === 10 || attributeType === 14) {\n switch (y) {\n case 0: return \"geschlossen\";\n case 1: return \"geöffnet\";\n case 2: return \"gekippt\";}\n } else if (attributeType === 205 ) {\n switch (y) {\n case 0: return \"Anwesend\";\n case 1: return \"Schlafend\";\n case 2: return \"Abwesend\";\n case 3: return \"Urlaub\";\n }\n } \n else if (attributeType === 40 ) {\n switch (y) {\n case 0: return \"ausgeschaltet\";\n case 1: return \"eingeschaltet\";\n case 2: return \"losgelassen\";}\n }\n else if (attributeType === 16 ) {\n return y === 1 ? \"meldet Rauch\" : \"meldet keinen Rauch\";\n }\n else if (attributeType === 76 ) {\n return y === 1 ? \"meldet Anwesenheit\" : \"meldet keinen Anwesenheit\";\n }\n else if (attributeType === 135 ) {\n switch (y) {\n case 0: return \"geöffnet\";\n case 1: return \"geschlossen\";\n case 2: return \"gestoppt\";\n }\n } \n else {\n return y;\n }\n};\nconst check_moment = x => {\n switch (x) {\n case 0: return \"none\";\n case 1: return \"beim Auslösen\";\n case 2: return \"beim ausführen der Aktion\";\n case 3: return \"beim Auslösen und ausführen der Aktion\";\n default: return '';\n }\n};\nconst conditions_operator = x => {\n switch (x) {\n case 0: return \"none\";\n case 1: return \"ist gleich\";\n case 2: return \"ist kleiner gleich\";\n case 3: return \"ist größer gleich\";\n case 4: return \"ist kleiner als\";\n case 5: return \"ist größer als\";\n case 6: return \"ist nicht gleich\";\n default: return '';\n }\n};\nconst conditions_hg_event = x => {\n switch (x) {\n case 0: return \"none\";\n case 1: return \"ist aktiviert\";\n case 2: return \"ist deaktiviert\";\n case 3: return \"läuft gerade\";\n case 4: return \"läuft gerade nicht\";\n default: return '';\n }\n};\nconst t_value = (x, y) => {\n const attributeType = x;\n if (attributeType === 1 ) {\n return y === 1 ? \"eingeschaltet\" : \"ausgeschaltet\";\n } else if (attributeType === 25) {\n return y === 1 ? \"meldet Bewegung\" : \"keine Bewegung\";\n } else if (attributeType === 10 || attributeType === 14) {\n switch (y) {\n case 0: return \"geschlossen\";\n case 1: return \"geöffnet\";\n case 2: return \"gekippt\";}\n } else if (attributeType === 205 ) {\n switch (y) {\n case 0: return \"Anwesend\";\n case 1: return \"Schlafend\";\n case 2: return \"Abwesend\";\n case 3: return \"Urlaub\";\n }\n } \n else if (attributeType === 40 ) {\n switch (y) {\n case 0: return \"ausgeschaltet\";\n case 1: return \"eingeschaltet\";\n case 2: return \"losgelassen\";}\n }\n else if (attributeType === 16 ) {\n return y === 1 ? \"meldet Rauch\" : \"meldet keinen Rauch\";\n }\n else if (attributeType === 76 ) {\n return y === 1 ? \"meldet Anwesenheit\" : \"meldet keinen Anwesenheit\";\n }\n else if (attributeType === 135 ) {\n switch (y) {\n case 0: return \"geöffnet\";\n case 1: return \"geschlossen\";\n case 2: return \"gestoppt\";\n }\n } \n else {\n return y;\n }\n};\nconst command = (x)=>{\n switch (x) {\n case 0: return \"none\";\n case 1: return \"wird auf Wert gesetzt\";\n case 2: return \"Wert wird übernommen\";\n case 3: return \"wird umgeschaltet\";\n}}\n\n//node.send({payload:f_hg(753)})\n\nhomeegrams.forEach(function(a){\n //z=\"\";\n // if (a.id === 753){\n z += `Homeegramm Name : ${decodeURIComponent(a.name)} (${a.id});\\n\\n`;\n z +=`Auslöser:\\n\\n`;\n a.triggers.switch_triggers.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z +=\"Abspielbutton : true ;\\n\\n\"; \n }\n })\n a.triggers.time_triggers.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Zeitauslöser: ${b.dtstart.slice(9,11)}:${b.dtstart.slice(11,13)}:${b.dtstart.slice(13,15)};\\n`;\n z += `Wiederholung: ${b.rrule};\\n\\n`;\n }\n })\n a.triggers.attribute_triggers.forEach(function(b){\n if (b.homeegram_id === a.id ){\n if (decodeURIComponent(f_attribut(b.attribute_id).unit) === \"n/a\"){\n var d = \"\";\n }\n else \n \n d =decodeURIComponent(f_attribut(b.attribute_id).unit);\n z += `${decodeURIComponent(f_node(b.node_id).name)} ${f_attribut(b.attribute_id).instance === 0 ? \"\": `(Instance ${(f_attribut(b.attribute_id).instance)+1})`}${ decodeURIComponent(f_attribut(b.attribute_id).name)} ${trigger_operator(b.operator)} ${h_value(b.attribute_id,b.value)}${d};\\n\\n`;\n }\n })\n a.triggers.webhook_triggers.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Webhook key: ${b.event};\\n\\n`;\n }\n })\n a.triggers.homeegram_triggers.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Homeegramm: ${decodeURIComponent(f_hg(b.source_homeegram_id).name)} wird ${trigger_hg_event(b.homeegram_event)};\\n\\n`;\n \n }\n })\n z +=\"\\nBedingungen:\\n\\n\";\n a.conditions.time_conditions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Uhrzeit von: ${b.dtstart.slice(9,11)}:${b.dtstart.slice(11,13)}:${b.dtstart.slice(13,15)};\\nDauer: ${b.duration.slice(2,-1)} Sekunden;\\nPrüfmoment: ${decodeURIComponent(check_moment(b.check_moment))};\\n\\n`;\n \n }\n })\n a.conditions.attribute_conditions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n if (decodeURIComponent(f_attribut(b.attribute_id).unit) === \"n/a\"){\n var d = \"\";\n }\n else \n \n d =decodeURIComponent(f_attribut(b.attribute_id).unit);\n z += `${decodeURIComponent(f_node(b.node_id).name)} ${f_attribut(b.attribute_id).instance === 0 ? \"\": `(Instance ${(f_attribut(b.attribute_id).instance)+1})`}${conditions_operator(b.operator)} ${h_value(b.attribute_id,b.value)}${d};\\nPrüfmoment: ${decodeURIComponent(check_moment(b.check_moment))};\\n\\n`;\n }\n })\n a.conditions.homeegram_conditions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Homeegramm: ${decodeURIComponent(f_hg(b.source_homeegram_id).name)} ${conditions_hg_event(b.homeegram_event)};\\n\\n`;\n \n }\n })\n z += `Aktion\\n\\n`;\n a.actions.attribute_actions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n if (decodeURIComponent(f_attribut(b.attribute_id).unit) === \"n/a\"){\n var d = \"\";\n }\n else \n \n d =decodeURIComponent(f_attribut(b.attribute_id).unit);\n z += `${decodeURIComponent(f_node(b.node_id).name)} ${f_attribut(b.attribute_id).instance === 0 ? \"\": `(Instance ${(f_attribut(b.attribute_id).instance)+1})`} wird auf ${h_value(b.attribute_id,b.value)} gesetzt;\\nDelay: ${b.delay};\\n\\n`;\n }\n })\n a.actions.notification_actions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z+=`Push Nachricht\\n`\n b.user_ids.forEach(function(c){\n z+= `an User ID: ${c}\\n`\n })\n z += `Kritisch: ${b.critical}\\nNachricht: ${b.message}\\nDelay: ${b.delay};\\n\\n`;\n }})\n a.actions.webhook_actions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Webhook\\nURL: ${b.url}\\nBody: ${b.body}\\nMethode: ${b.method}\\nContentType: ${b.content_type}\\nDelay: ${b.delay};\\n\\n`;\n }})\n a.actions.homeegram_actions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Homeegramm: ${decodeURIComponent(f_hg(b.target_homeegram_id).name)} wird ${trigger_hg_event(b.homeegram_event)};\\n\\n`;\n \n }\n })\n a.actions.group_actions.forEach(function(b){\n if (b.homeegram_id === a.id ){\n z += `Gruppe: ${decodeURIComponent(f_group(b.group_id).name)} ${command(b.command)} ${b.command === 3 ? \"\":t_value(b.attribute_type,b.value)} ;\\nDelay: ${b.delay};\\n\\n`;\n \n }\n })\n \n z +=\"\\n--------------------------------------------------------------------------------------------------------------------------------\\n\";\n//node.send({payload:z})\n //}\n})\n\n\n\nnode.send({payload:z})\n\n\n\nfunction trigger_operand(x,y){\n if (x === 1){ x = y = 1 ? true : false}\n else if ( x ===2 ){ x=y}\n return x;\n}\n\n\nfunction nodefe_id(x) {\n var y = [];\n nodes.forEach(function(no){if (no.protocol === x ){ \n \n y.push(no) }})\n return y\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 80,
"wires": [
[
"79df86da.c9c3a8",
"3ad4983a.a11968"
]
]
},
{
"id": "13bb40bb.aba697",
"type": "inject",
"z": "3ec260ca.c6f27",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 100,
"wires": [
[
"48503768.be4538"
]
]
},
{
"id": "79df86da.c9c3a8",
"type": "debug",
"z": "3ec260ca.c6f27",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 570,
"y": 100,
"wires": []
},
{
"id": "3ad4983a.a11968",
"type": "file",
"z": "3ec260ca.c6f27",
"name": "",
"filename": "/var/www//html/test.txt",
"appendNewline": true,
"createDir": false,
"overwriteFile": "true",
"encoding": "macintosh",
"x": 580,
"y": 220,
"wires": [
[]
]
}
]
Ist noch nicht komplett aber auf einen guten Weg.
Viel Spaß beim testen und probieren.