FORUMS
Remove All Ads from XDA
Post Reply Email Thread
Assuming your device is already very battery efficient because you are using my CPU profiles from here, next up is controlling your data connections and syncing schedule.

New to Tasker? Call yourself a geek?! Delete your XDA account immediately or get a free trial from here

The Theory

In order, the most important things in my life are as follows:

1) Preserving my phone’s battery life.
2) Sexually satisfying my girlfriend.

As you can see, it’s pretty important for me that I can get through a couple of days with medium usage without having a panic attack about the distance I am from my charger. Download my DistanceFromCharger profile here (just kidding).

So, I looked at my data connections and their battery usage when my scheduled once hourly sync of widgets, emails, facebook, twitter, rss etc etc took place. Without extensive testing, it became clear that these synchronisations became misaligned from the hourly slot due to data quantity, connection time/errors etc etc. Over time, it is therefore theoretically possible to have 10 applications/widgets/processes causing a data sync separately every six minutes (60 mins/10) and although some might say that the total data volume may be the same overall, the act of using the data connection so many more times tells me it will use more battery life. Do you concur?

Even if you don’t (liar!), the following Tasker profiles are to completely manage your wireless connectivity and prevent syncing of unwanted applications at misaligned times.

The Practice

My phone starts its day set to 2g networks only, data connection off, wireless off, screen brightness set so low I need there to be solar eclipse for me to see it and all system volumes set to only alert nearby dogs that I have a text message – all naturally for maximum battery preservation. Depending on the day, my location, calendar entries etc Tasker selects a relevant profile for me to use.

For the benefit of the profiles below, I am going to assume the phone starts in full battery saving mode and go from there. Once you’re up to speed with the flow of the profiles, you can adjust them accordingly to suit your usage.

Firstly, I learnt pretty recently that a wireless connection actually uses less battery than 3g (yes, honestly) and therefore whenever I sync data, I look to use wireless first. For those with constricting data plans, I’m assuming this suits you too?

Wireless states to consider:

On
Off
On and connected to a preferred network
On and connected to an open network
On but not connected to a network
On and recently disconnected from a network


I think that just about covers it?

Download and install Locale Execute Plug-in free from the market here. Import all the profiles (un-tick them) and tasks and with the relevant profile and tasks open (it will make a whole lot more sense then), follow the guide below.

Before we can look at the syncing profile itself, we need to set up some variables for the above first. For battery preservation, I couldn’t have an individual profile for each of the above, as many of them would be active at the same time and constantly on - After a lot of head scratching (and I mean a lot) I came up with the profile WIFI-OnCon let’s have a look at it:

We start with the state of ‘Wifi Connected’. This state means wifi is connected to a network (rather than just ‘on’). The task WifiOnConVar firstly runs a separate task WIFIPREFCON.

WIFIPREFCON writes a text file containing the standard wifi info variable %WIFII (you can take a look at the output file for your information). The next step is to extract just the SSID from the file so Tasker can set this as a variable %WIFIPREF (short for a wifi preferred network). The task ends with speech for you to test the variable has been set correctly (make sure you are connected to a network at the time).

Next, WifiOnConVar sets a variable %WIFIOC (standing for wifi on and connected) to a value of 2. It then sets a variable of %WIFIHOME to the value 2 only IF the name matches that of your home wireless SSID. You can set and add as many of these variables in as you like e.g. %WIFIWORK, %WIFIGIRLFRIENDHOUSE, %WIFIMASSAGEPARLOUR with the IF statement for their respective SSID’s. Setting up these variables is very useful to let Tasker determine your location for use in other profiles, without the need of running GPS or cell tower location profiles (yes, I’m a genius).

Ok, so at the moment, Tasker knows wifi is on and connected (%WIFIOC set to value 2) and you are at home (%WIFIHOME set to your home SSID) (assuming you are testing this at home). A speech task confirms the variables are set.

The next state to consider is when wifi is no longer BOTH on AND connected. We do this in the exit task – the exit task starting when the state of on and connected is no longer true. Firstly it checks if wifi is still on, if it is (goto action 7), it sets the variable %WIFIOC to a value of 3 (another profile reads this shortly) and then clears the name of the preferred network in %WIFIPREF as of course, that cannot be connected anymore…

If the wifi is off, it sets the variable %WIFIHOME to the value 1 and if you have added multiple preferred network variables (%WIFIWORK etc), you should insert that it sets these to a value of 1 too. A speech action confirms the values for your testing purposes (remember, if you delete the speech when you are happy it is working properly, you’ll need to change the Goto Action number accordingly!), the variable %WIFIPREF is cleared as of course you cannot be connected to a preferred network anymore and the task STOPs.

