KristianO, Ok, I've been running the code for 3 days now and it is turning off and on stuff morning, evening and nights - so it seems to be performing like a clock. I made some simplifications (less is more) and the code I use now is included below (incl. my schedules) Please login or register to see this code. Still the limitations that the sunrise is typically one day behind (not a big deal for me) and that you need to sort the schedules chronological to assure the the catchup logic makes sens