Hier für die Node Red User eine Funktion zum ersetzen von Geräten in homeegrammen.
[
{
"id": "76e0d02a.6b828",
"type": "inject",
"z": "2fafa37e.5aa2cc",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "get:homeegrams",
"payloadType": "str",
"x": 260,
"y": 780,
"wires": [
[
"b4a088b.49bff78"
]
]
},
{
"id": "38807a9c.1d3116",
"type": "function",
"z": "2fafa37e.5aa2cc",
"name": "Attribute und Node ID ersetzen bei Trigger , Conditions und Actions",
"func": "var nodeold = 1226;\nvar attributold = 3137;\n\nvar nodenew = 92;\nvar attributnew = 348\n\nif (Object.keys(msg.payload)[0] === \"homeegrams\"){\nvar hg = msg.payload.homeegrams;\nhg.forEach(function(hgs){\n hgs.triggers.attribute_triggers.forEach(function(trigger){\n if (trigger.node_id == nodeold && trigger.attribute_id == attributold){\n \n node.send({payload: \"PUT:homeegrams/\"+trigger.homeegram_id+\"/triggers/\"+trigger.id+\"?attribute_id=\"+attributnew});\n \n node.send({payload: \"PUT:homeegrams/\"+trigger.homeegram_id+\"/triggers/\"+trigger.id+\"?node_id=\"+nodenew})}\n })\n hgs.actions.attribute_actions.forEach(function(action){\n if (action.node_id == nodeold && action.attribute_id == attributold){\n \n node.send({payload: \"PUT:homeegrams/\"+action.homeegram_id+\"/actions/\"+action.id+\"?node_id=\"+nodenew+\"&attribute_id=\"+attributnew})}\n })\n hgs.conditions.attribute_conditions.forEach(function(conditions){\n if (conditions.node_id == nodeold && conditions.attribute_id == attributold){\n \n node.send({payload: \"PUT:homeegrams/\"+conditions.homeegram_id+\"/conditions/\"+conditions.id+\"?node_id=\"+nodenew+\"&attribute_id=\"+attributnew})}\n })\n})\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 580,
"y": 700,
"wires": [
[
"b4a088b.49bff78",
"7b910a91.3b31b4"
]
]
},
{
"id": "b4a088b.49bff78",
"type": "homeeApi",
"z": "2fafa37e.5aa2cc",
"homee": "",
"name": "homeeApi",
"messageTypeFilter": [],
"nodeFilter": null,
"attributeFilter": null,
"x": 540,
"y": 780,
"wires": [
[
"38807a9c.1d3116"
]
]
},
{
"id": "7b910a91.3b31b4",
"type": "debug",
"z": "2fafa37e.5aa2cc",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 780,
"wires": []
}
]
In der Funktion müsst Ihr die alte und neue Node_ID sowie Attribut_ID eingegeben werden.
Danach ein Get:homeegrams an die Api senden und die funktion ersetzt in alle HG’s die ID’s.
Viel Spaß und Erfolg