Finally, to complete the wifi control, we need to deal with the wireless still being on, but out of range of a preferred network (that you were connected to). This is definitely a chance to save some battery life, as we’ve all left wifi on by accident when we are not going to be using it. Above, we set the variable of wifi on and connected (%WIFIOC) to a value of 3 when the state became ON but NOT connected. The profile of WIFI-AutoDiscon is set up to come to life when %WIFIOC is set to a value of 3. It activates the task to start a one minute countdown before checking on the wifi state again. This one minute wait allows time where you may have been in a black spot in your office or home and experienced a short disconnection. At the end of the minute, it checks that the value of %WIFIOC has not been changed back to 2 (it has reconnected to a preferred network) and then switches off wifi with your battery giving you a high-5.

That concludes the wireless management. The only missing eventualities are:

On and connected to an open network. (I have little use for this, but can’t sort something out if the demand is high enough).

On and not connected to a network. Not having a profile for this may surprise you, but in actually fact, how often do you turn wireless on when you are not around a preferred network and just leave it? The only reason you would surely do this, is if you were scanning for open networks, in which case a battery saving profile is pretty irrelevant to the scenario. Remember, the state of on and not connected to a network when you were previously connected IS covered, the %WIFIOC variable 3 and the WIFI-AutoDiscon profile monitors this. Happy?

If not, set up a new profile with the state of wifi connected and click ‘invert’ – but this of course will be active when you’re not even using wifi at all…

Taking control of your data syncing

The profile AutoSync is of course time activated, as you would set up your normal ‘between hours’ for email synchronisation. The repeat value sets how often you would like to sync your emails, widgets, applications, weather updates etc etc, by simply restricting their access to an active data connection in-between-times.

The task of AutoSync itself, firstly checks your battery is above a chosen threshold (you decide) to perform the action and that it’s not the weekend (if you want). Again, once you get to grips with the task flow, you can add in separate entries for individual applications, actions etc based on an individual setting – not syncing your work email on the weekend for example.

Action 4 sets a new variable of %WIFIORS. This stands for the ‘original state of wifi’ when the task began and populates using the previously created %WIFIOC variable. The purpose of this is to make sure that once the task has finished it does not turn off wifi if you were in the middle of using it – it will return wifi to the state it was when the task started – clever hey?

Next it uses the third party Locale Execute Plug-in. Locale will be executing commands that will create and record a logcat file for you for the duration of your sync. The purpose of this is so you can review the logcat file and determine what applications are syncing and pulling data. I’ll discuss this further shortly. LOGCAT ACTIONS REMOVED IN LATER VERSIONS DUE TO ERRORS.

The task continues by turning on wifi (if it is already on nothing will change) and waiting to see if it connects to a preferred network by checking the value of the variable %WIFIOC. If a wifi connection is established, it skips to turning on automatic syncing (settings/accounts and sync to view what will sync), if it isn’t, it turns wifi off and uses your phone’s data connection until either eventuality ends up at action 16 where wifi is requested to switch off IF it was off when the task began using the value of %WIFIORS (clever hey).

Mobile Data (added in V4)

Due to popular demand, the context of mobile data has been added as a profile and then to the tasks. Limitations allow the task only to tell if the mobile data is on, it cannot tell if your preferences are 2g only for example. The variable %MOBORS acts in the same way as %WIFIORS above and will not switch off the mobile data connection if it was on at the beginning of AutoSync. As standard, the profiles assume that your device was set to 2g only to preserve battery. The tasks therefore look to return the device to this state. If you always use 3g preferred, you will need to remove these entries.

Finally, logcat commands are run and files are created, renamed with date and time stamp, moved and zipped up for your future perusal.. *LOGCAT ACTIONS REMOVED IN LATER VERSIONS* The task STOPS if %WIFIORS tells tasker that wifi was on originally or it continues on to switch to 2g only and kill the mobile data connection (these wouldn’t have been activated if wifi had connected or already been on).

So there you have it… Full wifi control and full sync management, with not a single byte of data or rouge connection in sight… You are free to switch off your wifi, data connection, uncheck auto-sync (settings/accounts and sync) and go to 2g only. Tick the profile boxes, hit apply and it’s job done.

Don't forget to set all of your applications and widgets etc that will be syncing to just below the AutoSync repeat time!

Give me your feedback please folks and don’t forget the thanks meter! – At the moment I feel very unappreciated

What do I do with the logcat file? *THESE HAVE NOW BEEN REMOVED*

The logcat files are zipped up and stored in the /tasker folder on your sd card. Looking through these will alert you to any unexpected processes that are requesting to send/receive data. These may be applications you don’t use any more and therefore could be uninstalled or archived (archiving can be achieved with applications such as Bloat Freezer).

