[{"id":"be5380fd.68d8d8","type":"tab","allowCycles":false,"label":"Skill Set Failures","disabled":false,"info":""},{"id":"7a8510ff.e4a7a","type":"comment","z":"be5380fd.68d8d8","name":"Skill MyNewSkill","info":"Please complete the workflow by adding the necessary processing nodes between the trigger node and response node. Once all required nodes are properly connected and configured, save the entire flow.","sticky":2,"x":540,"y":200,"wires":[]},{"id":"1b10a95b.790ad7","type":"comment","z":"be5380fd.68d8d8","name":"Authorization as Request Header","info":"Each request (like Get KPIs) needs to \nhave a Authorization Header with the Bearer Token.\nMessage property for http requests to set Headers\nmust be msg.headers\n","sticky":1,"x":1340,"y":300,"wires":[]},{"id":"94f92807.4f436","type":"comment","z":"be5380fd.68d8d8","name":"Enter data here","info":"Enter client id and client secret here. \nThe customer administrator can obtain those from \nXcelerator Admin Console by creating a \nServer User for Optimize my plant.","sticky":1,"x":480,"y":300,"wires":[]},{"id":"56acc2b6.c255ac","type":"comment","z":"be5380fd.68d8d8","name":"Get Token","info":"Turn client id and secret into a token valid for 30min.\nNote: the URL is different for each Region","sticky":1,"x":920,"y":300,"wires":[]},{"id":"70d6f722.4c27a","type":"comment","z":"be5380fd.68d8d8","name":"Set Failures","info":"Set Failures for the given ProjectId .","sticky":1,"x":1820,"y":320,"wires":[],"_type":"node"},{"id":"ece4f99d.898fa","type":"debug","z":"be5380fd.68d8d8","name":"Output","active":false,"console":false,"complete":"payload","x":1980,"y":500,"wires":[]},{"id":"227d7b05.bf0e1c","type":"debug","z":"be5380fd.68d8d8","name":"Prepare KPI Request","active":false,"console":"false","xaxis":"_time","complete":"true","x":1490,"y":500,"wires":[]},{"id":"edcea70f.af2318","type":"debug","z":"be5380fd.68d8d8","name":"Inputs","active":false,"console":"false","xaxis":"_time","complete":"true","x":320,"y":480,"wires":[]},{"id":"590f56f5.2b9338","type":"debug","z":"be5380fd.68d8d8","name":"Inputs","active":false,"console":"false","xaxis":"_time","complete":"true","x":490,"y":620,"wires":[]},{"id":"5fe749f1.cef428","type":"debug","z":"be5380fd.68d8d8","name":"Set Server User Credentials","active":false,"console":"false","xaxis":"_time","complete":"true","x":828.12890625,"y":481.4296875,"wires":[]},{"id":"f43b9ea5.2474f8","type":"debug","z":"be5380fd.68d8d8","name":"Get Auth Token","active":false,"console":"false","xaxis":"_time","complete":"true","x":1100,"y":480,"wires":[]},{"id":"480724a8.64f26c","type":"debug","z":"be5380fd.68d8d8","name":"ExampleOEE","active":false,"console":"false","xaxis":"_time","complete":"true","x":1730,"y":500,"wires":[]},{"id":"535d9201.d0fbfc","type":"function","z":"be5380fd.68d8d8","name":"Set Server User Credentials","func":"// first save the Input parameters, so they don't get overwritten\nif (msg.payload.PROJECTID) {\n    msg.PROJECTID = msg.payload.PROJECTID\n}\nif (msg.payload.SCENARIOID) {\n    msg.SCENARIOID = msg.payload.SCENARIOID\n}\nif (msg.payload.KPITYPE) {\n    msg.KPITYPE = msg.payload.KPITYPE\n}\nif (msg.payload.client_id) {\n    msg.client_id = msg.payload.client_id\n\n}\nif (msg.payload.client_secret) {\n    msg.client_secret = msg.payload.client_secret\n}\n\n// set credentials for Server User\n\nmsg.url = 'https://ompprod.eu1.sws.siemens.com/oauth/token'\nmsg.payload = 'grant_type=client_credentials&client_id=' + msg.client_id + '&client_secret=' + msg.client_secret;\n\nmsg.headers = {\n    'Content-Type': 'application/x-www-form-urlencoded'\n};\n\nreturn msg;","outputs":1,"language":"javascript","noerr":0,"x":530,"y":400,"wires":[["c3932f76.6ee4d","5fe749f1.cef428"]]},{"id":"9f21dec8.37ec78","type":"function","z":"be5380fd.68d8d8","name":"Prepare Failures Request","func":"if (msg.statusCode !== 200) {\n    node.error('Error ' + msg.statusCode);\n    return null;\n}\n\nconst token = msg.payload.access_token;\n//msg.url = 'https://cloud.eu1.sws.siemens.com/api/optimizemyplantapi/v1/omp/projects/' + msg.PROJECTID + '/scenarios/' + msg.SCENARIOID + '/kpis?kpitype=' + msg.KPITYPE\nmsg.url = 'https://cloud.eu1.sws.siemens.com/api/optimizemyplantapi/v1/omp/projects/' + msg.PROJECTID + '/failures'\n\nmsg.headers = {\n    'Accept': 'application/json',\n    'Authorization': 'Bearer ' + token\n};\n\n\nreturn msg;","outputs":1,"language":"javascript","noerr":0,"x":1260,"y":400,"wires":[["227d7b05.bf0e1c","1c4ffb0b.c128bd"]],"_type":"node"},{"id":"1f9a0a55.b5366e","type":"function","z":"be5380fd.68d8d8","name":"Set Inputs","func":"msg.PROJECTID = \"FDLO0H4U\";\nmsg.SCENARIOID = \"2770\";\nmsg.KPITYPE = \"Drain Total Throughput\";\nmsg.client_id = \"<insert your client_id>\";\nmsg.client_secret = \"<insert your client_secret>\"\nreturn msg;","outputs":1,"language":"javascript","noerr":0,"x":350,"y":560,"wires":[["535d9201.d0fbfc","590f56f5.2b9338"]]},{"id":"c3932f76.6ee4d","type":"http request","z":"be5380fd.68d8d8","name":"Get Auth Token","method":"POST","ret":"obj","url":"https://ompprod.eu1.sws.siemens.com/oauth/token","timeout":"","mindspherePath":"","useMindsphereAuth":false,"isAdmin":false,"x":850,"y":400,"wires":[["9f21dec8.37ec78","f43b9ea5.2474f8"]]},{"id":"b8a0730.165e31","type":"http request","z":"be5380fd.68d8d8","name":"Set Failures","method":"POST","ret":"obj","url":"https://cloud.eu1.sws.siemens.com/api/optimizemyplantapi/v1/omp/projects/{{PROJECTID}}/failures","timeout":"","mindspherePath":"","useMindsphereAuth":false,"isAdmin":false,"secretHeaders":"","x":1750,"y":400,"wires":[["ece4f99d.898fa","cb4c9357.f6cc1"]],"_type":"node"},{"id":"2ab7f5c5.5273a2","type":"inject","z":"be5380fd.68d8d8","name":"Start Flow","payloadType":"str","repeat":"","crontab":"","once":false,"timezone":"utc","x":190,"y":560,"wires":[["1f9a0a55.b5366e"]]},{"id":"cb4c9357.f6cc1","type":"skills-response","z":"be5380fd.68d8d8","x":2030,"y":400,"wires":[]},{"id":"712b999f.5c2918","type":"skills-trigger","z":"be5380fd.68d8d8","name":"OMP_SetAvailability","key":"OMP_SetAvailability","x":200,"y":400,"wires":[["535d9201.d0fbfc","edcea70f.af2318"]],"_type":"node"},{"id":"1c4ffb0b.c128bd","type":"template","z":"be5380fd.68d8d8","name":"ExampleFailures","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"[\n    {\n        \"EquipmentId\": \"S1\",\n        \"FailureName\": \"Failure\",\n        \"AvailabilityValue\": 93.4,\n        \"MTTR\": \"1:01:00\",\n        \"TimeRelation\": \"Simulation time\"\n    },\n    {\n        \"EquipmentId\": \"S2\",\n        \"FailureName\": \"Failure\",\n        \"AvailabilityValue\": 93.3,\n        \"MTTR\": \"1:02:00\",\n        \"TimeRelation\": \"Simulation time\"\n    },\n    {\n        \"EquipmentId\": \"S3\",\n        \"FailureName\": \"Failure\",\n        \"AvailabilityValue\": 93.2,\n        \"MTTR\": \"1:03:00\",\n        \"TimeRelation\": \"Simulation time\"\n    }\n]","output":"json","x":1500,"y":400,"wires":[["b8a0730.165e31","480724a8.64f26c"]],"_type":"node"}]