Functions in rules

I have tried to work with functions in rules and having problems with timers…

`Preformatted textval org.eclipse.xtext.xbase.lib.Functions$Function2 myFunc = [
org.openhab.core.library.items.SwitchItem relayItem,
org.openhab.model.script.actions.Timer t|

t=createTimer(now.plusSeconds(10)) [|
relayItem.sendCommand(OFF)
]
]

When the rule runs, the timer created successfully, but when the timer runs, it looks like it does not recognize the relayItem. here is the error:
2017-05-14 23:14:15.181 [ERROR] [org.quartz.core.JobRunShell ] - Job DEFAULT.2017-05-14T23:14:15.165+03:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
logInfo(,)
org.eclipse.xtext.xbase.impl.XIfExpressionImpl@6cb7d7
} ] threw an unhandled Exception:
java.lang.RuntimeException: The name ‘.sendCommand()’ cannot be resolved to an item or type.
at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:112)[129:org.eclipse.smarthome.model.script:0.9.0.b4]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:763)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:219)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]

Please help.
Thanks ahead,

That sounds like a situation in which the Expire Binding could be used. Please have a look at the following thread. @rlkoshak explains the usage at the bottom of the first post.
Design Pattern: Motion Sensor Timer

No…
I simplified the problem. My rules are much smarter with lots of conditions (not always turn off the light… and if they turn off the light it depends on the time…)

In this case a look into the following thread might help.

still I see (the same) errors:
The name '<XFeatureCallImplCustom>.containsKey(<XFeatureCallImplCustom>)' cannot be resolved to an item or type

err, that’s not the same error. When you began, with it was complaining about .sendCommand, now it is .containsKey

Yes, I tried the other way.
My big problem is that when I forward the item as parameter the timer not recognize it…

Are you using OH2? If so, this import is incorrect-

org.openhab.core.library.items.SwitchItem relayItem,

perhaps you followed an OH1 example?

Yes I’m using OH2, what is the SwtichItem classpath for OH2?
Thanks!

No path required at all, already included
http://docs.openhab.org/tutorials/migration#rules

@rossko57 Thanks!! that was the problem!