String to Item within a Lambda

I’m trying to create an itemname within a Lambda that I can query, but I can’t find how to do it.

Items:

Switch item1 (gSwitches)
Switch item2 (gSwitches)
Switch item3 (gSwitches)
Number MinsItem1 (gRuntimes)
Number Minsitem2 (gRuntimes)
Number Minsitem3 (gRuntimes)

Rules:

rule "Calculate Uptimes"
when Time cron "0 0/1 * * * ?" then	{
gSwitches.members.filter(y | y.state == ON).forEach[onItem|
val rtItem = "Mins" + onItem.name.toString
logInfo("test", "rtItem is " +rtItem)
var rtOld = rtItem.state as Number // rule fails here
var rtNew = rtOld + 1
rtItem.sendCommand(reNew)
]
}
end

The intention is to increment the value by 1 every minute for each member of the group that is on.
The log statement suggests that the item name is correct but this can’t be used to get its state. What am I missing?

You can do

sendCommand('itemnameAsString', reNew)

instead of

rtItem.sendCommand(reNew)

use must use

sendCommand(rtItem, reNew)

This is one of the cases where you have to use the sendCommand action instead of the item function

Regards

Thanks for the replies @luckymallari @vzorglub
Unfortunately it doesn’t like the 6th line of the rule, so I don’t get to send the command

 var rtOld = rtItem.state as Number

add .state in your log like this:

logInfo("test", "rtItem is " + rtItem.state)

Please think abouit using VSCode and the openHAB extension to edit your files. This helps you a lot in regard to avoid mistakes.

rtItems is a string and therefore has no state.

To get the item you want you havet to get it, for this you can use your group gRuntimes, then you have a valid item you can get the state from and also use the postUpdate or sendCommand functions.

var rtItem= gRuntimes.members.findFirst[i | i.name == "rtItemNameAsString"] as GenericItem 

Thanks, that seems to have fixed it.
Regarding editors, I am still using Designer purely and simply because I can’t get the VSCode and OpenHAB extension to work. I’ve just downloaded both again and the VSCode part seems to work, and I also added GiT which is seemed to want.
However I have no idea where to put the “openhab-vscode-master” folder, or how to tell VSCode to use it.
Where does it go?

https://docs.openhab.org/configuration/editors.html

Press Ctrl+Shift+X and type openhab install the listet extension.

After that follow the instructions
Go to File/preferences/Settings you can insert your user settings on tle right side.
Set you openhab host, this is neccessary!

Then go to file/open workspace and open your openhab folder, it has to be mounted or reachable as network device if it is not located on your pc. Mount the drive with Samba, SFTP etc so you are able to acces it fromyour working pc.

Hope this helps

Thanks very much, for those following on I had to add the configuration folder before I could open it.
All is now working with VSCode thanks