# Send notifications via jython script

**URL:** <https://community.openhab.org/t/send-notifications-via-jython-script/124968>\
**Category:** HABot\
**Created:** [July 28, 2021, 7:08am UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968 "2021-07-28T07:08:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 28, 2021, 7:08am UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/1 "2021-07-28T07:08:27Z")

</div>

Using openhab 3.1 with jython helper libraries.  
Normal actions like Voice.say work fine but WebPushNotificationAction.sendHABotNotification produces the following runtime exception:

```yaml

java.lang.RuntimeException

obj.localizedMessage = u'java.lang.ClassNotFoundException'

obj.stackTrace = array(java.lang.StackTraceElement, [javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:50), javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:55), org.openhab.ui.habot.notification.internal.webpush.PushService.send(PushService.java:156), org.openhab.ui.habot.notification.internal.NotificationService.sendNotification(NotificationService.java:128), org.openhab.ui.habot.notification.internal.NotificationService.broadcastNotification(NotificationService.java:110), org.openhab.ui.habot.notification.WebPushNotificationAction.sendHABotNotificationExt(WebPushNotificationAction.java:101), org.openhab.ui.habot.notification.WebPushNotificationAction.sendHABotNotification(WebPushNotificationAction.java:46), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method), java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62), java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43), java.base/java.lang.reflect.Method.invoke(Method.java:566), org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190), org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:208), org.python.core.PyObject. __call__ (PyObject.java:461), org.python.core.PyObject. __call__ (PyObject.java:465), org.python.pycode._pyx1035.pushReport$11(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py:117), org.python.pycode._pyx1035.call_function(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction. __call__ (PyFunction.java:426), org.python.core.PyMethod. __call__ (PyMethod.java:141), org.python.pycode._pyx1035.handleInvokeLeave$13(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py:142), org.python.pycode._pyx1035.call_function(/etc/openhab/automation/jsr223/python/personal/00_routines_statuschecks.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction. __call__ (PyFunction.java:426), personal.composer$py._wrapper$10(/etc/openhab/automation/lib/python/personal/composer.py:77), personal.composer$py.call_function(/etc/openhab/automation/lib/python/personal/composer.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:150), org.python.core.PyFunction. __call__ (PyFunction.java:426), org.python.core.PyMethod. __call__ (PyMethod.java:141), personal.composer$py.execute$3(/etc/openhab/automation/lib/python/personal/composer.py:28), personal.composer$py.call_function(/etc/openhab/automation/lib/python/personal/composer.py), org.python.core.PyTableCode.call(PyTableCode.java:173), org.python.core.PyBaseCode.call(PyBaseCode.java:306), org.python.core.PyBaseCode.call(PyBaseCode.java:197), org.python.core.PyFunction. __call__ (PyFunction.java:485), org.python.core.PyMethod.instancemethod ___call__ (PyMethod.java:237), org.python.core.PyMethod. __call__ (PyMethod.java:228), org.python.core.PyMethod. __call__ (PyMethod.java:218), org.python.core.PyMethod. __call__ (PyMethod.java:213), org.python.core.PyObject._jcallexc(PyObject.java:3565), org.python.core.PyObject._jcall(PyObject.java:3598), org.python.proxies.personal.composer$__RelayRule$2015.execute(Unknown Source), org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRuleActionHandlerDelegate.execute(SimpleRuleActionHandlerDelegate.java:34), org.openhab.core.automation.module.script.rulesupport.internal.delegates.SimpleActionHandlerDelegate.execute(SimpleActionHandlerDelegate.java:59), org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183), org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:991), org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:90), java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515), java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264), java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304), java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128), java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628), java.base/java.lang.Thread.run(Thread.java:829)])

```

A rule with the classic rule engine that just states:

```yaml

rule "habot.notify"

when 

    Item TestSwitch1 changed to ON

then

    sendHABotNotification("foo")

end

```

produces something quite similar:

2021-07-28 09:06:04.327 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘test-1’ failed: java.lang.ClassNotFoundException in test

On the other hand, a rule clicked together in UI works just fine  
code of the rule:

```yaml
triggers: []
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      body: Ring Ring Ring
    type: habot.WebPushNotificationAction

```

Please help

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 28, 2021, 2:26pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/2 "2021-07-28T14:26:03Z")

</div>

Now I made another rule via UI and gave it some trigger item. This rule now works fine just as the one before if I click “Run” in UI.  
If it is triggered via its “item changed” trigger, I get:

