• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

BedTime Daemon

Hawker

Android Expert
I have developed a simple init.d script that will turn various things such as wifi, data sync etc. off during bedtime. Defined services will then turn back on when outside of bedtime hours. Unfortunately I couldn't code a blink-detection program to detect when you are sleeping, so I have had to go for the options-file route instead! :)

The script creates /sdcard/BedTime as its working folder
within this folder, the following folder/files are created/used:

1. Scripts
For manual execution through Script Manager
BedTimeOn.sh - Manually turn on BedTime mode
BedTimeOff.sh - Manually turn off BedTime mode
BedTime.sh - Called by the above

2. options.prop
The best way to describe what the options are and how to set them is to show you the contents of the file itself:

# vvvvvvvv Editable Values vvvvvvvv
# [BedTime start and end times]
OPT_START=0000
OPT_END=0630

# [Services to shutdown/start up]
OPT_RADIO=0
OPT_WIFI=1
OPT_DATA=1
OPT_SYNC=1
OPT_BT=1
OPT_SOUND=0

# [Other options]
DAEMON_ENABLED=1
SUSPEND_RUN=0
FORCE_BEDTIME_ON=0
FORCE_BEDTIME_OFF=0
LOG_EVENTS=1
# ^^^^^^^^ Editable Values ^^^^^^^^

# Section 1: BedTime start and end times
# OPT_START: Time to enter BedTime mode
# OPT_END: Time to exit BedTime mode
# Keep time range in 24 HR FORMAT, NUMBERS ONLY (NO :,' Etc.)
# Original values above will enter BedTime mode at 00:00 midnight
# and will return back to normal at 06:30

# Section 2: Services to shutdown/start up
# What to turn off during BedTime, and turn back on after
# Currently the following options are supported:
# 1. Radio (OPT_RADIO) Turn radio off to prevent incoming calls/SMS
# 2. Wi-Fi (OPT_WIFI)
# 3. Mobile Data (OPT_DATA)
# 4. Data Sync (OPT_SYNC)
# 5. BlueTooth (OPT_BT)
# 6. Sound (OPT_SOUND)
# Set an option to 1 to turn it off during BedTime and back on
# again when BedTime ends
# Set an option to 0 to skip the option in BedTime processing

# Section 3: Other options
# DAEMON_ENABLED
# Set to 0 to stop daemon running. To re-enable, set to 1 and reboot

# SUSPEND_RUN
# Set to 1 to suspend BedTime processing. Daemon remains resident but will
# not perform any processing until this has been set back to 0. No reboot
# is required.

# FORCE_BEDTIME_ON
# Set to 1 to force the handset to enter BedTime mode regardless of current time

# FORCE_BEDTIME_OFF
# Set to 1 to force the handset to exit BedTime mode regardless of current time

# LOG_EVENTS
# Set to 1 to log events to RunLog.txt

3. RunLog.txt
Shows you a log of what options are set and any functions it has performed.

4. run
Can be deleted instead of setting DAEMON_ENABLED=0 in order to exit the execution of the daemon

5. running
This file lets you know that the daemon is still processing in the background. To check, look at the File Properties for the date/time stamp. It should be within the last minute or so.


I started to look into developing a front end .apk in order to adjust the settings, but as I would need to register with google to get a unique developer key etc. I thought bugger it, so you will have to manually edit the options file I'm afraid.

By default on installation BedTime will be set with the following options:
BedTime mode between 00:00 to 06:30
turn off wifi, mobile data, data sync and bluetooth.

If you want to set a different time range, or shut down different services, then edit the options.prop file.

I have found that the services will shut down and start back up pretty much instantly according to your specified time range when the screen is on. When in deep sleep, the action may take a good while longer to instigate.

PLEASE NOTE:
1. BedTime mode will be entered at the pre-defined time regardless of whether or not you are using your handset at the time. To prevent this happening, set SUSPEND_RUN=1, or manually run the BedTimeOff.sh script.
2. If you are on DorimanX 7.? or later then you will have to enable init.d support in ExTweaks.


Download BedTime daemon
Download BedTime uninstaller

Many thanks to Tungstwenty over on XDA whose Gesture thread gave me the idea to do this.
 
