Automation motion after sunset

New to HA. Set up automation. I want lights to turn on based on motion, after sunset but not after 10:59 pm. The automation runs but starts before sunset.

it’s quite hard to help debug a screenshot of an automation, especially with all the substantive information collapsed. if you want help with it, you should post the yaml AND format it correctly.

however what you’re trying to do has a ton of blueprints that just does it right for you. here’s one example:

but if you want help with your code and don’t want to use the blueprint, please take a look at how to post yaml here: