'Semi-smart' alarm clock

It that function is being used in a sort, it’s missing the equals condition.

time.toZDT() takes all sorts of inputs and will give you a ZonedDateTime as the result. With no arguments it gives you now. If you pass in a String that matches a time of day, it returns a ZDT with today’s date and the given time. If you pass in an ISO8601 String, it will convert that to a Duration and add that to now. So time.toZDT("08:00") means “08:00 today” and time.toZDT('P1D') means “now plus one day”.

However, if you want to do something like 08:00 tomorrow, I have a method toTomorrow() in OHRT or you can still use the plusDays(): time.toZDT("08:00").plusDays(1).

Consider the following scenario. I work M-F but let’s say that I need to get up earlier on trash days. I create one dayset named “workday” that includes M-F and another dayset named “trash” that only includes Monday. Then I can use something like:

if( actions.Ephemeris.isInDayset("workday") ){
  var alarmTime = (actions.Ephemeris.isInDaySet('trash')) ? time.toZDT('06:00') : time.toZDT('06:30');
}

I can put all the work and school holidays into a custom holidays Ehpemeris configuration file and take it one step further.

if( !actions.Ephemeris.isBankHoliday(0, "path/to/ephemeris.xml") ) {
  if( actions.Ephemeris.isInDayset("workday") ){
    alarmTime = (actions.Ephemeris.isInDaySet('trash')) ? time.toZDT('06:00') : time.toZDT('06:30');
  }
}  

I don’t need to create awkward arrays in the rule to keep track of the days of the week and stuff like that. And if I use the Ephemeris binding I don’t even need to use the actions. I can have all the daysets and holiday stuff in Items.

if(items.BankHoliday.state == "ON") {
  if(items.Weekeday.state == "ON") {
    alarmTime = (items.TrashDay.state == "ON") ? "06:00" : "06:30";
  }
}

And the Items can be used to trigger rules.

You start with an array allewekkers.

We want to filter the Array down to just those entries that match a given criteria. The criteria is implemented in an anonymous function (argument => function code). If the anonymous function were made a regular function it would look like:

function nameFilter(dezewekker) {
  return dezewekker.name.includes(weekdagen[nu.dayOfWeek().value()-2]) 
             && dezewekker.name.includes(wekkersoorten["school"]) 
             || dezewekker.name.includes(wekkersoorten["vakantie"]);
}

...

allewekkers.filter(nameFilter);

The filter returns an array of just those Items that match the criteria. Then we run a forEach on that array. Again, it takes an anonymous function.

See Array - JavaScript | MDN for these and all the other methods available on Arrays with examples. It’s very rare that you would need to create a for(var x = 0...type loop in a rule and the Array functions are almost always going to be easier for future you to understand what’s going on.