OH3: Scripts do not work

All I can offer at this point is at one point years ago when I started experimenting with the NGRE (which is what this is) I got the notifications working using

var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
NotificationAction.sendNotification("rlkoshak@gmail.com", "This is a directed notification");
NotificationAction.sendNotification("rlkoshak@gmail.com", "This is a detailed directed notification", "light", "WARN"); // TODO what is severity? "light" is the icon
NotificationAction.sendBroadcastNotification("This is a broadcast test");
NotificationAction.sendBroadcastNotification("This is a detailed brodcast test", "light", "WARN")
NotificationAction.sendLogNotification("This is a log notification");
NotificationAction.sendLogNotification("This is a detailed log notification", "light", "WARN");
3 Likes

Yes there is something wrong with NGRE engine on OH3 …
For me doesn’t work your way:

var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.core.model.script.LowBatteryTrigger");
logger.debug("Trigger Started");
var NotificationAction = org.openhab.io.openhabcloud.NotificationAction;
if (NotificationAction == null)
  {
      logger.debug("NULL");
  }
else
  {
      NotificationAction.sendNotification("EMAIL", "This is a directed notification");
      logger.debug("SEND");
  }
logger.debug("Trigger Finished");

So NotificationAction is not null but it still crash:

2020-11-09 19:14:25.581 [DEBUG] [.core.model.script.LowBatteryTrigger] - Trigger Started
2020-11-09 19:14:25.626 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: script
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.openhab.io.openhabcloud.NotificationAction.sendNotification
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:531) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:456) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:413) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:409) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:162) ~[jdk.scripting.nashorn:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1179) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1031) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1047) [bundleFile:?]
        at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:305) [bundleFile:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) [bundleFile:1.0.9]
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) [bundleFile:1.0.9]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) [bundleFile:1.0.9]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) [bundleFile:1.0.9]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) [bundleFile:1.0.9]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) [bundleFile:1.0.9]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) [bundleFile:1.0.9]
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) [bundleFile:1.0.9]
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301) [bundleFile:1.0.9]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220) [bundleFile:1.0.9]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [bundleFile:3.1.0]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:276) [bundleFile:1.0.9]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:852) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:544) [bundleFile:9.4.20.v20190813]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:536) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1581) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1307) [bundleFile:9.4.20.v20190813]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:482) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1549) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1204) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [bundleFile:9.4.20.v20190813]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [bundleFile:?]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.Server.handle(Server.java:494) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:374) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:268) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:426) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:320) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:158) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) [bundleFile:9.4.20.v20190813]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) [bundleFile:9.4.20.v20190813]
        at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.ClassNotFoundException: org.openhab.io.openhabcloud.NotificationAction.sendNotification
        at jdk.nashorn.internal.runtime.NativeJavaPackage.classNotFound(NativeJavaPackage.java:163) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.scripts.Script$Recompilation$117$\^eval\_$cu1$restOf.:program(<eval>:23) ~[?:?]
        at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527) ~[jdk.scripting.nashorn:?]
        ... 70 more

Same thing happen when I test on 3.0.0-SNAPSHOT - Build #2006 on Windows PC… DSL work ECMA not.
Im found in source codes that cloud plugin need dependenncy org.apache.servicemix.bundles.jsr305 if that mean something(DSL or ECMA) …

In JavaScript you would want to test for undefined.

if(NotificationAction === undefined)

It doesn’t.

Im get it working on both DSL and ECMA scripts. For some strange reason after installation of openhab cloud addon openhab server MUST be restarted otherwise sendNotification do not work in ECMA and function is visible on DSL but do not send anything and in log write “No connection, notification is not sent” but cloud connection work normaly and over wan I normaly see sitemaps…
So only script access didn’t work until restart after addon installation… Im test this few times and can confirm that this can be reproduced… Because Im develop openhab addon on my computer and add access to rest api with token authentication it didn’t work because Im rebuild&install addon without openhab restart and push messages never didn’t work.
Now Im make ECMA Rule script which ill send push message when battery will be under 30% and send push notification when it will be full(99% or 100%)… Last two messages are how they will look and older are test messages before removing some parts of item name…

