Trigger routine only when sensor changes from closed to open state

I have a door to my basement with an open close door sensor. 90% of the time it has been left open. What I want the routine to do is on transition from closed to open state, if the lights are already off, then turn on the lights. I have a separate routine that shuts off these lights at 2:30am.

Because the door is being left open, the routine to turn off the lights is being reversed by the open door routine. What I would like to have is only when the door goes from closed to open state, run the routine. If the door is already open, don’t keep trying to run the routine when the lights shut off. Back when I had smart lighting, this used to work “as expected” but with these new routines, I’m struggling to get this work.

I’m sure this has been answered before but I can’t find it. Thanks in advance for insights and help.

You want to include preconditions so that the state of a device is considered when the trigger condition occurs. So, in your case:

If Light is off (precondition)
   Contact opens
   Turn on light

You could also have a Routine to turn off the light when the contact closes:

If Light is on (precondition)
 Contact closes
   Turn off light

Similarly, you could add a precondition to your “lights off at 2:30am” that checks to see if the light is on or not.


So simply adding the lights as a precondition solves this problem? Thanks. I’ll give it a shot. Here is the routine for reference

Here’s what I changed it to. I’ll see what happens tonight at 2:30 when the door is still open and the other routine is trying to turn off the lights.

Yes, that looks like what you want. The way the ST app reads is kinda goofy. With your new Routine, it reads like this:

When Contact opens
    If Kitchen Light is off
    If Stairs Light is off
    If Night mode
   do your actions

In your previous Routine all the conditions are triggers. I appreciate the UI of which makes it very clear “When an event happens, evaluate this set of conditions, and execute if the conditions are met.”