I knew there was easier logic!! Decrement the loop!!
[{"id":"0f754cfa5d2f11b3","type":"tab","label":"Heating Event driven switch","disabled":false,"info":"","env":[]},{"id":"e55ff2a0097c1601","type":"comment","z":"0f754cfa5d2f11b3","name":"filepath","info":"// file path with / at the end\nvar filepath = \"/mnt/array1/NodeRed/AutoBackups/\"; // This is the path\nvar localfilepath = \"/home/pi/node-red-storage/\";\n//\"220129_nodered_backup.zip\"","x":310,"y":60,"wires":[]},{"id":"d22324c7f6658b15","type":"inject","z":"0f754cfa5d2f11b3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"30","topic":"","payload":"","payloadType":"date","x":140,"y":100,"wires":[["236e0b92934aa646","f4961ee17e09efa4"]]},{"id":"236e0b92934aa646","type":"file in","z":"0f754cfa5d2f11b3","name":"HW times file","filename":"/home/colin/node-red-storage/HWt.imes","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":310,"y":100,"wires":[["2c5e99851d92fd90"]]},{"id":"2c5e99851d92fd90","type":"csv","z":"0f754cfa5d2f11b3","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":450,"y":100,"wires":[["90934bf9f347ac05"]]},{"id":"347f7f877f9020c9","type":"catch","z":"0f754cfa5d2f11b3","name":"","scope":null,"uncaught":false,"x":620,"y":60,"wires":[["1835d45f1fd96af9"]]},{"id":"1835d45f1fd96af9","type":"debug","z":"0f754cfa5d2f11b3","name":"debug 98","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":60,"wires":[]},{"id":"90934bf9f347ac05","type":"join","z":"0f754cfa5d2f11b3","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":100,"wires":[["a7c6c2c983db796b"]]},{"id":"e314060fc6833351","type":"debug","z":"0f754cfa5d2f11b3","name":"debug 99","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":160,"wires":[]},{"id":"a7c6c2c983db796b","type":"change","z":"0f754cfa5d2f11b3","name":"","rules":[{"t":"set","p":"#:(storeInFile)::timesHW","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":100,"wires":[["2a322bc99fb6d87c"]]},{"id":"2a322bc99fb6d87c","type":"function","z":"0f754cfa5d2f11b3","name":"set HW deg","func":"delete msg.payload;\ndelete msg.topic;\ndelete msg.filename;\ndelete msg.columns;\n\nlet length;\nlet setHours;\nlet setMinutes;\nlet eventTime;\nlet timeEvent;\nlet payload = global.get('timesHW', \"storeInFile\");\nlet tempDesired = global.get('tempDesiredHW', \"storeInFile\") || 0;\n\n//Get current day start and end timestamp\nlet dateNow = Date.now();\nlet timeFrom = new Date(dateNow).setHours(0, 0, 0, 0);\nlet timeTo = new Date(dateNow).setHours(23, 59, 59, 0)\n//msg.payload = timeTo; //dateNow + \" + \" + timeFrom + \" + \" + timeTo;\n//msg.timeFrom = timeFrom;\n//msg.timeTo = timeTo;\n\n//let i=3;\n\n//Add offset, iterate until file time < current time\nfor (let i = payload.length - 1; i >= 0; i--) {\n eventTime = payload[i].time;\n // msg.eventTime = eventTime\n setHours = eventTime.slice(0, eventTime.indexOf(\":\"));\n setMinutes = eventTime.slice(eventTime.indexOf(\":\") + 1);\n timeEvent = new Date(timeFrom).setHours(setHours, setMinutes, 0, 0); //Date from midnight this morning\n msg.timeEvent = timeEvent;\n// msg.payload = timeFrom + \" + \" + timeEvent + \" + \" + timeTo;\n msg.index = i;\n\n\n tempDesired = payload[i].desired;\n msg.tempDesired = tempDesired;\n msg.dateNow = dateNow;\n // msg.timeThen = timeThen;\n\n if (dateNow > timeEvent) {\n global.set('tempDesiredHW', tempDesired, 'storeInFile');\n node.status({ text: timeEvent + \" | \" + tempDesired });\n return msg;\n }\n\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":100,"wires":[["b1e54be8e7b858ad"]]},{"id":"b1e54be8e7b858ad","type":"debug","z":"0f754cfa5d2f11b3","name":"debug 100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1070,"y":100,"wires":[]},{"id":"f4961ee17e09efa4","type":"file in","z":"0f754cfa5d2f11b3","name":"CH times file","filename":"/home/colin/node-red-storage/CHt.imes","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":310,"y":140,"wires":[["4d488e485025ed7f"]]},{"id":"4d488e485025ed7f","type":"csv","z":"0f754cfa5d2f11b3","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":450,"y":140,"wires":[["392fde4e9b6b416b"]]},{"id":"392fde4e9b6b416b","type":"join","z":"0f754cfa5d2f11b3","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":140,"wires":[["22639536baf79828"]]},{"id":"22639536baf79828","type":"change","z":"0f754cfa5d2f11b3","name":"","rules":[{"t":"set","p":"#:(storeInFile)::timesCH","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":140,"wires":[["dd79303f44f035c0"]]},{"id":"dd79303f44f035c0","type":"function","z":"0f754cfa5d2f11b3","name":"set CH deg","func":"delete msg.payload;\ndelete msg.topic;\ndelete msg.filename;\ndelete msg.columns;\n\nlet length; \nlet setHours;\nlet setMinutes;\nlet eventTime;\nlet timeEvent;\nlet payload = global.get('timesCH', \"storeInFile\");\nlet tempDesired = global.get('tempDesiredCH', \"storeInFile\")||0;\n\n//Get current day start and end timestamp\nlet dateNow = Date.now();\nlet timeFrom = new Date(dateNow).setHours(0, 0, 0, 0);\nlet timeTo = new Date(dateNow).setHours(23, 59, 59, 0)\n//msg.payload = timeTo; //dateNow + \" + \" + timeFrom + \" + \" + timeTo;\n//msg.timeFrom = timeFrom;\n//msg.timeTo = timeTo;\n\n//let i=3;\n\n//Add offset, iterate until file time < current time\nfor (let i = payload.length - 1; i >= 0; i--) {\n eventTime = payload[i].time;\n// msg.eventTime = eventTime\n setHours = eventTime.slice(0, eventTime.indexOf(\":\"));\n setMinutes = eventTime.slice(eventTime.indexOf(\":\") + 1);\n timeEvent = new Date(timeFrom).setHours(setHours,setMinutes,0,0); //Date from midnight this morning\n msg.timeEvent = timeEvent;\n// msg.payload = timeFrom + \" + \" + timeEvent + \" + \" + timeTo;\n msg.index = i;\n\n\n tempDesired = payload[i].desired;\nmsg.tempDesired = tempDesired;\nmsg.dateNow = dateNow;\n// msg.timeThen = timeThen;\n\n if (dateNow > timeEvent){\n global.set('tempDesiredCH', tempDesired, 'storeInFile');\n node.status({ text: timeEvent + \" | \" + tempDesired });\n return msg; \n }\n\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":160,"wires":[["e314060fc6833351"]]}]