Take a look at this community app:
https://community.smartthings.com/t/turn-off-after-motion-stops/22847?u=lmosenko