Integration from Date in Debug

Hi everybody,

I am a full beginner by Node-Red, so please excuse me if my explanations are maybe difficult to understand.

I am trying to use a API form Forcast.solar to become the actuel PV estimated yiel.
Therfore I am using a inject node then a http request node and finally a debug node.
The http request use this link: https://api.forecast.solar/estimate/watt_hours_day/39.7/2.97/45/0/1.2 (Json object) and it is working fine.
In the debug I am using msg. payload.result to obtain the kwh. The Api provide the kwh for today and tomorrow. I would like to isolate the value for the catual day.
To do that I can e.g in the debug use msg.payload.result["2023-01-06"]. But the date is changing every day.
So how can I integrate the actual date in the debug to make sure, it will actualize the date in the request?
I hope you can understand.

Best and happy new year.

Syl

Hi and welcome to the forum.

I am not sure this question falls under the creating nodes category.
(That is for people wanting to make their own nodes)

Could you change the request to general rather than this one?

Hi?
Thank you very much for the advice.

I changed it already.

Best

Syl

You could convert the msg.payload.result to an array. Then msg.payload.result[0] will be today, and msg.payload.result[1] would be tomorrow. But it relies on the object having same layout each time.
e.g.

[{"id":"1443affe2a15c0ed","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"url","v":"https://api.forecast.solar/estimate/watt_hours_day/39.7/2.97/45/0/1.2","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":2820,"wires":[["0aaf17df539748e2"]]},{"id":"0aaf17df539748e2","type":"http request","z":"da8a6ef0b3c9a5c8","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":350,"y":2820,"wires":[["715b5ab2d3b28abb"]]},{"id":"715b5ab2d3b28abb","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload.result","pt":"msg","to":"$$.payload.result.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2820,"wires":[["a91123f4e56d6d55"]]},{"id":"a91123f4e56d6d55","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 223","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":2860,"wires":[]}]

Or you could use a more complicated expression and create the date strings require to address your values.
e.g.

[{"id":"1443affe2a15c0ed","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"result\":{\"2023-01-06\":4568,\"2023-01-07\":4514},\"message\":{\"code\":0,\"type\":\"success\",\"text\":\"\",\"info\":{\"latitude\":39.7,\"longitude\":2.97,\"distance\":0,\"place\":\"Camí de Tirasset, Inca, Raiguer, Illes Balears, 07430, España\",\"timezone\":\"Europe/Madrid\",\"time\":\"2023-01-06T08:42:46+01:00\",\"time_utc\":\"2023-01-06T07:42:46+00:00\"},\"ratelimit\":{\"period\":3600,\"limit\":12,\"remaining\":8}}}","payloadType":"json","x":150,"y":2800,"wires":[["7f239f293c096fb5"]]},{"id":"7f239f293c096fb5","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload.today","pt":"msg","to":"$lookup($$.payload.result,$moment().format(\"YYYY-MM-DD\"))","tot":"jsonata"},{"t":"set","p":"payload.tomorrow","pt":"msg","to":"$lookup($$.payload.result,$moment().add(1, \"day\").format(\"YYYY-MM-DD\"))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":2800,"wires":[["a91123f4e56d6d55"]]},{"id":"a91123f4e56d6d55","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 223","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":2840,"wires":[]}]
1 Like

Thank you so much. It works like a charm. I am still learning on the code. Have a nice weekend

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.