OH3: Scripts do not work

Nothing didn’t work :slight_smile:
Now Im do everything as written in tutorial but they do not work also HelloWorld.js do not write into log every 10 seconds…
First Im enable logging:
jsr223 │ DEBUG
org.openhab.core.automation │ DEBUG

Then Im shutdown openhab and copy files.

Im copy content of Core folder into openhab:
automation_folder

Then Im rename configuration file:

configuration

And copy demo script to personal folder:

personal

Then Im start openhab and log:tail

19:01:09.577 [INFO ] [b.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/Ljubljana'.
19:01:09.610 [INFO ] [b.core.internal.i18n.I18nProviderImpl] - Location set to 'REMOVED'.
19:01:09.620 [INFO ] [b.core.internal.i18n.I18nProviderImpl] - Locale set to 'sl_SI'.
19:01:11.028 [DEBUG] [ript.internal.ScriptEngineManagerImpl] - Initialized a generic ScriptEngineFactory for Oracle Nashorn (11.0.9): supports ECMAScript (ECMA - 262 Edition 5.1) with file extensions [js], names [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], and mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
19:01:11.038 [DEBUG] [ript.internal.ScriptEngineManagerImpl] - Initialized a custom ScriptEngineFactory for Oracle Nashorn (11.0.9): supports ECMAScript (ECMA - 262 Edition 5.1) with file extensions [js], names [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], and mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript]
19:01:16.938 [WARN ] [org.openhab.core.net.NetUtil         ] - Found multiple local interfaces - ignoring REMOVED
19:01:25.739 [DEBUG] [ovider.AbstractResourceBundleProvider] - Parse rules from bundle 'org.openhab.core.automation' 
19:01:25.739 [DEBUG] [ovider.AbstractResourceBundleProvider] - Parse rules from bundle 'org.openhab.core.automation.module.script.rulesupport' 
19:01:25.870 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added CoreModuleHandlerFactory
19:01:25.870 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added TimerModuleHandlerFactory
19:01:25.878 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptModuleHandlerFactory
19:01:25.880 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptedCustomModuleHandlerFactory
19:01:25.880 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptedPrivateModuleHandlerFactory
19:01:25.880 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added AnnotatedActionModuleTypeProvider
19:01:25.880 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added AnnotatedThingActionModuleTypeProvider
19:01:25.880 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added EphemerisModuleHandlerFactory
19:01:28.624 [DEBUG] [ript.internal.ScriptEngineManagerImpl] - Initialized a custom ScriptEngineFactory for null (null): supports Rule DSL (v1) with file extensions null, names null, and mimetypes [application/vnd.openhab.dsl.rule]
19:01:28.635 [INFO ] [b.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
19:01:31.389 [DEBUG] [re.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added MediaModuleHandlerFactory
19:01:31.481 [INFO ] [org.openhab.ui.internal.UIService    ] - Started UI on port 8080
19:01:31.974 [INFO ] [hab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
19:01:32.148 [DEBUG] [io.openhabcloud.internal.CloudService] - openHAB Cloud connector activated
19:01:32.148 [DEBUG] [io.openhabcloud.internal.CloudService] - remoteAccessEnabled is not set, keeping value 'true'
19:01:32.157 [DEBUG] [io.openhabcloud.internal.CloudService] - API Token = REMOVED
19:01:32.167 [DEBUG] [io.openhabcloud.internal.CloudService] - Using secret at 'c:\openhab\userdata\openhabcloud\secret' with content 'REMOVED'
19:01:32.167 [DEBUG] [io.openhabcloud.internal.CloudService] - UUID = REMOVED, secret = REMOVED
19:01:32.179 [DEBUG] [io.openhabcloud.internal.CloudService] - Using secret at 'c:\openhab\userdata\openhabcloud\secret' with content 'REMOVED'
19:01:33.378 [DEBUG] [.io.openhabcloud.internal.CloudClient] - Socket.IO connected
19:01:33.378 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = REMOVED, base URL = http://localhost:8080)

If I create simple Script in UI and run it:

var OPENHAB_CONF = Java.type('java.lang.System').getenv('OPENHAB_CONF');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');

if (Ping.checkVitality("10.5.5.5", 0, 5000)) {
    LogAction.logInfo("Rules", "Server is online");
} else {
    LogAction.logInfo("Rules", "Server is offline");
}

It still crash:

19:16:16.416 [INFO ] [smarthome.event.RuleUpdatedEvent     ] - Rule '71a2abce18' has been updated.
19:16:23.261 [DEBUG] [ript.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'application/javascript' with identifier: 9f0e7e1f-6265-444d-98c0-eeb15f4de628
19:16:23.715 [WARN ] [re.automation.internal.RuleEngineImpl] - Fail to execute action: script
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.Exec cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
        at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:531) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1438) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.runtime.Context.load(Context.java:962) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.objects.Global.load(Global.java:1720) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.scripts.Script$Recompilation$37$\^eval\_$cu1$restOf/0x00000007c0dfd040.:program(<eval>:2) ~[?:?]
        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:?]
        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.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.eclipse.smarthome.model.script.actions.Exec cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) ~[org.eclipse.osgi-3.12.100.jar:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:564) ~[org.eclipse.osgi-3.12.100.jar:?]
        at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176) ~[bundleFile:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:588) ~[?:?]
        at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192) ~[bundleFile:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:?]
        at java.lang.Class.forName(Class.java:398) ~[?:?]
        at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1180) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:546) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:326) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:318) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314) ~[jdk.scripting.nashorn:?]
        at jdk.nashorn.internal.scripts.Script$Recompilation$41$16A$actions$cu1$restOf.L:3(file:/c:/openhab/conf/automation/lib/javascript/core/actions.js:23) ~[?:?]
        at jdk.nashorn.internal.scripts.Script$Recompilation$39$actions.:program(file:/c:/openhab/conf/automation/lib/javascript/core/actions.js:3) ~[?:?]
        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:?]
        ... 73 more
