If there are two things that irritate me the most when I go to sleep, they are: Sync notifications going off and battery drained off in the morning (worst case being drained off before alarm time, making me late for work). I used to have a simple profile that turned off auto sync between 11 PM to 7 AM but it didn’t always work well because I work past 11 quite a lot and don’t usually have a fixed sleep time. Similarly I get up at different times. Sometimes I’m not even home and still the profile runs, making me lose sync.
(For the impatient, if you want to use it, I’ve uploaded my profiles to my github account.)
So, I set up and quick and simple but much better working night mode profile. It consists 3 different profiles actually as listed below:
- Night Mode -> This actually turns on the night mode based on a host of different combinations listed later in the post.
- Alarm Detection -> Detects when the alarm goes off
- Unlock Detection -> Detects when the phone display is unlocked.
- Home Detection -> Detects if I’m at home
The basic premise behind this night mode setup is:
- The phone should detect that I’m sleeping by taking a combination of following scenarios:
- The location should be at home (Done by home detection profile using “Cell Near”. I use this mostly because it is more accurate than network location and works indoors as well which GPS doesn’t do and is very light on battery as well)
- Time should be between 11 PM to 7 AM (my likely sleep time)
- Display should not have been unlocked in the last 30 minutes (i.e. make sure I’m not actively using the phone)
- It’s dark in the room (Make sure that lights are turned off. Need to turn on ambient light sensor to work with screen off in tasker settings for this)
- Once all the above conditions are established, my phone is fairly certain by now that I’m indeed sleeping
and turns off auto sync - The night mode still has to check whether the conditions still exist after every half hour or so (e.g. I might not be sleeping yet but lights turned off to allow my wife to sleep and I didn’t fiddle with the phone for some time)
- If I unlock the phone any time at night, it should tell my phone immediately that I’m not sleeping and it deactivates the night mode (for the next 30 minutes or so when night mode check kicks in again)
- When the alarm goes off, night mode should be stopped since I’m obviously awake now
- There are quite a few other checks and balances incorporated to make sure all these 4 profiles don’t go out of sync and also do as less as possible to preserve battery.
Tested this setup for past few weeks and it works pretty well. If you want to use it, I’ve uploaded my profiles to my github account.
Improvements/Changes:
- Exchange sync still bypasses the auto sync turn off settings. So need to either buy “Synker” to control exchange sync directly or figure out a way to connect droidwall to tasker to cut the internet connection for exchange app.
- The home mode xml in the account does not have anything in cell tower locations
, so you need to open it in tasker and scan for your own cell towers - I just turn off auto sync for me in night mode (want to receive sounds for other notifications, texts etc), you can edit the profile to suit your other needs
- You can change the timings as well as per your needs
- I have some prints done to a file in these profiles, mainly for debugging. You can remove those once you are certain the setup works well for you.
- Let me know if you can think of any other ways to make this more robust. I’ll post the rest of my tasker profiles as well soon.



One thing I think will make this complete is (if possible) having it make sure that your alarms are ON once it detects all of the above criteria for being in “night mode”. I hate it when I forget to set my alarms…just a thought.
There is good software for Nokia – ‘situations’
Hi man,
I like Your settings, but how do I import them?
Thanks!
It might be worth renaming your files so that they’re called .prf.xml rather than .xml – Tasker wont see them to import them if you don’t.
@jerba
1) Rename each file so that it’s called .prf.xml – so for example alarm-detect.xml becomes alarm-detect.prf.xml
2) Copy them to the root directory of the SD card on your device.
3) In Tasker’s preferences make sure ‘Beginner mode’ is *not* selected.
4) From the main screen, press and hold ‘Profiles’ until an options box appears.
5) Select import
6) Use the silver arrow to go up a directory until you get to the root of your sdcard, click one of the files to import it.
7) go back to step 4 and repeat this process for each file.
Andy
@Andy: Thanks for letting me know. I exported them from Tasker, weird that it should not take care of the naming so that importing later works fine. Will rename the files.
Hey there, I get ‘error importing profile data’. Any ideas?
Same here,
“error importing profile data”
@naskar, mario: Which tasker version do you have? And did you rename the files as mentioned by Andy above?
Jep, found the problem. Classic mistake done by noobs. Your github account shows the files in a directory listing. So what does the average internet user do? Right Click and “Save as”. Unfortunately this is going to save the full html file and not the raw xml only.
Just realized it because the file was a little bit too big for just this few lines.
*facepalm*
Now i will check out your scripts. Was already trying to figure out the whole day how to create the condition “if in standby for 30 minutes”. So curious
Thanks!
Update: I see that txt files are written. Do I need to create them?
Isn’t there another way to count the time since I used the phone the last time? A condition like “Wait for 30 Minutes” and every phone interaction will start the timer again?
@Mario: txt files are for logging purpose only so you can debug them or if you are a stats nerd
Don’t need to create them. They should be created by tasker automatically. The actual data for last used is stored in tasker internal variables.
Love the idea…but can’t get it working! Having problems importing the .prf.xml files – ‘error importing profile data’. I’m using Tasker 4.0u1m for Android 4.0 on my GS3. I copied the text into Excel and saved as .prf.xml.