I knew you were up to the challenge !!
wsft.txt (26.7 KB)
Here is the complete output. Copy/paste out of debug doesn't work, it is too big.
And the flow.
[{"id":"228836bd.ed4b1a","type":"function","z":"f5b50430.ea48b8","name":"MF2Array","func":"var ech = [];\nvar temp = [];\nvar precipi = [];\nvar windf = [];\nvar windg = [];\nvar windd = [];\n\nflow.set(\"ech\",\"\");\nflow.set(\"temp\",\"\");\nflow.set(\"precipi\",\"\");\nflow.set(\"precipp\",\"\");\nflow.set(\"windf\",\"\");\nflow.set(\"windg\",\"\");\nflow.set(\"windd\",\"\");\n\nfor (var i=0; i<24;i++) {\n ech.push(msg.payload.forecast[i].dt);\n temp.push(msg.payload.forecast[i].T.value);\n precipi.push(msg.payload.forecast[i].rain[\"1h\"]);\n windf.push(msg.payload.forecast[i].wind.speed);\n windg.push(msg.payload.forecast[i].wind.gust);\n windd.push(msg.payload.forecast[i].wind.icon);\n}\n\nflow.set(\"ech\",ech);\nflow.set(\"temp\",temp);\nflow.set(\"precipi\",precipi);\nflow.set(\"windf\",windf);\nflow.set(\"windg\",windg);\nflow.set(\"windd\",windd);\nflow.set(\"nbstep\",24);\nflow.set(\"index\",0);\nreturn msg;\n","outputs":1,"noerr":0,"x":500,"y":880,"wires":[["cc6aaa78.40ffb8"]]},{"id":"cc6aaa78.40ffb8","type":"counter-loop","z":"f5b50430.ea48b8","name":"Step?","counter":"kjsqhdhsifhsj","counterType":"msg","reset":false,"resetValue":"value-null","initial":"0","initialType":"num","operator":"lt","termination":"nbstep","terminationType":"flow","increment":1,"incrementType":"num","x":690,"y":880,"wires":[[],["282d038e.77a30c"]]},{"id":"282d038e.77a30c","type":"function","z":"f5b50430.ea48b8","name":"Reassemble","func":"var host = global.get(\"host\");\nvar token = global.get(\"token\");\n\nvar ech = flow.get(\"ech\");\nvar temp = flow.get(\"temp\");\nvar precipi = flow.get(\"precipi\");\nvar windf = flow.get(\"windf\");\nvar windd = flow.get(\"windd\");\nvar windg = flow.get(\"windg\",\"\");\nvar i = flow.get(\"index\");\n\n// var windtext=[\"N\",\"NNE\",\"NE\",\"ENE\",\"E\",\"ESE\", \"SE\", \"SSE\",\"S\",\"SSO\",\"SO\",\"OSO\",\"O\",\"ONO\",\"NO\",\"NNO\",\"N\"]\n\nvar hour = new Date(ech[i]*1000).getHours();\nvar hour_format = \"\";\nif ( hour <= 9 ) { hour_format = \"0\" + hour + \":00\" }\nelse { hour_format = hour + \":00\" }\n\nvar raini = precipi[i];\nif ( raini == \"unknown\" ) { raini = \"-\" }\nelse raini = raini.toFixed(1)\n\n\nvar windgkm = ( windg[i] * 3.6 ).toFixed(0) + \")\";\nvar windfkm = ( windf[i] * 3.6 ).toFixed(0) + \" km/h (\" + windgkm;\n// var wind_index = (windd[i] / 22.5).toFixed(0) - 1;\n\nmsg.payload = {\n \"state\": 'forecast',\n \"attributes\" : {\n \"hour\": hour_format,\n \"temp\": temp[i].toFixed(1),\n \"rain\": raini,\n \"wind\": windfkm,\n \"dir\" : windd[i]\n }\n}\n\nvar sensor = 'forecast' + i;\nmsg.url = host + \"/api/states/sensor.\" + sensor;\nmsg.method = \"POST\";\nmsg.headers = {\n 'Authorization': 'Bearer ' + token,\n 'content-type': 'application/json',\n} ;\ni = i + 1;\nflow.set(\"index\",i);\nreturn msg;\n","outputs":1,"noerr":0,"x":573,"y":980,"wires":[["23c9d18f.f84ace"]]},{"id":"23c9d18f.f84ace","type":"https-node","z":"f5b50430.ea48b8","name":"HA OUT","method":"use","ret":"txt","url":"","authorized":false,"agent":true,"x":740,"y":980,"wires":[["cc6aaa78.40ffb8"]]},{"id":"f2b0fee2.29624","type":"http request","z":"f5b50430.ea48b8","name":"WSFT","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://webservice.meteofrance.com/premiumforecast?token=private_token&lat=43.58&lon=1.44&lang=en","tls":"","persist":false,"proxy":"","authType":"","x":230,"y":880,"wires":[["1976f02d.9def7"]]},{"id":"1976f02d.9def7","type":"json","z":"f5b50430.ea48b8","name":"","property":"payload","action":"","pretty":false,"x":350,"y":880,"wires":[["228836bd.ed4b1a"]]},{"id":"4d35554e.99276c","type":"inject","z":"f5b50430.ea48b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":880,"wires":[["f2b0fee2.29624"]]}]
In the WSFT node, I have removed the token (personal info).
The functions are probably badly written as well... But, my question is really about doing one action per entry in the JSON output.
Thanks for looking into this!
GV