Something very similar exists. Bathroom light control. @rayzurbock wrote it for just this purpose and it’s based on trending.
There is also some use case discussion you might find of interest, as well as a discussion of specific sensor issues.