Rule "Warnung bei offener Tür" funktioniert nicht
Verfasst: 4. Mär 2021 15:44
Ich habe eine kleine Rule geschrieben, die mich benachrichtigen soll, wenn die Haustür länger offen ist:
Das funktioniert soweit bis der timer abläuft und eigentlich die "sendOpenNotification()" aufrufen sollte. Da kommt dann:
Da werde ich nicht ganz schlau draus. Irgendwas scheint mit dem Parameter sendOpenNotification() der createTimer Methode nicht zu stimmen. Ich weiß leider nicht, was die Methode eigentlich erwartet, da das etwas openhab internes ist, habe ich da keine Referenz zu. Ich habe das aus einem Beispiel übernommen.
Code: Alles auswählen
var ScriptExecution = Java.type("org.openhab.core.model.script.actions.ScriptExecution");
var ZonedDateTime = Java.type("java.time.ZonedDateTime");
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
function sendOpenNotification() {
logger.info("Send door open notification");
NotificationAction.NotificationAction.sendNotification("***@***.de","Haustür offen");
this.timer = undefined;
}
if(event.itemState === CLOSED){
if (this.timer !== undefined) {
this.timer.cancel();
this.timer = undefined;
}
}
else if(event.itemState === OPEN){
this.timer = ScriptExecution.createTimer(ZonedDateTime.now().plusSeconds(5), sendOpenNotification);
logger.info("Start door open timer");
}
Code: Alles auswählen
2021-03-04 15:32:47.148 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
jdk.nashorn.internal.runtime.ECMAException: TypeError: Cannot read property "sendNotification" from undefined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.runtime.Undefined.get(Undefined.java:161) ~[jdk.scripting.nashorn:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$430$322$\^eval\_.sendOpenNotification(<eval>:9) ~[?:?]
at jdk.nashorn.javaadapters.org_eclipse_xtext_xbase_lib_Procedures$Procedure0.apply(Unknown Source) ~[?:?]
at org.openhab.core.model.script.actions.ScriptExecution.lambda$0(ScriptExecution.java:82) ~[?:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:166) ~[bundleFile:?]
at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:76) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]