Hi .. i was playing around with this also and i noticed too that the api doesnt return data (404 status error) for the next day when its not past some specific time. So its after 16:00 ?
I guess you can use a Trigger node and set it up to trigger the request of data once a day and after 16:00.
Regarding the manipulation of datetimes i always find it easy to use the moment.js library.
If you are running Node red 1.3 or greater you can enable in your settings.js
file the option to load additional modules (as is the moment.js
module).
More info on this new functionExternalModules
Node-red feature here
Once you have that setup you can use it in your Function node.
Demo flow of its use and formatting of TimeStamp
to the format your sqlite db needs.
[{"id":"0e58a03f349f4bf0","type":"inject","z":"4895ea10b4ee9ead","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 16 * * *","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":250,"y":680,"wires":[["16a66d05b8144149"]]},{"id":"16a66d05b8144149","type":"function","z":"4895ea10b4ee9ead","name":"","func":"let urlDate = moment().add(1, 'day').format(\"YYYY-MM-DD\");\nnode.warn(urlDate)\n\n// if (moment().isAfter(moment('16:00', 'HH:mm'))) {\n// urlDate = moment().add(1, 'day').format(\"YYYY-MM-DD\");\n// }\n// else {\n// urlDate = moment().format(\"YYYY-MM-DD\");\n// }\n\n\nmsg.url = `https://www.vattenfall.se/api/price/spot/pricearea/${urlDate}/${urlDate}/SN3`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"moment","module":"moment"}],"x":440,"y":680,"wires":[["1b9b2d8f17fcfcc8"]]},{"id":"1b9b2d8f17fcfcc8","type":"http request","z":"4895ea10b4ee9ead","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":680,"wires":[["25c114981d693ae5"]]},{"id":"523288eb84a1db59","type":"debug","z":"4895ea10b4ee9ead","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":680,"wires":[]},{"id":"25c114981d693ae5","type":"function","z":"4895ea10b4ee9ead","name":"","func":"if (msg.statusCode === 200) {\n msg.payload = msg.payload.map(el => {\n return {\n TimeStamp: moment(el.TimeStamp).format('YYYY-MM-DD HH:mm:ss'), // format timestamp using moment\n Value: el.Value\n }\n });\n return msg\n}\nelse {\n msg.payload = \"No Data\"\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"moment","module":"moment"}],"x":800,"y":680,"wires":[["523288eb84a1db59"]]}]