Javascript ECMA 11 action question

I have been reading over the Javascript documentation to learn about openHAB’s Javascript language. It’s been challenging for me as I am not a programmer and I first had to figure out how to interpret the documentation :woozy_face:. I am slowly accomplishing this and have a decent understanding of putting together items statements.

I also read over the Semantics actions section. There I found the following statement:
Semantics.getLocation​(Item item)

I have been experimenting with this action in a test script. Through a lot of trial and error I have the following script:

var Semantics = Java.type("org.openhab.core.model.script.actions.Semantics");
const myitem = items.getItem('BedroomSensor_Luminance');'Script test', 'Item: ' + + ' location: ' + actions.Semantics.getLocation(myitem))

Unfortunately the script fails because of the actions.Semantics.getLocation statement. I’ve tried replacing (myitem) with (‘BedroomSensor_Luminance’), (BedroomSensor_Luminance), (item, ‘BedroomSensor_Luminance’) but nothing works. The script always fails.

What is the proper way to enter the item in that method?

The error returned for actions.Semantics.getLocation(myitem) is:

Unsupported operation identifier 'getTags' and  object '[object Object]'(language: JavaScript, type: Item). Identifier is not executable or instantiable

And when I try actions.Semantics.getLocation(‘BedroomSensor_Luminance’):

TypeError: invokeMember (getLocation) on org.openhab.core.model.script.actions.Semantics failed due to: Cannot convert 'BedroomSensor_Luminance'(language: Java, type: java.lang.String) to Java type 'org.openhab.core.items.Item': Unsupported target type

when I remove the quotes and use (BedroomSensor_Luminance):

ReferenceError: "BedroomSensor_Luminance" is not defined

Thanks for any clues.

JavaScript and Java are 2 different languages.

ECMAScript 11 (i.e. the JavaScript Scripting add-on) comes with a library. See actions - Documentation which is linked to from the add-on’s docs.

You don’t need to import the class, it’s already imported in the actions namespace.


Looking at the docs, it appears to require an Item, not just the Item name :frowning: . But it needs the actual openHAB Item, not the openhab-js JavaScript wrapper around the Java Item Object.

For now, you’ll have to use the following:


It shouldn’t be this way. I’ll file an issue. I’m not sure the best place to fix this though, in openhab-js or in core.

Indeed and OP I’m sure is fully aware of that. But OH allows users to write rules in JavaScript (ECMAScript). And there is indeed documentation for writing those rules here and here and it’s clear that OP has been reading them and that is what OP is referring to.


Thanks Rich, that did the trick.