PIR + LED ligth

I wan to turn on the LED light when the PIR turns on, and I made a simple rule.
It works, but if the PIR turns on while the LED is on, it will not prolong the timer. I want the ligth to be continiously on if there are motion in the room, ie multiple “ON” signal on the PIR. The script below just wait until the timer has ended, thereafter it switch of the LED and waits for the next “ON” from the PIR. I do not want it to switch off the LED if there has been motion in the room while the LED was on.
How would such a script look like?

    rule "Handle PIR Events"
    when
    	Item PIR_1 changed from OFF to ON
    then
		KitchenPowerLED.sendCommand(ON)
		Thread::sleep(1000)
		PIR_1.sendCommand(OFF)

    			LED_timer_1 = createTimer(now.plusSeconds(10)) [|
    			KitchenPowerLED.sendCommand(OFF)
                        LED_timer_1 = null
    			]

end

I used the code from your example, see below. However, I do not get the rule to trigger when the PIR_1 goes from OFF to ON. If I change the rule to “Item PIR_1 changed from ON to OFF” it will trigger the rule, but then I do not get the extention of the timer, and thus no improvement from my original rule. Why do not “Item PIR_1 received command ON” work?

rule "MotionDetector1 received ON"
when
    Item PIR_1 received command ON
then
KitchenPowerLED.sendCommand(ON)
    if(md1Timer == null) {
        md1Timer = createTimer(now.plusMinutes(timeoutMinutes ), [|
            PIR_1.sendCommand(OFF)
            md1Timer = null
            KitchenPowerLED.sendCommand(OFF)
        ])
    }
    else {
        md1Timer.reschedule(now.plusMinutes(timeoutMinutes ))
        
    }
end

For these kind of scenarios I use the expire binding. With each trigger (movement) the timer always resets

It is a very simple to use binding

HTH
Christos

Perhaps your mystery Item doesn’t receive commands. Is it getting state updates instead, perhaps?

the mystery item is:
Switch PIR_1 “PIR_1” {mqtt="<[broker:openhabian/Sensors/PIR_1:state:default]"}

Indeed, you have the item configured to get updated when a mqtt message is received. Change state to command in the mqtt binding config for the item and the item will start to receive commands instead of updates.

Alternatively, change the rule trigger to received update.