Minimum presence time?

I have a smart app that will turn on a light when a door opens only after it is after sunset. Once the door opens the light turns on and the mode gets set to Night. The problem is, if I open the door after sunset and I’ve been home since before sunset, the light will still come on.

Is there a way to poll the amount of time my phone has been present? So if it’s been present since 5:30pm the light shouldn’t turn on since I’ve been home for some time.

Thanks in advance!

I suspect there are a number of possible ways to address this. I’m certainly not the most knowledgeable in solving these problems. One way I can think of would be to change the house mode to sunset at sunset each day. Then have the automation exclude all other modes except sunset to turn on that light. Then you can use the fact that the light switch is now on to trigger the change of mode to night. Once the mode has been changed to night the light would no longer come on with the door opening as night mode would be excluded from that automation.