Another reason I have stored the logcat is so Tasker could read it and therefore confirm which of your applications have successfully synced, or alert you to failures. This is effort to design and I will only go on to do this by popular demand. In addition, Tasker could be used to kill the rouge processes that are lining up to sync, but are unnecessary… Again, you tell me…

What’s next?

Over to you! Please give me your suggestions. These profiles were set up to suit my individual usage and it may be that most of you focus on your mobile data connection management rather than wifi? Don’t be afraid to post and let me know.

Credits

Unknown for zip file profile
Bdanders for wifi variable inspiration
The Following 80 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
12th April 2011, 03:13 AM |#2  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,232
 
Donate to Me
More
Conclusion

Knowing my phone can remain in deep sleep between syncing times with all data connections switched off has got to be good for battery life? If I ever stop fiddling with my phone for long enough, I'll let you know!

Let me know your feedback please folks, inconsistencies, errors, I’m all ears.

FAQ

Q) I didn't understand the %WIFIPREF variables and how and where I add in my own %WIFIWORK ones etc? Help!
A) A wrote an additional tutorial on how to do this and why here

Q) These profiles always turn my phone to 2g only. I like to use 3g preferred - what do I do??
A) Remove action #21 in the task AutoSync

Q) I don't always want my data connection to be turned off after I sync & I want to leave wifi on if connected to a preferred network.
A) See this post for ideas - credit Nacrul

Q) I don't want to switch between 2g/3g and how do I keep mobile data connections to their original state so I don't disconnect?
A) See this post for ideas - credit lodder

Q) I have many other Tasker questions, can I post them here??
A) To avoid clutter, probably best to use this official Google group

Q) Where can I learn more about Tasker?
A) The manual and Profiles and step-throughs on the Tasker wiki and you’ll be up to speed in no time.

Change Log

Code:
The profiles and tasks include a lot of 'wait' times. These can be reduced to therefore reduce the time you are syncing and the profile is active. They are set to thresholds that ensure enough time is given to each task - you can adjust these manually depending on your device's performance and testing experience. 

V2
Additional wait times added to allow data connection more time after switching from 2g to 3g
Added additional example of %WIFIWORK 
%WIFIWORK & %WIFIHOME are reverted correctly to a value of 1 in the exit task
Unneeded split variables cleared for good housekeeping - credit Nacrul
Voice-overs removed (if you want to check your variables are assigning correct, add a pop up or speech anywhere!).
Adjusted positions of data connection to prevent lag.
Added time based notifications to show LAST successful sync
New %INCALL variable added to ensure 2g/3g switch does not happen during calls * 

* The %INCALL variables are already created in my CPU tutorial here. If you are not running these, then you'll need to create two simple profiles:

DuringCall - the event is 'phone offhook' and in the task 'variable set' %INCALL to a value of 2 (2 = call active)
EndCall - the event is 'phone idle' and in the task 'variable set'' %INCALL to a value of 1 (1= no call is taking place)

The above will come in handy in many other profiles I'm sure...

V3

REMOVED ALL LOGCAT ACTIONS

[Should the running task be interrupted, the logcat may continue to be written to /sdcard/taskerlogcat.txt. Please check that this file is not present! If it is, delete it.] 

If you are really interested in the logcat contents to see what your device is up to when it has a data connection, V2 is stable and works well - the above considered. 

Credit (and apologies) for the above - pasteyface 

V3.1

Updated incorrect 'goto' action in the exit task WifiDisVar. Should have been 'goto' action 7 (not 6). Credit torsrex

Nothing else has changed from V3, so very easy to change for those currently on V3, no need to download and re-install!

V4

Fixed device-asleep notifications
Adding mobile data controls (equivalent to %WIFIOC and %WIFIORS)
Added WiFi or Data to notifications so you can tell which your device used to sync.
Added Minimalistic Text task for home-screen widget.
Added days of the week as a context
Bugs

'Sync Successful - %TIME' notifications not cancelled when device asleep - Fixed in V4

Future Requests

* Wifi remaining on when certain SSID's detected - I'll write up the instructions for this soon...
* Data connection to remain on if it was on at the beginning of the task - I'm working on it... Added in V4
The Following 25 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
12th April 2011, 03:14 AM |#3  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,232
 
Donate to Me
More
Installation Instructions

In menu options/profile data 'Import One Task':

WIFIPREFCON.tsk.xml

In menu options/profile data 'Import One Profile':

AutoSync.prf.xml
WIFI-AutoDiscon.prf.xml
WIFI-OnCon.prf.xml
MobileData.prf.xml


