Rules / ECMA Script - NullPointerException on event handling (ThreadedEventHandler)

Hi all,

I have set up rules that should process trigger events from my hue dimmer switches.

Example from rule 1:

  - id: "1"
      thingUID: hue:0820:001788708acd:8
      channelUID: hue:0820:001788708acd:8:dimmer_switch_event
    type: core.ChannelEventTrigger

When i am trying to test the trigger channel i always get the following error log:

20:22:57.263 [ERROR] [] - Error on event handling.
java.lang.NullPointerException: null
        at java.lang.String.contains( ~[?:?]
        at org.openhab.core.automation.internal.module.handler.ChannelEventTriggerHandler.apply( ~[?:?]
        at ~[bundleFile:?]
        at ~[bundleFile:?]
        at ~[bundleFile:?]
        at$0( [bundleFile:?]
        at [?:?]
20:22:57.276 [INFO ] [org.openhab.rule.dimSwBederoom       ] - reason before if clause is: null
20:22:57.283 [INFO ] [org.openhab.rule.dimSwBederoom       ] - event in if clause is: hue:0820:001788708acd:8:dimmer_switch_event triggered 2002.0
20:22:57.287 [INFO ] [org.openhab.rule.dimSwBederoom       ] - event.event in if clause is: 2002.0
20:22:57.293 [INFO ] [org.openhab.rule.dimSwBederoom       ] - reason is: 2002.0
20:22:57.298 [INFO ] [org.openhab.rule.dimSwBederoom       ] - DIM UP Button SHORT event
20:22:57.311 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'g_Schlafzimmer_Leuchten_Szene' received command 2

Here is the script code i am using:

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID)
var bedroom_Scene = itemRegistry.getItem("g_Schlafzimmer_Leuchten_Szene");
// Proper init to avoid errors when ran without event available
var reason = null"reason before if clause is: " + reason)

if(typeof event !== 'undefined' && typeof event.event !== 'undefined'){"event in if clause is: " + event)"event.event in if clause is: " + event.event)
  reason = event.event
}"reason is: " + reason)

  case "2002.0":"DIM UP Button SHORT event")
    events.sendCommand(bedroom_Scene, 2)
  case "2003.0":"DIM UP Button LONG event")
    events.sendCommand(bedroom_Scene, 2)
  case "3002.0":"DIM DOWN Button SHORT event")
    events.sendCommand(bedroom_Scene, 1)
  case "3003.0":"DIM DOWN Button LONG event")
    events.sendCommand(bedroom_Scene, 1)
  default:"Unknown Switch Event triggered. No action fired!")

As you can see the complete script is working anyway after the error message and commands are executed as wanted.
Did somebody face this NPE yet?

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage Virtual Machine with 4 GB Ram
    • OS: what OS is used and which version Ubuntu Server 20.04
    • Java Runtime Environment: which java platform is used and what version Zulu
    • openHAB version: 3.0.0

I don’t get the NPE, but I get an error, if I use this:

  - id: "1"
      cronExpression: 0 0 7,12,18 * * ? *
    type: timer.GenericCronTrigger
  - id: "2"
      groupName: MQTTMOWASMeldungen
    type: core.GroupStateChangeTrigger
conditions: []
  - inputs: {}
    id: "3"
      type: application/javascript
      script: >-
        var logger =
        Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' +

        var NotificationAction =;

        if (typeof(event) === undefined) {
          // es war ein Cron-Event, also mal alle losschicken
"es ist Cron")
        } else {
          if(event.itemName !== undefined){
            var MowasNr = event.itemName.split("0")[1];
  "Es ist die Nummer: " + MowasNr)

it spits out this, if the cron sets in:

2021-01-16 18:45:08.977 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'MowasInformation' failed: ReferenceError: "event" is not defined in <eval> at line number 8

I’d like to check, if it was the CRON or it was the changing item, which triggered the rule. So I have to do two rules linking to the same script, which makes it a bit more clustered if I could use one rule…

I also tried if(event === undefined){ with the same outcome. Don’t know, if that helps you, but at least I don’t get an NPE out of it… :wink: