Light switch on and off based on sensor—but not every time?

Sure, there are lots of things that you can do. If you use webcore, which is an advanced rules engine for smartthings, you could have the light only turn off every other time the door is closed, for example.

That said, my own Experience is that an open/close sensor just doesn’t tend to work for bathrooms Unless you live by yourself and have very predictable habits.

There are just too many different reasons why someone might open the door a second time or leave it ajar. Kids are obvious, But also you may need to get a towel or toothpaste or something and you may not shut the door behind you each time.

For this reason, I do think most people use motion sensors rather then contacts sensors for bathrooms, or a combination of the two.

The following FAQ explains how you can set up more complex rules. (This is a clickable link). But before you get into that, you may want to just think through all the different patterns that would be detected by the devices you have, and whether that will work for you.