Hi @Steve-Mcl
Just an FYI
To better explain what I was/am trying to do, here is the flow I have ended up with.
Your efforts have not gone in vain and are much appreciated!
[{"id":"3ae76361.c44e84","type":"change","z":"1fe2e6f5.206b79","name":"","rules":[{"t":"set","p":"slots","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":100,"wires":[["c47ce33b.acc1b8"]]},{"id":"f967f962.57fb2","type":"comment","z":"1fe2e6f5.206b79","name":"Get Octopus slot pricing & store @17:53, data is for 1600 today until 2300 tomorrow","info":"https://discourse.nodered.org/t/best-strategy-for-reading-sorting-electricity-cost-array/7929\n","x":370,"y":60,"wires":[]},{"id":"2c62a350.5abbe4","type":"file","z":"1fe2e6f5.206b79","name":"","filename":"OctopusPrices.json","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":1030,"y":100,"wires":[["3ee0a0a4.5e4718"]]},{"id":"c47ce33b.acc1b8","type":"http request","z":"1fe2e6f5.206b79","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-H/standard-unit-rates/","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":100,"wires":[["b499a7a8.89ad5"]]},{"id":"fc481d42.5de148","type":"function","z":"1fe2e6f5.206b79","name":"","func":"var now = Date.now();\n\nvar payload = msg.payload.results;\n\n//payload.results[0].valid_from\n\nfor(var i = 0; i < payload.length; i++){\n msg.payload.results[i].valid_from = Date.parse(msg.payload.results[i].valid_from);\n msg.payload.results[i].valid_to = Date.parse(msg.payload.results[i].valid_to);\n}\n\n/*\n//Comment this section out when data missing.\nvar data = msg.payload.results;\nvar newData = data.filter(item => {\n return item.valid_from > now;\n});\nmsg.payload.results = newData;\n//\nmsg.payload.results = data;\n// to get missing data\n*/\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":840,"y":100,"wires":[["2c62a350.5abbe4","a0c2161b.5472e"]]},{"id":"b499a7a8.89ad5","type":"json","z":"1fe2e6f5.206b79","name":"","property":"payload","action":"obj","pretty":false,"x":690,"y":100,"wires":[["fc481d42.5de148"]]},{"id":"577f452e.0df87c","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["207838b6.102de8"],"x":1315,"y":100,"wires":[]},{"id":"3ee0a0a4.5e4718","type":"delay","z":"1fe2e6f5.206b79","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1220,"y":100,"wires":[["577f452e.0df87c","47351e64.6b203"]]},{"id":"4f4e7d65.e2b2d4","type":"comment","z":"1fe2e6f5.206b79","name":"Check InfluxFB has been filled for midnight today, if so, send email, if not refetch","info":"","x":820,"y":140,"wires":[]},{"id":"ddf1ed4c.0d881","type":"cronplus","z":"1fe2e6f5.206b79","name":"Update Octopus","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"Update","topic":"Update","payloadType":"str","payload":"8","expressionType":"cron","expression":"0 53 17 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":100,"wires":[["3ae76361.c44e84"],[]]},{"id":"a0c2161b.5472e","type":"link out","z":"1fe2e6f5.206b79","name":"API Slots","links":["cf76cd0a.7986b8"],"x":935,"y":60,"wires":[]},{"id":"ba71f6ac.c921d","type":"cronplus","z":"1fe2e6f5.206b79","name":"Check Data */1","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/5 * * * * ","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":200,"y":160,"wires":[["3ae76361.c44e84"],[]]},{"id":"c25a0794.4e241","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["2f3d2f97.ae8dd","3263b051.51d618","c37657d4.22ba28"],"x":55,"y":160,"wires":[["ba71f6ac.c921d"]]},{"id":"3263b051.51d618","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["c25a0794.4e241"],"x":1175,"y":200,"wires":[]},{"id":"47351e64.6b203","type":"function","z":"1fe2e6f5.206b79","name":"InfluxDB query","func":"var d = new Date();\n//d.setHours(25,0,0,0); // next midnight\nd.setHours(1,0,0,0); // previous midnight\nd = Date.parse(d);\nd = d * 1000000\nd = \"SELECT * FROM slots WHERE time = \" + d;\nmsg.query = d;\n//msg.payload =\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":180,"wires":[["6dcbfd09.dab3b4"]]},{"id":"6dcbfd09.dab3b4","type":"influxdb in","z":"1fe2e6f5.206b79","influxdb":"6e737abc.a8cef4","name":"InfluxDB / energy","query":"","rawOutput":false,"precision":"","retentionPolicy":"","x":830,"y":180,"wires":[["79ec9b17.a46b5c"]]},{"id":"79ec9b17.a46b5c","type":"function","z":"1fe2e6f5.206b79","name":"Slot got value?","func":"var cost = msg.payload;\n\n\nvar controlMsg = {\n payload : \"refetch\"\n}\n\nif (cost === 0) {\n msg.email = 0;\n controlMsg.topic = \"start\"; //start cron\n}\nelse {\n msg.email = 1;\n controlMsg.topic = \"pause\"; //pause cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1040,"y":180,"wires":[["571c4497.4087b4"],["3263b051.51d618"]]},{"id":"9acc5590.ddcda","type":"debug","z":"1fe2e6f5.206b79","name":"eMail","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":240,"wires":[]},{"id":"b4b95892.d10a4","type":"link out","z":"1fe2e6f5.206b79","name":"Send email out","links":["f39ea767.1fbcb8"],"x":975,"y":300,"wires":[]},{"id":"f39ea767.1fbcb8","type":"link in","z":"1fe2e6f5.206b79","name":"Send email in","links":["b4b95892.d10a4"],"x":295,"y":300,"wires":[["cbe9d1da.c9a8e"]]},{"id":"18a666f5.6286d1","type":"inject","z":"1fe2e6f5.206b79","name":"evening stop","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"email","v":"0","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"pause","payload":"evening","payloadType":"str","x":350,"y":340,"wires":[["cbe9d1da.c9a8e"]]},{"id":"5fd8791f.193b88","type":"function","z":"1fe2e6f5.206b79","name":"msg.email","func":"if (msg.email === 1) {\n msg.payload = \"evening\";\n msg.topic = \"start\"; //start cron\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":260,"wires":[["cbe9d1da.c9a8e"]]},{"id":"cbe9d1da.c9a8e","type":"cronplus","z":"1fe2e6f5.206b79","name":"send_eMails","outputField":"topic","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"Morning","topic":"morning","payloadType":"str","payload":"0800hrs to 2300hrs today","expressionType":"cron","expression":" 0 0 8 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"evening","topic":"evening","payloadType":"str","payload":"now until 2300hrs tomorrow","expressionType":"cron","expression":"* 18-23 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":590,"y":280,"wires":[["3d33c899.9b5ce"],[]]},{"id":"fcbd07a9.14b7","type":"change","z":"1fe2e6f5.206b79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"message","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"subject","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":260,"wires":[["9acc5590.ddcda","71e9c04b.a13f6"]]},{"id":"3d33c899.9b5ce","type":"function","z":"1fe2e6f5.206b79","name":"send email. pause cron","func":"var slots = msg.topic;\n\n\nvar controlMsg = {\n payload : \"evening\"\n}\n\n\n msg.subject = \"Octopus slots from \" + slots;\n msg.message = \"Some message here\"\n msg.to = \"Joe <recipient@example.com>\";\n msg.from = \"Node Red <sender@example.com>\";\n \n \n \n controlMsg.topic = \"pause\"; //pause cron\n\n\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":810,"y":280,"wires":[["fcbd07a9.14b7"],["b4b95892.d10a4"]]},{"id":"f387424f.05f2a8","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["45a2afc9.2ddac","571c4497.4087b4"],"x":295,"y":260,"wires":[["5fd8791f.193b88"]]},{"id":"71e9c04b.a13f6","type":"function","z":"1fe2e6f5.206b79","name":"Log2Context","func":"var contextname = \"cron_log\";\n\nvar log = flow.get(contextname) || [];\n\nvar logEntry = {\n msg: RED.util.cloneMessage(msg),\n time: new Date()\n}\n\nlog.push(logEntry);\n\nflow.set(contextname, log);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1250,"y":280,"wires":[[]]},{"id":"571c4497.4087b4","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["f387424f.05f2a8"],"x":1175,"y":160,"wires":[]},{"id":"b85323d.a697ee","type":"inject","z":"1fe2e6f5.206b79","name":"Push to Test!","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":180,"wires":[["47351e64.6b203"]]},{"id":"6dd78b49.d8ae7c","type":"inject","z":"1fe2e6f5.206b79","name":"refetch stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"pause","payload":"refetch","payloadType":"str","x":110,"y":220,"wires":[["ba71f6ac.c921d"]]},{"id":"65a231aa.96568","type":"comment","z":"1fe2e6f5.206b79","name":"Send an email @ 0800, and when data first becomes available after fetching","info":"","x":810,"y":220,"wires":[]},{"id":"6e737abc.a8cef4","type":"influxdb","z":"","hostname":"localhost","port":"8086","protocol":"http","database":"","name":"","usetls":false,"tls":""}]