please help me…I found many examples for this topic but for OH2, OH3, nothing for OH4 (ver. 4.1.1 Windows platform)
In DSL script I’m trying to get the state of triggering item, but nothing of methods work
I tried to do that by:
var vsTriggerItemName = triggeringItemName
var vsState = itemRegistry.getItem(vsTriggerItemName).getState().toString()
var vsState = triggeringItem.state
var vsState = getState(triggeringItem)
var vsState = triggeringItem.newState
var vsState = triggeringItem.getState()
so how to get the state of triggered item? Somebody can help me?
It is triggeringItemName.
As for the state, do NOT try to get the state by .state.
You need to use implicit variables as described here
Otherwise you run into a problem that your rule gets triggered and before OH gets the state back, the state might have already changed.
The name of that implicit variable depends on how the rule is triggered (by channel, by command or by update).
If you post the complete rule we are able to help you.
Also think about adding all your items into a group and then have the rule triggered by a change of a group member. Your rule becomes easier und you still can access the triggering item by
triggeringItem.name
(please note the difference to triggeringItemName)
it doesn’t work [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘c440808901’ failed: cannot invoke method public abstract java.lang.String org.openhab.core.items.Item.getName() on null
the second one:
logInfo(newState)
it works!
Thank you very much for your help! Have a nice day.
the ERROR is: [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘c440808901’ failed: cannot invoke method public java.lang.String java.lang.Object.toString() on null
could you make a test with triggeringItem.name
I remember there were plans to align implicit variables. Maybe this was already done but the docs were not updated.