First, in openHAB2 you must not use the * in imports.
Second, I don’t use lambdas for defining functions myself, but I’m pretty sure this has to be done outside a rule.
Third, if using a function, you have to call it.
Fourth… please prefer the method item.sendCommand(value)/item.postUpdate(value) against the action sendCommand(item, value)/postUpdate(item, value), read this for further information.
a simple rule with countdowm would be like this:
var Timer tMyTimer = null
rule "timer with countdown"
when
Item myItem received command ON
then
myCountdown.postUpdate(60)
if (tMyTimer !=null)
tMyTimer.cancel
tMyTimer = createTimer(now.plusMinutes(1),[
myCountdown.postUpdate((myCountdown.state as Number).intValue - 1)
if ((myCountdown.state as Number).intValue !=0)
tMyTimer.reschedule(now.plusMinutes(1))
else
myLight.sendCommand(OFF)
])
end
As long as myItem is retriggered with ON, the rule will restart the timer and reset the Countdown to 60. if there are no more triggers, the item myCountdown will be decremented once every minute.
When myCountdown reaches 0, the item myLight will be set to OFF.
Of course, you may want to stop the timer and reset the countdown when the light is switched off manually…