Ha, that’s nice. I was struggling with the same problem. I want to charge the car during the 5 cheapest hours of the night. This can be done well with PBTH, but if you enter a fixed value for the period (10 hours, for example) and the price is lower during the day than at night, the 5 hours will continuously lie in the future. So, it is important to narrow the window so that it stops at the end time.
I managed to do it with a script that calculates the number of remaining hours until the deadline. Ideally, I would also like to shrink the 5 lowest, but for now, it meets my needs.
The script:
// BepaalUren
const date = new Date();
var resterendeUren;
var doelUur = 8;
var huidigUur = date.getHours()+2; //schijnbaar werkt Homey met universele tijd
if (huidigUur > doelUur){ //het doeluur is morgen
resterendeUren = 24-huidigUur+doelUur;
} else {
resterendeUren = doelUur-huidigUur;
}
return resterendeUren;
