You should be able to handle this in HA within a single automation:
Trigger: Room is occupied (occupancy > 0)
Condition: Light off
Action:
- Call service: Turn Light On
- Wait for Trigger: Room is clear for 5 minutes (occupancy < 1)
- Call service: Turn Light Off
If you are basing your occupancy on more than one sensor state, you could build a helper to combine the states into a single sensor value, which itself might need a Hysteresis helper.
I've started moving some of my own automations over to this method. It works pretty well, but it is susceptible to being interrupted by restarts or reboots. You may need to build in additional logic to reset things to a known state on startup.