How to check if a person is detected after motion detection?

What I would like to do is the following automation:

Motion gets detected
Turn lights on
After that if no person is detected via Frigate within 30 seconds → Turn lights off

I haven’t figured out a way to do this via UI and I am not able to programm this. Is this possible and if so how?

This is psuedo yaml so you’ll need to adapt it to the UI, but:

motion sensor detected motion

turn lights on
wait for time 30 seconds
if frigate person count > 0:
leave lights on (do nothing)
turn lights off