Did you create the rule before or after installing the addon? I ask because the first time the rule is run it is given a context and each subsequent run it gets the same context. This is a good thing as it gives us a place (at least in ECMAScript) to store data from one run to the next of the rule. But this context likely does not get updated when new Actions are installed. If this is in fact what happened, it might be enough to just open the rule for editing and make some minor change (e.g. add a space) and save it. You may not even need to make a change, just re-save it. That will recreate the rule and therefore recreate the context with the new addon now being available. You can see the rule being recreated in events.log.

Im not sure and can’t confirm or deny… :slight_smile: But if remember right cloud addon has been installed because Im also create few new scripts… But Im sure edit, make changes and save rule when plugin has been already installed…

Thanks Rich for that. I was looking all over the place for a way to use sendNotification in ECMA.
Did you - or anyone - find out, what kind of severity there is?

sorry @rlkoshak

…and sorry @rlkoshak, if I just sent you a notification, I copied your code and due to a crash in the OH3-GUI I had to re-copy it and forgot to change your email to mine…

I want to solve!!!
it’s the names of the icons: Icons | openHAB

Yes icon name and it will show you different icons…

Great find! Thanks for persevering. I still haven’t done much with notifications yet. I’m mainly using email right now but need to get notifications back running. Being able to control the icon could be very useful.

Yes, I use notifications for warnings (weather warnings, catastrophes, doorbell, …) in parallel with the longer email, but I find it useful to get some “alerts” right away.
btw: The icons are only within the App and not embedded in the push-notification (at least with Android); but I’d like to think it is not possible to push other information than text…

For me I use notifications for most stuff during the day. But when I’m asleep I only allow high priority alerts and move everything else into email.

1 Like

Icons are normaly visible in notifications on android… Check my post from 10.11.2020 in this thread with screenshots(low battery notification)…

you’re absolutely right! perhaps I saw some tests in which i tried typical “severity” terms like “heavy”…
#cool

Hi, I have a similar rule to the opening topic, and can’t get to work…what I’m doing wrong? I already know that the trigger is not the problem, because the rule stops working if I ad the but only if part in gui:

triggers:
  - id: "1"
    configuration:
      itemName: DimmerKuechenlicht
    type: core.ItemStateUpdateTrigger
conditions:
  - id: "4"
    configuration:
      itemName: DimmerKuechenlicht
      operator: ">"
      state: "80"
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: Arbeitsplattenlicht_Switch
      command: ON
    type: core.ItemCommandAction
  - inputs: {}
    id: "3"
    configuration:
      itemName: Dunstabzugshaube
      command: ON
    type: core.ItemCommandAction

An aeotec dimmer should switch on other switches when above a certain value…
This format worked for me though but I want to use new OH3 Rules =) -> (This is an old rule with differnt item names):

rule "Kuechenbeleuchtung Regel"
when
    Item Dimmer_Kuechenlicht_Esstischlicht received update
then
    if (Dimmer_Kuechenlicht_Esstischlicht.state > 80) {
    Dunstabzugshaube.sendCommand(ON)
    Schalter_Arbeitsplattenlicht_Kueche.sendCommand(ON)
    }
    else {
    Dunstabzugshaube.sendCommand(OFF) 
    Schalter_Arbeitsplattenlicht_Kueche.sendCommand(OFF)
    }
end

Is this maybe related and an issue with rules? See here: TTS on OH3 in Rules and Main-Ui

With 3.2.0-M1 I got the error

ScriptEngine for language ‘application/vnd.openhab.dsl.rule’ could not be found for identifie

This had been seen some earlier as saw in gitHub.

First error in log about 1 second after entry Rule engine startet. So seems like startlevel reacting to fast?