Help me - Turn off light after 5 minutes human body go off

Help me - Turn off light after 5 minutes human body go off

Good evening I’m a beginner
I would like to implement a rule that does the following:
I turn on the light with the physical button and go into the room, at the same time a 5 minute timer starts to turn off the light but if the body sensor detects a movement in the room it starts the timer again. The light should switch off after 5 minutes if the body sensor detects no movement or if I switch off the physical button.
Thank you all

Switch Luce_Centrale_Cucina “Luce Centrale Cucina” (Luci, LuciCucina) [“Lighting”] { channel=“openwebnet:bus_on_off_switch:xxxxxxxxx:xxxx:switch” }

Switch Pir_Cucina_Motion “Stato Movimento Cucina” (gPirPresenze) { channel=“mihome:sensor_motion_aq2:xxxxxxxxxxxxxx:motion” }

now I use this rule to turn off the light automatically after x minutes but I can not integrate the body sensor.

Thanks to everyone who wants to help me

var Timer TimerLuceCucina = null

rule “Luce Cucina Auto OFF dopo 2 Minuti”
Item Luce_Centrale_Cucina changed
if (Luce_Centrale_Cucina.state == ON) {
if (TimerLuceCucina === null) {
logInfo(“rules”, “Avvio del TimerLuceCucina”)
TimerLuceCucina = createTimer(now.plusMinutes(1)) [|
sendCommand(Luce_Centrale_Cucina, OFF)
logInfo(“rules”, “Tempo Scaduto Spengo la Luce Cucina”)
} else {
logInfo(“rules”, “Resetto il TimerLuceCucina”)
// subsequent ON command, so reschedule the existing timer
} else if (Luce_Centrale_Cucina.state == OFF) {
logInfo(“rules”, “Spengo la luce cucina”)
// remove any previously scheduled timer
if (TimerLuceCucina !== null) {
logInfo(“rules”,“Cancello il Timer”)
TimerLuceCucina = null

Head over to the Add-ons wiki and review the expire binding, you put the timer at the item level (I placed it on my light switch item) and then set your rule to turn the light on if it detects motion which will in turn refresh the expire.

I found in my case the motion detection refreshes every 5 - 6 mins, so I had to set that particular light to expire after 10 mins.

Please use the code fences

As mentioned, using the expire binding is a good route. See my example rule below that uses iPhone detection and the expire binding as a timer. The rule executes when gPresent receives an update. If no one is detected a timer set for 20 minutes is started. After the 20 minute timer expires then Presents will send a command off. If during the 20 minutes presents is detected then the timer is canceled.

If you modify the items and the expire timer, to suit your needs, you should be able to use the rule with motion as well.


Group:Switch:AND(OFF,ON) gPresent <present>
Switch Present "Phone is home" <present>
Switch Present_Timer { expire="20m, command=OFF" }
Switch MyDevice <network> (gPresent) { channel="network:pingdevice:SiPhone:online" }


rule "start gPresent on system start"
    System started
    Present.sendCommand(OFF) // assume no one is home

rule "gPresent updated, at least one change of state"
    Item gPresent received update
    // someone came home
    if(gPresent.state == ON && Present.state != ON) { 
        Present_Timer.postUpdate(OFF) // cancel the timer if necessary

    // no one is home and timer is not yet ticking (otherwise endless loop)
    else if(gPresent.state == OFF && Present.state != OFF && Present_Timer.state != ON) {
        Present_Timer.sendCommand(ON) // start the timer

rule "Present_Timer expired"
	Item Present_Timer received command OFF

Hope this helps.