Hi everyone, I’m trying to set up an automation for my lights that turns them on when motion is detected after sunset but before 11 PM, and also turns them off after 11 PM if they’re already on. I’ve tried a few different automations, but none have worked as intended yet. Let me walk through what I’ve done so far and where I might be going wrong.First, I set up a motion sensor in my hallway. It detects movement pretty well, but the timing aspect is where I’m struggling. I want the lights to come on when motion is detected, but only during specific times. For example, if I come home after sunset but before 11 PM, I want the lights to turn on automatically. However, if it’s after 11 PM, I don’t want the lights to stay on unnecessarily.I tried creating an automation that checks for motion and the current time. Here’s how I structured it:1. Trigger: Motion detected.2. Conditions: - After sunset. - Time is before 11:00 PM.3. Action: Turn on the lights.This worked initially, but I noticed that if I’m still up after 11 PM, the lights stay on because the automation doesn’t check the time again. I want the lights to turn off after 11 PM, regardless of motion.To address this, I added another automation:1. Trigger: Time reaches 11:00 PM.2. Conditions: Lights are on.3. Action: Turn off the lights.This works for turning off the lights at 11 PM, but it doesn’t account for whether motion was detected earlier. I want the lights to stay on only during the specified window and turn off afterward, even if motion is detected again after 11 PM.I also considered using a single automation with multiple triggers and conditions, but I’m not sure how to structure it properly. Maybe using a combination of time-based triggers and state checks would work better.Another challenge I faced was ensuring that the automation doesn’t conflict with other routines, like my morning routine where the lights should turn on at 6 AM regardless of motion. I need to make sure that this automation doesn’t interfere with other settings.I’ve looked into using templates and variables to make the automation more flexible, but I’m not entirely sure how to implement them correctly. Any advice or examples would be greatly appreciated!In summary, I want:- Lights to turn on when motion is detected after sunset and before 11 PM.- Lights to turn off at 11 PM, even if motion was detected after that time.- No interference with other routines, like the morning light schedule.If anyone has successfully set up something similar or has tips on how to structure the automations, I’d love to hear from you. Thanks in advance for your help!