# Solar data from mqtt to PVoutput

**URL:** <https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150>\
**Category:** General\
**Created:** [25 October 2019 15:53 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150 "2019-10-25T15:53:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [25 October 2019 15:53 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150/1 "2019-10-25T15:53:20Z")

</div>

Hello,  
i have been busting my head with tis issue.  
I have input from mqtt and i want some of this input formatted into a url and push it to pvoutput.  
I know what the URL has to look like.  
Manualy making the url works.  
1 piece of data from mqtt and input them into the httprequest with moustache works  
But how to get multiple data into the http request?? I have no idea.

See attached flow. the inject is 1 output from the solarpanels.  
I deleted my API key so testing is not possible. Sorry 😉

```auto
[{"id":"5f00def2.c9ac9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"bb06f86a.d7d958","type":"debug","z":"5f00def2.c9ac9","name":"WATT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1010,"y":120,"wires":[]},{"id":"d8270078.6a829","type":"function","z":"5f00def2.c9ac9","name":"Watt","func":"var v2 = { payload: msg.payload.runningInfo.pac.toString() };\nreturn v2;","outputs":1,"noerr":0,"x":290,"y":300,"wires":[["92306094.ce42b"]]},{"id":"4948e055.890ae","type":"http request","z":"5f00def2.c9ac9","name":"PV output","method":"GET","ret":"txt","paytoqs":true,"url":"https://pvoutput.org/service/r2/addstatus.jsp?key=APIKEY&sid=MYID&d=20191025&t=13:40&v2={{v2}}&v5=15.5&v6={{v6}}","tls":"","persist":false,"proxy":"","authType":"","x":840,"y":120,"wires":[["bb06f86a.d7d958"]]},{"id":"64872bec.6c7f94","type":"function","z":"5f00def2.c9ac9","name":"Voltage","func":"var v6 = { payload: msg.payload.runningInfo.vac1.toString() };\nreturn v6;","outputs":1,"noerr":0,"x":300,"y":340,"wires":[["92306094.ce42b"]]},{"id":"4b0742ce.4637cc","type":"inject","z":"5f00def2.c9ac9","name":"","topic":"","payload":"{\"address\":11,\"addressConfirmed\":true,\"idInfo\":{\"firmwareVersion\":\"\",\"function\":130,\"internalVersion\":\"\",\"manufacturer\":\"\",\"modelName\":\"\",\"nominalVpv\":0,\"safetyCountryCode\":0,\"serialNumber\":\"\"},\"inverterType\":3,\"isOnline\":true,\"lastSeen\":1572009709165,\"runningInfo\":{\"eDay\":14.5,\"eTotal\":6709.9,\"errorMessage\":[],\"fac1\":50.01,\"fac2\":50.01,\"fac3\":50.01,\"function\":129,\"gcfiFault\":20,\"hTotal\":3553,\"iac1\":4.4,\"iac2\":4.4,\"iac3\":4.2,\"ipv1\":4.5,\"ipv2\":2.5,\"line1FFault\":60.48,\"line1VFault\":0,\"line2FFault\":30.54,\"line2VFault\":0,\"line3FFault\":0,\"line3VFault\":0,\"pac\":3266,\"pv1Fault\":0,\"pv2Fault\":0.7,\"temp\":37.8,\"tempFault\":151.5,\"timestamp\":\"20191025152149\",\"vac1\":231.5,\"vac2\":230.9,\"vac3\":229.5,\"vpv1\":497.7,\"vpv2\":378.5,\"workMode\":1},\"serial\":\"96000DTU187W0031\",\"serialNumber\":[57,54,48,48,48,68,84,85,49,56,55,87,48,48,51,49],\"settingInfo\":{\"facMax\":0,\"facMin\":0,\"function\":131,\"tStart\":0,\"vacMax\":0,\"vacMin\":0,\"vpvStart\":0}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":160,"wires":[["9999376c.98f9f8","d8270078.6a829","64872bec.6c7f94","8d221d65.7ce16","8793d5cc.e4b648","34737d4f.e299f2","686a239c.ea70ac"]]},{"id":"9999376c.98f9f8","type":"function","z":"5f00def2.c9ac9","name":"Watt&Voltage (as string)","func":"msg.payload = {\n \"v2\": msg.payload.runningInfo.pac.toString(),\n \"v6\": msg.payload.runningInfo.vac1.toString(),\n };\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":120,"wires":[[]]},{"id":"d320de03.aa64b","type":"comment","z":"5f00def2.c9ac9","name":"Inject node","info":"The injectnode gives the output from my solarpanels.\nOutput is every 5 seconds. i do not need all data. Only:\n\npac: (is the current WATT)\nvac1: (current voltage)\ntimestamp: (must be seperated tot date and time)\n","x":120,"y":100,"wires":[]},{"id":"ec87dd4c.8f9ab","type":"comment","z":"5f00def2.c9ac9","name":"PV output & Issues","info":"https://pvoutput.org/service/r2/addstatus.jsp?\nkey=API KEY&\nsid=MYID&\nd=20191025&\nt=13:40&\nv1=v2&\nv2={{{v2}}}&\nv5=15.5&\nv6={{{v6}}}\n\nAbove is the url with API it works when i input the numbers manually.\n\nd=date, but the format from my panels is different\nBut it doe snot have to be the dat from the panels, it can be system date. date from the upload.\nSame with time.\nv1=v2 no changes here.\nv2 the data from pac\nv5 the temperature, nice to have, but data comes from other mqtt\nv6 is the vac1 not nescesary ","x":690,"y":60,"wires":[]},{"id":"8d221d65.7ce16","type":"function","z":"5f00def2.c9ac9","name":"Watt&Voltage (numbers)","func":"msg.payload = {\n \"v2\": msg.payload.runningInfo.pac,\n \"v6\": msg.payload.runningInfo.vac1,\n };\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":160,"wires":[[]]},{"id":"8793d5cc.e4b648","type":"function","z":"5f00def2.c9ac9","name":"Watt&Voltage (not working)","func":"var v2 = { payload: msg.payload.runningInfo.pac };\nvar v6 = { payload: msg.payload.runningInfo.vac1 };\nreturn v2,v6;","outputs":1,"noerr":0,"x":360,"y":200,"wires":[[]]},{"id":"d9c8e7a7.188bf8","type":"delay","z":"5f00def2.c9ac9","name":"Upload every 5 minutes","pauseType":"delay","timeout":"300","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":630,"y":120,"wires":[[]]},{"id":"1c8d2c0.25d6bd4","type":"inject","z":"5f00def2.c9ac9","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":420,"wires":[[]]},{"id":"92306094.ce42b","type":"debug","z":"5f00def2.c9ac9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":360,"wires":[]},{"id":"34737d4f.e299f2","type":"moment","z":"5f00def2.c9ac9","name":"datum","topic":"","input":"payload.runningInfo.timestamp,","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYYMMDD","locale":"nl_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":290,"y":380,"wires":[["92306094.ce42b"]]},{"id":"686a239c.ea70ac","type":"moment","z":"5f00def2.c9ac9","name":"tijd","topic":"","input":"payload.runningInfo.timestamp,","inputType":"msg","inTz":"Europe/Amsterdam","adjAmount":0,"adjType":"days","adjDir":"add","format":"HH:mm","locale":"nl_NL","output":"","outputType":"msg","outTz":"Europe/Amsterdam","x":290,"y":420,"wires":[["92306094.ce42b"]]},{"id":"5057ee19.4ce5c","type":"join","z":"5f00def2.c9ac9","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":590,"y":240,"wires":[["92306094.ce42b"]]}]

```

But output has to look like this:  
[https://pvoutput.org/service/r2/addstatus.jsp?key=API](https://pvoutput.org/service/r2/addstatus.jsp?key=API) KEY&sid=MYID&d=20191025&t=13:40&v1=v2&v2={{{v2}}}&v5=15.5&v6={{{v6}}}

Where between the moustache has to be numbers, and the formatting of the dates has to be like in the url.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [25 October 2019 16:45 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150/2 "2019-10-25T16:45:38Z")

</div>

If you look at the `Info` panel on the right hand side after clicking on the `http request` node.  
You can see that you can pass the url to the node if you leave the url field blank in the config panel.

So you can build the URL in the same function as you simplify the watt and voltage

eg.

```auto
msg.v2 = msg.payload.runningInfo.pac,
msg.v6 = msg.payload.runningInfo.vac1,
msg.url="https://pvoutput.org/service/r2/addstatus.jsp?key=APIKEY&sid=MYID&d=20191025&t=13:40&v2="+msg.v2+"&v5=15.5&v6="+msg.v6

return msg

```

If you want to use the moment node its probably easier to do it in serial than in parallel.  
move the V2 & V6 values msg.v2 & msg.v6 in a function node  
then have the moment node then build the url in another function node where you have the date and time available.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [25 October 2019 20:16 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150/3 "2019-10-25T20:16:12Z")

</div>

Thank you,  
First part is done.  
Now the date part.?  
I do not want to use the moment node, but the date format has to be correct..

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [25 October 2019 20:21 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150/4 "2019-10-25T20:21:01Z")

</div>

There are lots of guides online about "javascript date" if you don't want to use the moment node.

---

<div class="post-metadata">

**Author:** ![R0yk3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/r0yk3/32/10650_2.png) [@R0yk3](https://discourse.nodered.org/u/R0yk3)\
**Post date:** [25 October 2019 22:54 UTC](https://discourse.nodered.org/t/solar-data-from-mqtt-to-pvoutput/17150/5 "2019-10-25T22:54:38Z")

</div>

Thank you for the heads up.  
this is how i solved it for now:

```auto
msg.d = msg.payload.runningInfo.timestamp.substr(0, 8),
msg.h = msg.payload.runningInfo.timestamp.substr(8, 2),
msg.m = msg.payload.runningInfo.timestamp.substr(10, 2),
msg.v2 = msg.payload.runningInfo.pac,
msg.v6 = msg.payload.runningInfo.vac1,
msg.url="https://pvoutput.org/service/r2/addstatus.jsp?key=API&sid=MYID&d="+msg.d+"&t="+msg.h+":"+msg.m+"&v2="+msg.v2+"&v6="+msg.v6

return msg

```

There is a timestamp in my data i only had to reformat it.
