here is a copy of a prior post a good while back.
==========================
I use MacroDroid to turn the internet on/off as needed.
works like a champ.
When screen is locked, internet is turned off.
When screen unlocks, internet is turned back on.
While the internet is off, the phone just idles along and sips battery about about 8 or 10 percent per day.
When you need the phone, it is ready to go to work for you and has lots of battery to do it with.
* MacroDroid - Device Automation - Android Apps on Google Play
Here is a short list of the main macros important to me:
T = Trigger
A = Action
C = Contstraints
Labeled Internet Off:
T: Screen Off
A: Data off, disable Wifi
C: None
now touch the right arrow at the top right corner
Labeled Internet On:
T: Screen Unlocked
A: Data On, enable Wifi
C: None
now touch the right arrow at the top right corner
Now it will ask you to Label the macro, give a name that makes sense to you.
If you are using the free version, you must use two macros to turn off the internet, and 2 more to turn the internet back on.
They allow you 5 macros with the free version, so you get a chance to get accustomed to MacroDroid.
It took me about 30 minutes to spring for the Paid version because with the Paid version, you can have one macro do multiple actions. The free version will only allow 1 action per Trigger.
MacroDroid has a huge library of transition sensors, and controls. You just have to play with it. Once you do, you will come to depend on it a lot.