items.getItem(event.itemName) returns [object Object]?


i am migrating my jython rules to jsscripting, i encountered a behavior that i can’t explain. Why do I find

[object Object]

in the logfile when calling



Thanks a lot!

The full rule an the output:

let rules_filename = "testscript";
let logger = log(rules_filename);

  name: "testrule",
  triggers: [triggers.ItemStateUpdateTrigger('LaCrosseSensor8_Temperatur')],  
  execute: (event) => {"event.receivedState Kachelofen: " + event.receivedState);"itemName: " + items.getItem(event.itemName));"itemNameGroups: " + items.getItem(event.itemName).groupNames);
	// Logfile:
	// ....
	//2023-01-30 16:26:25.024 [INFO ] [hab.automation.openhab-js.testscript] - event.receivedState Kachelofen: 26 °C
	//2023-01-30 16:26:25.026 [INFO ] [hab.automation.openhab-js.testscript] - itemName: [object Object]
	//2023-01-30 16:26:25.029 [INFO ] [hab.automation.openhab-js.testscript] - itemNameGroups: gLaCrosseTemp,gTemperatureFireAlarm


Do not get confused by items in Jython and items in JS Scripting.

In Jython, items is a dict using Item names as the key and the corresponding Item’s current state as the value. Both the key and the value are Java Objects.

I JS Scripting, items is a JavaScript class that provides a pure JavaScript interface to the ItemRegistry. So, as the docs describe, items.getItem(event.itemName) returns a JavaScript Item Object, not just the current state of the Item.

The equivalent of the Jython items[event.itemName] in JS Scripting is items.getItem(event.itemName).rawState (note that in both cases you get the Java State Object.

See JavaScript Scripting - Automation | openHAB

ah, thanks a lot, i’m slowly getting an insight …