I never switch my phone off overnight as I use it for my morning alarm. With this in mind I decided to develop an init.d daemon that will shut down the following services during bedtime:

Radio
Wifi
Mobile Data
Data Sync
BlueTooth
Sound

All fully configurable (ie. what services you want to shut down), as is the time range you want your bedtime mode to take place. All this is done by manually tweaking the parameters in the daemon's options file. (I've no .apk development skills (yet) so until I work out how to do it via an app, then it will have to be manual text editor amendments.)

For example, I set the script to turn off wifi, mobile data, data sync and bluetooth between 00:00 and 06:30. My typical battery drain overnight is around 1% ALL NIGHT. :smokingsomb:

Ok, you can always do all this stuff manually, but I really can't be bothered with faffing around doing that every night/morning! :shot:

I'm still testing and perfecting the script so I'm not posting it up on here yet.
:p

I just want a general feel as to who may be interested in having something like this.


Great idea.

Definitely something I've been wanting!
 
I think it is a great idea Hawker. I personally can't see an instance when I'd use it as my phone goes on charge when I go to bed. However I'm sure there are users out there that haven't got access to a charger overnight and (ultimately) I'm sure a one click app that's configurable would be most welcome.
 
I charge my phone all night, so im not looking for anything of the sorts,
but way to go dude, i love your work.
 
Great idea. Not one I'd personally use though as trend to charge my phone overnight. Happy to be a kamikaze tester off you want one though ;-)
 
Im still seeking my holy grail of 2 days without charging, that I last found on gingerbread days. With only 1% overnight, this would be useful to get towards that
 
Like most id probably not use it very often, but can see the need on occasions where camping/hill walking etc.... Good luck in it becoming an apk file :-)
 
Would be perfect, would love something like that. Miss the BlaqckBerry style sleep mode and this comes very close. To have it done automatically is great, as plenty of times in the mornings have forgot to switch off airplane mode, sync back on etc etc and have missed calls / messages as a result. All this to keep a phone on for an alarm but reduce battery usage (around 2% overnight currently).

Looking forward to it!! :beer:
 
BedTime daemon has now been uploaded.
See Post#1 for details

About blooming time too you old Welsh wizard!

The only drawback for me is that, unlike you married people, I do not have a set bedtime or arousal time.

Can you imagine me trying to re-configure a script last thing at night after a night out or, worse still, trying to switch it back on before my first 3 cups of coffee in the morning. Nightmare!

What I really need is a simple ON/OFF toggle, preferably in the drop down Notification menu... is that too much to ask? :dontknow:



(Am now off to request that the River Severn bridge crossings from Wales are closed before Hawker comes over and abuses me... verbally, mentally and physically :ahhhhh: )
 
About blooming time too you old Welsh wizard!

The only drawback for me is that, unlike you married people, I do not have a set bedtime or arousal time.

Can you imagine me trying to re-configure a script last thing at night after a night out or, worse still, trying to switch it back on before my first 3 cups of coffee in the morning. Nightmare!

What I really need is a simple ON/OFF toggle, preferably in the drop down Notification menu... is that too much to ask? :dontknow:



(Am now off to request that the River Severn bridge crossings from Wales are closed before Hawker comes over and abuses me... verbally, mentally and physically :ahhhhh: )


Arousal time? Can you remember that far back butty?
:D

FORCE_BEDTIME_ON=1: forces bedtime mode on


Or buy Tasker you exigent little cheese chaser!
:banghead:

I could always write a script that you could run though Script Manager I suppose....
 
About blooming time too you old Welsh wizard!

The only drawback for me is that, unlike you married people, I do not have a set bedtime or arousal time.

Can you imagine me trying to re-configure a script last thing at night after a night out or, worse still, trying to switch it back on before my first 3 cups of coffee in the morning. Nightmare!

What I really need is a simple ON/OFF toggle, preferably in the drop down Notification menu... is that too much to ask? :dontknow:



(Am now off to request that the River Severn bridge crossings from Wales are closed before Hawker comes over and abuses me... verbally, mentally and physically :ahhhhh: )

Doesn't your retirement home have a curfew then?
 
Back
Top Bottom