Shortcuts-app automation to prevent iPhone screen from going to sleep
As a workaround, I'd use combination of Low-power mode and Auto-Lock after t time. 

In Display and Brightness Settings, you can set auto-lock to 1-5 minutes or never. Now since this might drain battery, use low power mode when your "condition is not met". This locks the auto-lock timer to 30 seconds. 

Low power mode has its own cons, like some syncs disabled, reduced brightness etc.