Sonos automatically set sleep timer

I have Sonos speakers in my kids rooms and they often listen to music when going to sleep. What I'd like to setup is an automation that recognizes the Sonos is playing after a certain time and turn it off if it's been playing for 30 or 45 minutes. Basically a sleep timer. Has anyone done this?