I was struggling with this myself today, and cobbled together bits of knowledge from a number of posts. Much thanks to @rlkoshak for his very helpful posts and knowledge!
- OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules
- How to start rule programming in OH3? - #9 by rlkoshak
This is what I settled on:
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
if (this.timer != undefined) {
this.timer.cancel();
this.timer = undefined;
}
function turnOff() {
events.sendCommand("Bath1_Fan_Switch", OFF);
this.timer = undefined;
}
this.timer = ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(60), turnOff);