JSScript: event.itemName == "ON" does not work?

running OH4.2.2-releas on openHABian.

I’d like to check if the change to an item is “ON” or not with this code:

configuration: {}
triggers:
  - id: "1"
    configuration:
      groupName: PL12Homeserver
    type: core.GroupStateChangeTrigger
  - id: "3"
    configuration:
      cronExpression: 0 0 0/6 * * ? *
    type: timer.GenericCronTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >
        if(event.itemName != undefined) {
          // Trigger was itemChange
          console.info("DEBUG: Docker item " + event.itemName + " hat Status " + event.itemState + " und alten Status " + event.oldItemState);
            if (event.itemState == "ON") {
              console.info("State is ON");
            } else {
              console.info("State is not ON");
            }
        }
    type: script.ScriptAction

But regardless the state, it’s always in the else part?

2024-11-14 11:29:38.434 [INFO ] [utomation.script.ui.MonitoringDocker] - DEBUG: Docker item HSRV_GrafanaOnline hat Status ON und alten Status OFF
2024-11-14 11:29:38.435 [WARN ] [utomation.script.ui.MonitoringDocker] - State is not ON

I don’t know if this is how it is supposed to be but I use event.itemState.toString() which works fine

1 Like

sorry, that event.itemState.state was an old test, that did not work. (changed it in my post to avoid confusion for other users)

But the “toString()” did the job. thanks!

The event Object in UI rules is the original Java event Object meaning all the properties of it are Java too. JavaScript Scripting - Automation | openHAB

There’s no opportunity for the add-on to intercept and convert the event to a JS Object so itemState is going to be a Java State, not a string like the state is represented everywhere else in a JS rule. You also won’t have numbericState, quantityState, etc.