```yaml
2021-07-28 16:24:00.688 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule '8a5d30fc3f': Fail to execute action: 3

```

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [July 28, 2021, 3:42pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/3 "2021-07-28T15:42:11Z")

</div>

In Python you usually need to import the actions. I don’t know if the Helper Libraries import the HABot Actions.

Import `org.openhab.ui.habot.notification.WebPushNotificationAction` and see if that helps it find the action.

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 28, 2021, 4:49pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/4 "2021-07-28T16:49:06Z")

</div>

Helper libs import the actions automatically. You can see in the stack trace that the action gets called but fails in javax.ws.rs.client.ClientBuilder.newBuilder - a method already implemented in Java.

I don’t think this is related to missing imports but I have not much experience with openhab internals…

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 28, 2021, 4:59pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/5 "2021-07-28T16:59:53Z")

</div>

I also added the suggested import to my test rule.  
It now reads

```yaml

import org.openhab.ui.habot.notification.WebPushNotificationAction

rule "habot.notify"
when 
    Item TestSwitch1 changed to ON
then

    WebPushNotificationAction.sendHABotNotification("foo")

end

```

But I still get an error as soon as it is triggered:

```yaml
2021-07-28 18:58:46.409 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-1' failed: java.lang.ClassNotFoundException in test

```

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 28, 2021, 5:23pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/6 "2021-07-28T17:23:47Z")

</div>

Searching the top frame from my exceptions stack brings up other openhab 3 related topics:

[[neeo] Can Not Add Brain - OH3 · Issue #8984 · openhab/openhab-addons · GitHub](https://github.com/openhab/openhab-addons/issues/8984)  
[[tesla] Failed to find JAX-RS Client · Issue #7775 · openhab/openhab-addons · GitHub](https://github.com/openhab/openhab-addons/issues/7775)

Perhaps this is helpful for someone with a little more insight into openhab mechanics…

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [July 29, 2021, 2:22pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/7 "2021-07-29T14:22:07Z")

</div>

After a lot of playing around I suspect a bug in HABot.  
I think notification are broken for openhab 3.x. Can anyone confirm that notifications are working on a similar OH 3 installation?

```yaml
runtimeInfo:
  version: 3.1.0
  buildString: Release Build
locale: de-AT
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.11
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.48+21-CA
  osName: Linux
  osVersion: 5.4.73-1-pve
  osArchitecture: amd64
  availableProcessors: 2
  freeMemory: 90867176
  totalMemory: 702545920

```

---

<div class="post-metadata">

**Author:** ![ysc](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/e480ec/32.png) [@ysc](https://community.openhab.org/u/ysc)\
**Post date:** [August 3, 2021, 2:24pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/8 "2021-08-03T14:24:25Z")

</div>

[GitHub · Where software is built](https://github.com/openhab/openhab-addons/issues/7775) appears really similar indeed.  
Looking at the fix ([[tesla] Use CXF JAX-RS client builder, if available. by kaikreuzer · Pull Request #7789 · openhab/openhab-addons · GitHub](https://github.com/openhab/openhab-addons/pull/7789/files)) it seems that instead of `ClientBuilder.newClient()` here:

> <https://github.com/openhab/openhab-webui/blob/36658f571e67cda3e9ccbc74fb3e1755a2e9f39a/bundles/org.openhab.ui.habot/src/main/java/org/openhab/ui/habot/notification/internal/webpush/PushService.java#L156>

It should get a `ClientBuilder` instance via dependency injection and call `build()` instead now. This supposes some refactoring…

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [August 3, 2021, 2:57pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/9 "2021-08-03T14:57:34Z")

</div>

While this looks like an easy change, I see no way I could do that alone with my level of experience regarding openhab internals.

How could this get more attention so we might get a fix soon? Perhaps it would be enough to give me some guidance on the dependency injection systems used here so I might get a PR together…

---

<div class="post-metadata">

**Author:** ![birnbeidla](https://community.openhab.org/user_avatar/community.openhab.org/birnbeidla/32/114255_2.png) [@birnbeidla](https://community.openhab.org/u/birnbeidla)\
**Post date:** [October 12, 2021, 12:05pm UTC](https://community.openhab.org/t/send-notifications-via-jython-script/124968/10 "2021-10-12T12:05:38Z")

</div>

Still hoping for a solution.  
Trying to keep the thread alive…
