It’s probably too late now that the rule is mostly working for you, but for future readers, this entire behavior can be reduced to:
Items:
Switch Light_Timer {expire="5m,command=OFF"}
Rules:
rule "Switch on kitchen lights when detecting motion at night"
when
Item molganKueche received update OPEN
then
if(nightTime.state == ON) {
logDebug("Motion", "Turning on lights in kitchen")
LichtKeucheUntenOn.sendCommand(ON)
Light_Timer.sendCommand(ON)
}
end
rule "Kitchen light timed out"
when
Item Light_Timer received command OFF
then
logDebug("Motion", "Turning lights in kitchen back off")
LichtKeucheUntenOn.sendCommand(OFF)
molganKueche.postUpdate(CLOSED)
end
See