I try to get the state from an item in a DSL Rule:
var String intentItem = transform("JSONPATH", "$.slots[0].value.value", ChangeLightState_ChangeLightState.state.toString)
intentItem.sendCommand("ON") //works
var state = intentItem.state.toString //does not work
So I get the name of the item via MQTT.
Then I can change the state via sendCommand but I am not able to get the state. I get the following error: The method or field state is undefined for the type String
(I would assume the same error for sendCommand)
I already had a look on ScriptServiceUtil but while adding the ‘import’ it complains that import is undefined. It is like it is not supported in DSL Rules.
Do I need to install something or do I need other configs in order to use import statements in DSL Rules?
For others to see a working example in DSL Rule GUI:
var String intentItemString = transform("JSONPATH", "$.slots[0].value.value", ChangeLightState_ChangeLightState.state.toString)
val intentItem = org.openhab.core.model.script.ScriptServiceUtil.getItemRegistry.getItem(intentItemString)
var state = intentItem.state.toString //works
I already had a look on Script Service Util but while adding the ‘import’ it complains that import is undefined. It is like it is not supported in DSL Rules. Tellpizzahut
There are multiple openHAB versions in common use. This affects where you have to get imports from. Which are you using?
There are file based DSL rules, and UI based DSL rules. These behave differently so far as imports goes. Which are you using?