Door sensor logic

Hi, im working for a few weeks with HA figuring out different sensors etc.

Today I got a door sensor, integrated it, and it works well and reliable.
So I thought, I use it to toggle lights in the bedroom. Simple stuff, if I’m in the room lights are on if I go through the door, lights turn off.
Easy enough, trigger lights on door open, bam, lights turn on.
Then i went into the kitchen, left the door open, lights go out, I come back into the room, close the door lights keep being off.

So if I use that toggle logic on door open, it very much depends on if I leave the door open or not.
In the end I want to set up room presence (maybe with input booleans…), so entering another room would reset/turn off the bedroom lights, but I wonder if there’s a smarter way to handle this “going through a door” logic or is a door sensor simply not the right sensor for this?

Cheers F.

I use occupancy in my spaces rather than just a door or motion or whatever sensor.

Door/ window sensors alone, unless you just need to know that its open, you’ll get the exact issues you just described wgere things are ‘out of sync.’

Motion sensors alone are also not an answer because they can be fooled for both false positives and false negatives and if I sit too long in one place it thinks I’m not there.

Combine logic from the two on a closed room you get a construct known as a ‘wasp in a box.’. Basically, if you have a room with only one portal, and that portal is closed, you can now reliably assume the space is occupied until the portal door reopens. You also solve your ‘which side of the door’ issue by knowing what side of ths door motion occurs on. (also useful if not an enclosed space).

I’m doing this combo (door sensor / motion sensor) in all the rooms I work with now and find theres very little about an area’s state I cant figure out from the sensors.