# Help me with the logic of this light

Alright, I am trying to figure out how to keep this light off at most times, but turn on when it has to. The light is at the main entrance of our house.
Here is my logic:
Keep the light off during the day, but turn on when I am leaving or coming to the house (me or my wife). I must have the ability to turn it on, on demand, but keep it like that for 2-3 hours without turning off by another automation accidentally.

What I have used so far:

• time: From 9am to 5pm the light remains off at all times as day light is bright and there is no need for lights.
• Google sharing location: When me or my wife are approaching the house, the light turns on. In addition to the proximity component I have it configured to check if we are closer than 1000 meters from the house and also checks if we are going “towards” it.
• Google sharing location: When I leave the house the light turns off. I have this enabled only for me and only at 6am and I will explain below why. << I am trying to figure this out.
• binary sensors: Every time the entrance door opens (in addition to the time condition) the light turns on.

So far I am 80% satisfied with what I have done, but there is a hole in this automation.
I think I have to start from the beginning and rebuild all the automations and conditions.

The idea is to turn on the light when me or my wife come or leave the house. Also turn it off automatically when we enter.

Some of the parameters here are:

• We work on different places and come home at different times. But there are some times that me or her can be late at home. That means that our arrival times can match with a difference of 5-10 minutes. Maybe more or less.
So, here is a bad scenario: When she approaches the house, the light turns on. 5 minutes later I am in close proximity and the light will turn on again (false positive since it is already on). Wife gets inside the house and the light turns off. So when I reach the entrance the light will be off… Baaaaad!

• We can leave the house (either for work or a visit) at separate times. That could be a difference of 1 minute – Yes it has happened before!
So, here is another bad scenario: I am leaving the house and she leaves after a while. The light is already on since I am the one who opened the door first. She closes the door and while stepping the stairs the light goes off, because I left out of proximity! BOOM there goes the wife!

• We are expecting guests, so we have to turn on the light manually because we cant know their exact location. The light must remain on even if I leave the house. That means no automations will be able to turn off the light If I turn it on manually, right?

All these sound a lot, I know… But I am trying to figure out how to do all this without creating a whole set of automations and then realize it doesnt work and then go all over again.

Please if you can help me! Also is there anything else I am forgetting? Another parameter?
If that helps, I have a camera in the entrance. Can I make use of it? I have thought of body detection (when detects a body, turn on the light no matter what) but this was very hard for me to implement.

I think I got this covered and for now, it seems to be working fine. I will have to check it for the rest of the week maybe, to test all the conditions and triggers. For now it does what I wanted to do…
But now I am getting an error every now and then. This error doesnt come up when I check the configuration.

Error during template condition: UndefinedError: ‘None’ has no attribute ‘attributes’

That error is likely due to the fact that the template is referencing an attribute of an entity that doesn’t exist at that moment.

Post you code and maybe we can spot the error.

I got what was wrong. I used the wrong template on one of my triggers… This template didnt have the attribute I was looking for. The name was similar to the correct one. It is that thing where you check and double check and maybe triple check everything and it all seems to be fine, but then when you look at it next day, you see your error right away. Thank you for the help!