How to approach various lighting with overlapping sensors

Hello,

I am fairly new to Home Assistant, but have already made many valuable improvement in my life! My wife at first seem to just roll her eyes as I talked about what I wanted to automate. This week, she asks why doesn’t the garage interior light automatically come on when she enters the garage at night. Now she is onboard :slight_smile:

I am running HA 2021.1.5 in a docker container with Zwave, Konnected, alarmo, nest, nut, Unifi, MQTT, HACS, and many other integrations.

I have a scenario that comes up a few ways and I am not sure how to best approach it.

For each of examples below, I want to turn on the light(s) and keep them on until the trigger is off. Then 10 minutes later auto turn off. However, If the light is already on manually, then ignore it from the automation stand point.

Examples:

  • If open the garage doors at night, I want to turn on the outside lights, the inside garage lights, and the entry way lights. This is triggered by either garage doors opening or a proximity sensor
  • If I open the garage interior door at night, I want to turn on the inside garage lights, and entry way lights. Triggered by the garage interior door
  • If I open the front door at night, I want to turn on the front porch lights. Trigger is the front door
  • If I open the entry closet door any time, turn on the entry way light and the entry closet light because it is always dark. Trigger is entry closet door

I have the basics of this working by having 3 automation for each light.

  • First contains the list of the possible triggers that turn it on. If the light is off, it turns on the light and also sets an input boolean so I know automation turned it on
  • Second, automation per light that turns it off 10 minutes after the trigger has been off for 10 minutes. If the light is on and the input boolean is not, then leave the light on
  • Then a third automation runs when the light turns off (manually or through automation ) and it also turns off the boolen. So you can turn it off manually and it cancels automation from touching it later.

The only issue is if there is multiple tiggers over time. What if I come home, go inside, and then go back into the garage 9 minutes later. I would want the lights for that area to extend another 10 minutes. Essentially, turn off the lights 10 minutes after the last trigger.

As you can see, there can be overlap in the lights and the automations. That is why each light has its own automations with similar triggers.

Then of course, I want to do something similar with my cameras with different but also overlapping sensors.

I have looked at a couple ways to do this, but I am not sure what is best:

  • Leverage the timer function per light. When a new trigger event happens that could impact that light, set or reset the timer. When the timer expires, turn off the light unless the boolean is off
  • Create a sensor for each light. Somehow leverage the templating to look at a list of sensors that might trigger a light and calculate if all have been off for 10 minutes and turn on. Leverage this sensor to turn lights off/on I am not sure if this works or how to do it, but it seemed possible.

Am I on the right track or is there a better way to manage this without going external to node red, etc.