I have done something similar but using both CoRE and the smart lighting smart app. I set smart lighting to turn on my daughter’s bathroom light when there’s motion and to turn it off 2 minutes after motion stops. The problem I was having was if the light was turned on manually and no one walked into the bathroom, then smart light would not turn the light off as smart light turns does its thing after motion stops but it doesn’t register doing that unless motion started in the first place.
I set up CoRE to turn the light off after a period of time if the motion sensor shows as inactive which allows the automation to run wether motion had started or not. I also noticed that using the toilet when people aren’t very active, the lights would go off without warning. To fix this I set CoRE to dim the lights to 2% for 10 seconds before turning the lights off, letting you know if you don’t move soon the lights will go out. Any movement after that restores the light to its previous level.
The Piston looks so complicated but it’s really simple and it works rock solid 100% of the time and evolved over time and trial and error.
Also, the reason I use smart lighting to turn on the lights is that my motion sensor and light are both run locally along with smart lighting, so that basic automation will run even if I don’t have an Internet connection. CoRE is there to do the heavy lifting when there is Internet but it’s good having a backup automation.