All instances of Items are null in Rules (OH2)

Help me out here - What am I doing wrong?

I’m writing rules, but all my references to any items are just giving null as a result. For example, this test rule that triggers when I switch the testItem Switch:

rule "testar"
    Item testItem  received update
    logInfo("testfunktion", "asdfasdfasdf")
    logInfo("testfunktion", testItem.state)

This gives the error:

19:06:02.231 [INFO ] [marthome.event.ItemStateChangedEvent] - testItem changed from ON to OFF
19:06:02.237 [INFO ] [.smarthome.model.script.testfunktion] - asdfasdfasdf
19:06:02.242 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'testar': An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

Of course I’m doing some basic “shit behind the keyboard” - but obviously my eyes miss it :wink:

Not sure why it is not working - it seems the method signature cannot be automatically matched.
If you change it to testItem.state.toString your rule starts to work as expected.

1 Like

Thanks Kai!

Your solution worked! I’m still a bit curious what caused the problem with my variant.