State of the item with combined name

Hello,

i have a rule

rule "Timer expired for a door"
when
    Member of gDoorsTimer received command OFF
then
    message = message + triggeringItem.name.split("Timer").get(0)+"LastChange"
    logInfo("TEST",  message) 
end

As result i get the exate name of item that i need

2019-12-05 17:11:32.166 [INFO ] [smarthome.model.script.sensors.rules] - DoorEntranceLastChange

But if i trying to get the state of this item like this

message = message + (triggeringItem.name.split("Timer").get(0)+"LastChange").state

i get error

 2019-12-05 17:09:58.944 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Timer expired for a door': 'state' is not a member of 'java.lang.String'; line 63, column 24, length 62

So how can i get the state of it.

Thanks a lot!

Which Item are you trying to get the state of? The Item that triggered the rule?

triggeringItem.state

You’ve assembled some name from the triggeringItem.name, so maybe you are doing something like explained in the associated Items DP. If so, then take that string and do this…

No of item, that name i have combined - DoorEntranceLastChange
So i have made it

triggeringItem.name.split("Timer").get(0)+"LastChange"

OK… check the post I linked to!

OK, i tried it works!!!
Thanks!

I am wondering why this combination do not work

val lastChange=gDoorsSensors.members.findFirst[ t | t.name == "DoorEntranceLastChange" ] as DateTimeItem

i get

2019-12-05 18:18:16.036 [INFO ] [.eclipse.smarthome.model.script.Door] - val opened at:  null

Why null, item has DateTime

DateTime  DoorEntranceLastChange "Door Entrance Last Change [%1$td.%1$tm.%1$tY %1$tH:%1$tM:%1$tS]"

NOTE: You don’t really need a Rule anymore to track the last changed for an Item, assuming you are using OH 2.x bindings. See Design Pattern: Time of Last Update

Are you certain that DoorEntranceLastChange is in gDoorsSensors? If not the findFirst will return null. Show the log statement that prints that line.

Thanks Rich, i will look now.