Timers that expire for lights to go off

Hi again! :slight_smile:

I’ve configured a successful rule to turn on my bathroom lights when the motion sensor (ZSE18) detects motion, but I can’t figure out how to turn the lights off after a few minutes (lets say 5 minutes) has passed.

Through research I’ve learned that there used to be an ‘expire binding’ which looks exactly like what I need, but as I read more and more I learned it (the expire binding) is a “core feature” of OH3.

I’ve been trying to figure out how to use the expire function the past couple weeks and I’m so confused.
I’ve searched and searched and have came up with almost nothing on how to use the expire function (lots of stuff for OH2 and OH2.5 and the old expire binding). The best I came up with was A) add the expiration as metadata and B) the expire function can only be done in the coding. I’ve read countless posts on this forum. I’ve read old tutorials on openhab.org from many years ago on the problem that I’m trying to solve. I can’t find a focus to steer me in the right direction and I’m a bit frustrated, lol. I’ve done lots of tests and the lights will not turn off. (I have a simple rule to turn the lights off once the sensor no longer detects motion, but if a person stands mostly still for 30 seconds the sensor doesn’t detect motion and the lights go off. Then the person has to wave their arms to turn the lights back on, lol.

Any help would be greatly appreciated!

Here’s what I want to do: After my Zooz ZSE18 Motion sensor no longer detects motion and updates to “off” (the sensor goes to “triggered” when detecting motion and then goes back to “untriggered” when it no longer detects motion), I want the expire binding to turn the lights off after 5 minutes. Here’s the code for my rule to turn the lights on.


  • id: “1”
    itemName: AtestB_BinarySensor
    state: ON
    previousState: OFF
    type: core.ItemStateChangeTrigger
    conditions: []
  • inputs: {}
    id: “2”
    itemName: GuestBathroomRoom_Power
    command: ON
    type: core.ItemCommandAction

Can I just add the expire coding somewhere in there? Something like expire=“5m,command=OFF”?

I’ve tried so many other things from so many things I’ve read. I could have did them wrong though, of course. I’m now humbly asking for help.

Thanks so much,

This bit should be part of your Item definition. How have you defined your Item? Please share it in-between code fences.

Thank You hafniumzinc!

I’ll be honest, I don’t know how to define an item or what that means. And although I’ve read the words ‘code fences’ many times while reading up on stuff, I do not know what code fences are. I’ll read up more on that.

Do I define an item by going into the configuration ‘items’ folder? I looked in my ‘items’ folder and there is literally nothing in there except the ‘readme’ file.

I guess I’m going to start here: Items | openHAB

A quick read at the top suggests using a text editor like VSC (Editors | openHAB).

Am I going in the right direction here regarding defining an item and getting to code fences?


Start here, read everything, and continue following to the next page - there’s a lot to take in, but then openHAB is very flexible!

Your OP shows this - you have created an Item called GuestBathroomRoom_Power?

Within openHAB go to SettingsItems → (your Item above) → Add MetadataExpiration Timer

Then choose Send Command, and under Command write OFF.

Then choose the countdown time.

Then click Save top right.

Done! Your Item now has an expiration timer on it!

hafniumzin you are A-W-E-S-O-M-E!!!

First off - thanks for the link to the ‘getting started’ introduction! I’ve read through that many times over the past year, but admittedly, I get stuck at a certain point once I get far enough. I do get a little farther every time with my understanding of things though, so that’s good! :slight_smile:

Secondly - thanks for the step-by-step knowledge for the expiration timer! I was SO close! You really enabled the missing piece for me and I so appreciate that! It also opened my world on how to accomplish other similar things in the future. So thank you! I actually tried doing (showing how close I was) this (your instructions) at some point earlier in my testing, but I think I was using the wrong item. Once I did as you instructed with the correct item - BOOM!! Mission accomplished! THANK YOU!!

I was basically way overthinking the whole expiration timer. It’s basically - simply choose the ‘item’ you want to use the expire timer on and then add the metadata to it". I bet it can get more complicated, but for now, this is good for me. :slight_smile:

The lights now go off at my specified time limit and I cannot be happier. Thank you again very much!