19:16:24.465 [DEBUG] [re.automation.internal.RuleEngineImpl] - The rule '71a2abce18' is executed.

This is my developing Windows 10 computer but same happen on linux openhab server…

Im try sendNotification with official 3.0.0M2(Installed from UI) and 3.0.0.SNAPSHOT(Installed manualy) on linux server and on windows pc and it crash wirh ClassNotFoundException …

Im also myself modify and build openhabcloud addon from sources and make it simple for debuging only and make it by new RuleAction way like in Mail or other addons but still didn’t work…
NotificationAction.java:

/**
 * Copyright (c) 2010-2020 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.io.openhabcloud;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.io.openhabcloud.internal.CloudHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class provides static methods that can be used in automation rules
 * for sending notifications to the native apps.
 *
 * @author Victor Belov - Initial contribution
 * @author Kai Kreuzer - migrated code to ESH APIs
 *
 */

@ThingActionsScope(name = "openhabcloud")
@NonNullByDefault
public class NotificationAction implements ThingActions {

    private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);

    private @Nullable CloudHandler handler;

    @RuleAction(label = "send a push message", description = "Sends a push message.")
    public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendNotification(
            @ActionInput(name = "userId") @Nullable String userId,
            @ActionInput(name = "message") @Nullable String message) {
        return sendNotification(userId, message, null, null);
    }

    @RuleAction(label = "send a push message", description = "Sends a push message.")
    public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendNotification(
            @ActionInput(name = "userId") @Nullable String userId,
            @ActionInput(name = "message") @Nullable String message, @ActionInput(name = "icon") @Nullable String icon,
            @ActionInput(name = "severity") @Nullable String severity) {

        if (userId == null) {
            logger.warn("Cannot send push message as userId is missing.");
            return false;
        }

        if (message == null) {
            logger.warn("Cannot send push message as message is missing.");
            return false;
        }

        try {

            final CloudHandler handler = this.handler;
            if (handler == null) {
                logger.info("Handler is null, cannot send push message.");
                return false;
            } else {
                logger.info("Push Message is send.");
                return true; // handler.sendMail(builder.build());
            }
        } catch (Exception e) {
            logger.warn("Could not send notification: {}", e.getMessage());
            return false;
        }
    }

    @Override
    public void setThingHandler(@Nullable ThingHandler handler) {
        if (handler instanceof CloudHandler) {
            this.handler = (CloudHandler) handler;
        }
    }

    @Override
    public @Nullable ThingHandler getThingHandler() {
        return handler;
    }
}

CloudHandler.java

package org.openhab.io.openhabcloud.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@NonNullByDefault
public class CloudHandler extends BaseThingHandler {

    private final Logger logger = LoggerFactory.getLogger(CloudHandler.class);

    public CloudHandler(Thing thing) {
        super(thing);
    }

    @Override
    public void handleCommand(ChannelUID channelUID, Command command) {
    }

    @Override
    public void initialize() {

        updateStatus(ThingStatus.ONLINE);
    }
}

Hmmm, I thought there was an update to the libraries for that. The LogAction changed names to Log. You can get past this error by editing actions.js and change LogAction to Log.

Does the notify action work if you write a Script Action using Rule DSL? I think sending a notification should be one of the options for choosing an Action for the rule which would not involve writing any code. Is it there? Does it work when you select it?

There is nothing to type or import and the like to use it in Rules DSL. If it doesn’t even work there then something else outside of the rules is the source of the problem.

Im on middle updating windows openhab server to latest snapshot to test if there has been some problem with M1 and M2 version and ECMA scripts and already fixed…
Im try Rule DSL on my linux openhab server and it work.

Sending script:

sendNotification("EMAIL", "This is a directed notification");

Log:

2020-11-09 18:48:46.939 [DEBUG] [b.io.openhabcloud.NotificationAction] - sending notification 'This is a directed notification' to user EMAIL
2020-11-09 18:48:46.940 [DEBUG] [o.openhabcloud.internal.CloudService] - Sending message 'This is a directed notification' to user id EMAIL

Script run normaly and I receive notification on mobile phone…

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?