okay, help me with the following code block please.
I have an object for cheap charging hours for an battery.:
cheapest5hours
array[5]
0: array[2]
0: 8.564
1: "2022-12-25T05:00:00.000Z"
1: array[2]
0: 8.565000000000001
1: "2022-12-25T04:00:00.000Z"
2: array[2]
0: 8.57
1: "2022-12-25T03:00:00.000Z"
3: array[2]
0: 9.084
1: "2022-12-25T02:00:00.000Z"
4: array[2]
0: 9.27
1: "2022-12-25T06:00:00.000Z"
the object is generated once a day by a node in my flow and stored in flow.cheapest5hours
the data period (where the cheapest 5 hours are available) are from 18:00 (6pm) until 9:00 (am) the next day.
now, in my minutely running flow I check hour and calculate how long my battery needs to charge today.
now, my issue is: I know e.g. my battery needs to charge 5 hours. the cheapest hours are 5,4,3,2,6
they are taken out from the flow.cheapest5hours in the same order to charge only in the not-so-cheap-hours the calculated difference.
but as the list is only as long as the needed calculated charged hours, already past hours need to be deleted out of the list. and in exactly this I am failing.
there is commented code where I tried to achieve this.
var chargehours = [];
if (batteryneedchargehours > 4.99) batteryneedchargehours = 4.99; // only cheapest 5h available
var chghourtmp = 0;
for (var i = 0; i < 5; i++) {
chghourtmp = new Date(cheapest5hours[i][1]).getHours();
chargehours.push(chghourtmp);
//if (hour >= chghourtmp) chargehours.push(chghourtmp);
if (chargehours.length >= batteryneedchargehours) break;
// node.warn("current hour: " + hour + " chghourtmp: " + chghourtmp)
// if ((hour > 17 && chghourtmp >= hour) || (hour < 10 && chghourtmp <= hour)) {
// chargehours.push(chghourtmp);
// } else node.warn("chargehour " + chghourtmp + " already in the past.");
}
my idea was: if var hour (which is current time.getHours() is e.g. 22 (10pm) an entry for 21 is not put put in the list, it would be skipped.
or, if the daybreak was, if hour = 4 (4am) an entry for 3 am is not put in the list.
the code part which switches on / off the charging (works):
if (chargehours.includes(hour)) {
....
}