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.

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.