Hello everyone,
I made a script to read data from some API's. The system on the right works perfect but doesnt store the needed data in 1 array ( its important that we can call the values from other nodes who are not connected.) on the left i made a script (almost exact the same) to strore the data but when the signial gets to the last http request i get an error (picture 2). I'll give you the data what the http requests should give to.
Picture 1:
Picture 2:
Data from http request servicelocation:
{"appName":"Electro & Light Systems_API","serviceLocations":[{"serviceLocationId":59792,"serviceLocationUuid":"dff5be04-8398-4c18-8ccb-d1bd13eb46f7","name":"Electro & light systems","deviceSerialNumber":"5010003526"}]}
Data from the http request metering config:
{"lon":0,"lat":0,"electricityCost":0,"electricityCurrency":"EUR","timezone":"Europe/Brussels","appliances":[{"id":9,"name":"","type":"Find me","sourceType":"NILM"},{"id":18,"name":"","type":"Find me","sourceType":"NILM"},{"id":13,"name":"","type":"Microwave","sourceType":"NILM"},{"id":5,"name":"","type":"Find me","sourceType":"NILM"},{"id":20,"name":"","type":"Find me","sourceType":"NILM"},{"id":24,"name":"","type":"Find me","sourceType":"NILM"},{"id":8,"name":"","type":"Find me","sourceType":"NILM"},{"id":19,"name":"","type":"Find me","sourceType":"NILM"},{"id":12,"name":"","type":"Find me","sourceType":"NILM"},{"id":21,"name":"","type":"Find me","sourceType":"NILM"},{"id":22,"name":"","type":"Find me","sourceType":"NILM"},{"id":17,"name":"","type":"Find me","sourceType":"NILM"},{"id":11,"name":"","type":"Find me","sourceType":"NILM"},{"id":3,"name":"","type":"Find me","sourceType":"NILM"},{"id":4,"name":"","type":"Find me","sourceType":"NILM"},{"id":10,"name":"","type":"Find me","sourceType":"NILM"},{"id":25,"name":"","type":"Find me","sourceType":"NILM"},{"id":15,"name":"","type":"Find me","sourceType":"NILM"},{"id":6,"name":"","type":"Find me","sourceType":"NILM"},{"id":7,"name":"","type":"Find me","sourceType":"NILM"},{"id":16,"name":"","type":"Find me","sourceType":"NILM"},{"id":23,"name":"","type":"Find me","sourceType":"NILM"},{"id":1,"name":"","type":"Coffeemaker","sourceType":"NILM"},{"id":14,"name":"","type":"Dishwasher","sourceType":"NILM"},{"id":2,"name":"","type":"Car Charger","sourceType":"NILM"}],"actuators":[{"id":1,"monitorId":4,"name":"Test ap","serialNumber":"4006005597","type":"SWITCH","applianceType":"Air Conditioner","connectionState":"CONNECTED","states":[{"id":"ON_ON","name":"on","current":false},{"id":"OFF_OFF","name":"off","current":true}]}],"sensors":[{"id":5,"name":"3004003908","channels":[{"name":"Water","ppu":1,"uom":"l","enabled":true,"type":"water","channel":1},{"name":"Gas","ppu":100,"uom":"m3","enabled":true,"type":"gas","channel":2}]}],"monitors":[{"id":4,"name":"Test ap","serialNumber":"4006005597"}],"chargingStations":[{"id":59793,"serialNumber":"6000000046","connectMac":"A4CF129F717C","connectSerialNumber":"5130000476","firmwareVersion":"EC 3.18","chargers":[{"uuid":"b940831c-5f40-4803-873c-1f8c4b4e16d3","serialNumber":"5820000030","position":1,"minPower":6,"maxPower":16,"channels":[{"consumptionIndex":0,"powerTopicIndex":0,"modbusAddress":1,"name":"ELS - Laadpaal links - 1","phase":"PHASEA"},{"consumptionIndex":1,"powerTopicIndex":1,"modbusAddress":1,"name":"ELS - Laadpaal links - 1","phase":"PHASEB"},{"consumptionIndex":2,"powerTopicIndex":2,"modbusAddress":1,"name":"ELS - Laadpaal links - 1","phase":"PHASEC"}]},{"uuid":"c97f9021-3f09-4de2-abff-96072bbf09a3","serialNumber":"5820000120","position":2,"minPower":6,"maxPower":16,"channels":[{"consumptionIndex":3,"powerTopicIndex":3,"modbusAddress":2,"name":"ELS - Laadpaal links - 2","phase":"PHASEA"},{"consumptionIndex":4,"powerTopicIndex":4,"modbusAddress":2,"name":"ELS - Laadpaal links - 2","phase":"PHASEB"},{"consumptionIndex":5,"powerTopicIndex":5,"modbusAddress":2,"name":"ELS - Laadpaal links - 2","phase":"PHASEC"}]}],"behindVoltageTransformer":false},{"id":59796,"serialNumber":"6000000057","connectMac":"98F4AB66F788","connectSerialNumber":"5130000447","firmwareVersion":"EC 3.18","chargers":[{"uuid":"ae2c0d0d-076f-4f74-adc1-da5ac41f12d9","serialNumber":"5820000089","position":1,"minPower":6,"maxPower":16,"channels":[{"consumptionIndex":3,"powerTopicIndex":3,"modbusAddress":1,"name":"ELS - Laadpaal rechts - 1","phase":"PHASEA"},{"consumptionIndex":4,"powerTopicIndex":4,"modbusAddress":1,"name":"ELS - Laadpaal rechts - 1","phase":"PHASEB"},{"consumptionIndex":5,"powerTopicIndex":5,"modbusAddress":1,"name":"ELS - Laadpaal rechts - 1","phase":"PHASEC"}]},{"uuid":"d898054d-42e6-4896-b01e-33ad94cbac3f","serialNumber":"5820000023","position":2,"minPower":6,"maxPower":16,"channels":[{"consumptionIndex":0,"powerTopicIndex":0,"modbusAddress":2,"name":"ELS - Laadpaal rechts - 2","phase":"PHASEA"},{"consumptionIndex":1,"powerTopicIndex":1,"modbusAddress":2,"name":"ELS - Laadpaal rechts - 2","phase":"PHASEB"},{"consumptionIndex":2,"powerTopicIndex":2,"modbusAddress":2,"name":"ELS - Laadpaal rechts - 2","phase":"PHASEC"}]}],"behindVoltageTransformer":false}],"phaseType":"THREE_STAR","channelsConfiguration":{"inputChannels":[{"ctInput":0,"name":"Net","phase":0,"inputChannelType":"CONSUMPTION","reversed":false,"nilm":true,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":1,"name":"Net","phase":1,"inputChannelType":"CONSUMPTION","reversed":false,"nilm":true,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":2,"name":"Net","phase":2,"inputChannelType":"CONSUMPTION","reversed":false,"nilm":true,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":3,"name":"PV 1","phase":0,"inputChannelType":"PRODUCTION","inputChannelConnection":"GRID","reversed":false,"nilm":false,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":4,"name":"PV 1","phase":1,"inputChannelType":"PRODUCTION","inputChannelConnection":"GRID","reversed":false,"nilm":false,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":5,"name":"PV 1","phase":2,"inputChannelType":"PRODUCTION","inputChannelConnection":"GRID","reversed":false,"nilm":false,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":6,"name":"PV 2","phase":2,"inputChannelType":"PRODUCTION","inputChannelConnection":"GRID","reversed":true,"nilm":false,"balanced":false,"inputChannelCTType":"SCT2_50A"},{"ctInput":0,"phase":0,"inputChannelType":"UNUSED","reversed":false,"nilm":false,"balanced":false,"inputChannelCTType":"CT50_100_200"},{"ctInput":0,"phase":0,"inputChannelType":"UNUSED","reversed":false,"nilm":false,"balanced":false,"inputChannelCTType":"CT50_100_200"}]},"measurements":[{"id":92894,"parentId":0,"name":"Net","type":"GRID","channels":[{"consumptionIndex":0,"powerTopicIndex":0,"name":"Net","phase":"PHASEA"},{"consumptionIndex":1,"powerTopicIndex":1,"name":"Net","phase":"PHASEB"},{"consumptionIndex":2,"powerTopicIndex":2,"name":"Net","phase":"PHASEC"}],"childIds":[]},{"id":121792,"parentId":0,"name":"PV 1","type":"PRODUCTION","channels":[{"consumptionIndex":3,"powerTopicIndex":3,"name":"PV 1","phase":"PHASEA"},{"consumptionIndex":4,"powerTopicIndex":4,"name":"PV 1","phase":"PHASEB"},{"consumptionIndex":5,"powerTopicIndex":5,"name":"PV 1","phase":"PHASEC"}],"childIds":[]},{"id":121800,"parentId":0,"name":"PV 2","type":"PRODUCTION","channels":[{"consumptionIndex":6,"powerTopicIndex":6,"name":"PV 2","phase":"PHASEC"}],"childIds":[]}],"custom":[],"overloadMaxAmpere":25,"serviceLocationId":59792,"serviceLocationUuid":"dff5be04-8398-4c18-8ccb-d1bd13eb46f7","name":"Electro & light systems","deviceSerialNumber":"5010003526","from":1614084696645}
THE SCRIPT:
[{"id":"953113c4da81de3f","type":"link in","z":"ae51c14d6e31c251","name":"Serienummer/servicelcation","links":["30b4089784cd57a3"],"x":155,"y":80,"wires":[["271f27fa5e73acdc"]]},{"id":"8a01e1611d64e3de","type":"http request","z":"ae51c14d6e31c251","name":"Servicelocation","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":300,"y":240,"wires":[["48cdc5f648e25532","c9fe1c4c40aec959"]]},{"id":"c9fe1c4c40aec959","type":"function","z":"ae51c14d6e31c251","name":"rotate and rename","func":"var Servicelocation = global.get(\"ServicelocationID\")\n\n//global.set(\"MonitorID\",msg.payload.serviceLocations[0].serviceLocationId )\n\n\nif (global.get(\"Serienummers\") === undefined){\n global.set(\"Serienummers\",[\n ['Naam'],\n ['Genius'],\n ['Laadpaal1'],\n ['Laadpaal2'],\n ])}\n \n\n\n\nconst APIdata = msg.payload.serviceLocations;\nfor (var i = 0; i < APIdata.length; i++) {\n var Serienummers = global.get(\"Serienummers\");\n (Serienummers[0]).push(APIdata[i].name);\n (Serienummers[1]).push(APIdata[i].serviceLocationId);\n}\n\nmsg.payload= Serienummers[1][1]\n\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":280,"wires":[["426d69268b5bc23a"]]},{"id":"f7f9bc850af30fe1","type":"function","z":"ae51c14d6e31c251","name":"","func":"var UserMatrix = global.get(\"UserMatrix\")\n\nmsg.payload= UserMatrix[6][1]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":120,"wires":[["20b93b716fb27071"]]},{"id":"136932d11467e21c","type":"template","z":"ae51c14d6e31c251","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/servicelocation?deviceSerialNumber={{payload}}\n","output":"str","x":280,"y":200,"wires":[["8a01e1611d64e3de"]]},{"id":"20b93b716fb27071","type":"json","z":"ae51c14d6e31c251","name":"","property":"payload","action":"","pretty":false,"x":270,"y":160,"wires":[["136932d11467e21c"]]},{"id":"271f27fa5e73acdc","type":"change","z":"ae51c14d6e31c251","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":80,"wires":[["f7f9bc850af30fe1"]]},{"id":"48cdc5f648e25532","type":"debug","z":"ae51c14d6e31c251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":240,"wires":[]},{"id":"ac7427c760b73cf5","type":"http request","z":"ae51c14d6e31c251","name":"Metering config","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":300,"y":400,"wires":[["40bf11ab96555ec8","3f144014ebcd0853","58b92f60c65db1cc","f1e6bea29d8964b8","d79fd912ecd9e71d"]]},{"id":"414f4376e744bc63","type":"template","z":"ae51c14d6e31c251","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/servicelocation/{{payload}}/info\n","output":"str","x":280,"y":360,"wires":[["ac7427c760b73cf5","e8725f5a1b3d27e5"]]},{"id":"426d69268b5bc23a","type":"change","z":"ae51c14d6e31c251","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":320,"wires":[["414f4376e744bc63"]]},{"id":"8bf0e946c9122b8f","type":"inject","z":"ae51c14d6e31c251","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":40,"wires":[["271f27fa5e73acdc"]]},{"id":"f1e6bea29d8964b8","type":"debug","z":"ae51c14d6e31c251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":400,"wires":[]},{"id":"d79fd912ecd9e71d","type":"function","z":"ae51c14d6e31c251","d":true,"name":"","func":"\n (Serienummers[2]).push(msg.payload.chargingStations[0].connectSerialNumber);\n (Serienummers[3]).push(msg.payload.chargingStations[1].connectSerialNumber);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":440,"wires":[[]]},{"id":"562608a14c70a125","type":"http request","z":"ae51c14d6e31c251","name":"Servicelocation","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1120,"y":220,"wires":[["4f71614d9739465d","b625d1b26ef7364c"]]},{"id":"4f71614d9739465d","type":"function","z":"ae51c14d6e31c251","name":"rotate and rename","func":"const rotated = {\n SERVICELOCATIONID: [],\n SERVICELOCATIONUUID: [],\n NAAM_SERVICELOCATION: [],\n\n\n}\n\n\nconst APIdata = msg.payload.serviceLocations;\nfor (var i = 0; i < APIdata.length; i++) {\n rotated.SERVICELOCATIONID[i] = APIdata[i].serviceLocationId\n rotated.SERVICELOCATIONUUID[i] = APIdata[i].serviceLocationUuid\n rotated.NAAM_SERVICELOCATION[i] = APIdata[i].name\n}\n\nmsg.payload = rotated;\nglobal.set('servicelocation',rotated)\n\nvar msg1 = { payload: rotated.SERVICELOCATIONID[0] };\n\nreturn [msg,msg1];\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":260,"wires":[[],["1f9314c8cf894074"]]},{"id":"a1337c8261d2d3b8","type":"function","z":"ae51c14d6e31c251","name":"","func":"var UserMatrix = global.get(\"UserMatrix\")\n\nmsg.payload= UserMatrix[6][1]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1100,"y":100,"wires":[["2769096cb7921afe"]]},{"id":"224f3a34b0135eb6","type":"template","z":"ae51c14d6e31c251","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/servicelocation?deviceSerialNumber={{payload}}\n","output":"str","x":1100,"y":180,"wires":[["562608a14c70a125"]]},{"id":"2769096cb7921afe","type":"json","z":"ae51c14d6e31c251","name":"","property":"payload","action":"","pretty":false,"x":1090,"y":140,"wires":[["224f3a34b0135eb6"]]},{"id":"1799f90d35f355bf","type":"change","z":"ae51c14d6e31c251","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":60,"wires":[["a1337c8261d2d3b8"]]},{"id":"b625d1b26ef7364c","type":"debug","z":"ae51c14d6e31c251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1310,"y":220,"wires":[]},{"id":"207adb786b34cf2f","type":"http request","z":"ae51c14d6e31c251","name":"Metering config","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://app1pub.smappee.net/dev/v3/servicelocation/59792/meteringconfiguration","tls":"","persist":false,"proxy":"","authType":"bearer","senderr":false,"x":1120,"y":380,"wires":[["78cad9dd5531d957","aa5c4c587075b5c0","348ffe1312bf476d","19bce4846bfb0a90"]]},{"id":"99717b6f7f06de61","type":"template","z":"ae51c14d6e31c251","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/servicelocation/{{payload}}/info\n","output":"str","x":1100,"y":340,"wires":[["207adb786b34cf2f"]]},{"id":"1f9314c8cf894074","type":"change","z":"ae51c14d6e31c251","name":"","rules":[{"t":"set","p":"headers.Authorization","pt":"msg","to":"\"Bearer \" & $globalContext(\"UserMatrix[5][1]\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":300,"wires":[["99717b6f7f06de61"]]},{"id":"e4914bcb9320ad27","type":"inject","z":"ae51c14d6e31c251","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":940,"y":60,"wires":[["1799f90d35f355bf"]]},{"id":"e8725f5a1b3d27e5","type":"debug","z":"ae51c14d6e31c251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","targetType":"msg","statusVal":"","statusType":"auto","x":500,"y":360,"wires":[]},{"id":"19bce4846bfb0a90","type":"debug","z":"ae51c14d6e31c251","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1310,"y":380,"wires":[]}]
does anyone know why i get this error ?
Thanks in advance
Olivia