The thanks meter lets me know I'm appreciated!
Attached Files
File Type: zip WiFi and Data Sync Control V4.zip - [Click for QR Code] (3.0 KB, 13555 views)
The Following 101 Users Say Thank You to brandall For This Useful Post: [ View ] Gift brandall Ad-Free
8th July 2011, 10:12 PM |#4  
Junior Member
Thanks Meter: 0
 
More
Exclamation Failed to import profile
Quote:
Originally Posted by brandall

Installation Instructions

In menu options/profile data 'Import One Task':

WIFIPREFCON.tsk.xml

When I try to "Open" the WIFIPREFCON.tsk.xml with Tasker in android, I get the error "File Import: Failed to move import to my SD directory".

All the other xml files imported just fine, but this one will not. When I browser to a different directory in Tasker to import the file, this profile will not display. I just installed Tasker 1.0.21u2m
8th July 2011, 10:40 PM |#5  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,232
 
Donate to Me
More
Quote:
Originally Posted by tleish

When I try to "Open" the WIFIPREFCON.tsk.xml with Tasker in android, I get the error "File Import: Failed to move import to my SD directory".

All the other xml files imported just fine, but this one will not. When I browser to a different directory in Tasker to import the file, this profile will not display. I just installed Tasker 1.0.21u2m

I can't think what the problem would be...? There are no actions within that task that would cause an issue on an updated version... Can you try unzipping the folder on your pc and dragging the task into sdcard/tasker/tasks when you are connected via USB. See if that works and if not let me know...
9th July 2011, 03:11 PM |#6  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by brandall

Can you try unzipping the folder on your pc and dragging the task into sdcard/tasker/tasks when you are connected via USB. See if that works and if not let me know...

Thanks for the tip. 'sdcard/tasker/tasks' folder didn't exists, only 'sdcard/tasker/profiles'. I created the 'tasks' folder and it fixed the error. I was able to import the task into tasker.

Unfortunately I've run into another error. I can't import AutoSync.prf.xml. I've been able to import the other 3 profiles using 'Import One Profile', but when I try to import AutoSync I get the error "Error: Import of AutoSync.prf.xml failed: failed to import profile data."

Do I need to pre-define a variable or something in order to be able to import this profile?
9th July 2011, 03:47 PM |#7  
brandall's Avatar
OP Senior Member
Flag Birmingham
Thanks Meter: 5,232
 
Donate to Me
More
Quote:
Originally Posted by tleish

Thanks for the tip. 'sdcard/tasker/tasks' folder didn't exists, only 'sdcard/tasker/profiles'. I created the 'tasks' folder and it fixed the error. I was able to import the task into tasker.

Unfortunately I've run into another error. I can't import AutoSync.prf.xml. I've been able to import the other 3 profiles using 'Import One Profile', but when I try to import AutoSync I get the error "Error: Import of AutoSync.prf.xml failed: failed to import profile data."

Do I need to pre-define a variable or something in order to be able to import this profile?

It's strange that the folder was not created... Are you running the latest version? Have you tried unzipping them first and placing them individually in the task or profile folders? If that fails, I would suggest you backup your data and uninstall and reinstall Tasker. There's no obvious reason why they shouldn't import I'm afraid... Make sure you're not forcing Tasker to install on the SD in anyway too...

If that doesn't work, let me know and we'll investigate further...
13th July 2011, 06:06 AM |#8  
Member
Thanks Meter: 8
 
More
I had the same import error.

You have to update your app to the last version.

Bye,

NOTE: My next post will be a question/bug. Please answer me !!!
13th July 2011, 06:11 AM |#9  
Member
Thanks Meter: 8
 
More
Question about sync email client
First of all, Brandall thanks for this great script.

I was working with and no problem with gmail or google contacts.

But I can't get managed with Email Client or K-9 Mail (I try K-9 also).

As you say here:
"7)
"Don't forget to set all of your applications and widgets etc that will be syncing to just below the AutoSync repeat time!"

So if the AutoSync repeat time is set to 30 min, the AppSync time should be <29 min...?

/Peter
"

In order to test it I put my email client and sync time or 1 hour, and your state repeat time in 2 hour.

Let's go: 1 hour < 2 hour, but still doesn't work.

I also try by making longer the sync time, from 1 minute to 5 minutes, but nothing happens.

Email and K-9 work perfectly, but doesn't autosync.

Have I to put 59 minutes and 1 hour, or 1:59 and 2 hour ? Is it correct 1 hour and 2 hour or your time event profile ?

Thanks a lot.
13th July 2011, 04:28 PM |#10  
Junior Member
Thanks Meter: 0
 
More
Wifii.txt not created
It seems that my wifii.txt isn't created. I added the "File" option in the Wifiprefcon task at the end and that seems to work but I don't know what the correct location for this option in this task is.

After the "import" of the task there are 7 steps defined. It feels like something is missing.

Hope you can help

Vern
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes