If I understand your question correctly, then there is a very easy way of doing this yourself. Im sure there are many ways of going about this, but this is the easiest and most reliable method that I know of.
You said that you wanted something that doesn't rely on the screen being off. My solution does rely on the "display" being off, however for the "display" as opposed to the "screen" to be off, the device must be locked, meaning that this should work flawlessly for you.
If you just follow the instructions I've provided below, you should have satisfying results in just a few minutes!
- Download Tasker from the Play Store.
- Open Tasker and click the
+ button. Now click Event → Display → Display Off.
- Click the gear (back button) in the top left corner. A pop up menu will appear. Select New Task and name it
+ → Net → WiFi and make sure the box that says Set is set to
- Click the gear (back) twice so that you end up on the Profiles screen.
- Now click
+ again, then Event → Display → Display On.
- Tap the gear (back) and then select New Task. Name it something along the lines of
+ → Net → WiFi and change Set to
On. Now exit back to the Profiles tab. You should now have both Display Off and Display On.
- In the Profiles tab to the right of your conditions, there are On/ Off toggles. Turn both of these to Off and then back to On.
- Simply exit out of Tasker and you're done!
Good luck and I hope this helps you!