Skip to content

Commit

Permalink
START v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory-K committed Nov 12, 2017
0 parents commit d285638
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patch/diff artifacts.
*.patch
*.diff
*.orig
*.rej
*.log

# emacs artifacts.
*~
\#*\#

# VI swap file
*.swp

# Hidden files.
.DS*
.DS_Store
.project

# Windows links.
*.lnk
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 David Konsumer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# tp-link Circadian Alarm

A simple bash script alarm to mimic a "natural" sunrise light wake-up.

The script works with the [tp-link LB120](http://www.tp-link.com/us/products/details/cat-5609_LB120.html) smart wifi LED bulb.
It may work with the LB110/LB130 or with the entire range of tp-link wifi bulbs.
tp-link Circadian Alarm uses the [tplink-lightbulb](https://github.com/konsumer/tplink-lightbulb) nodejs controller and it is based on this [simple Bash alarm clock script](https://github.com/mkscrg/alarm-clock).

github repository <https://github.com/Gregory-K/tplight-circadian-alarm>

## How it works

User inputs the desired wake-up time.
The script calculates the remaining time and one hour before wake-up time it starts sending commands to the wifi bulb.
The bulb will start with 2700K color temperature and 5% brightness and will gradually ascend to 5000K/100% 10 minutes before wake-up time.

It is supposed to assist you in waking-up in a more "natural" way using external cues to adjust your circadian rhythms.
Of course, this particular method is not scientifically proved in any way.
*Although circadian rhythms are endogenous ("built-in", self-sustained), they are adjusted (entrained) to the local environment by external cues called zeitgebers (from German, "time giver"), which include light, temperature and redox cycles. ref: [Wikipedia](https://en.wikipedia.org/wiki/Circadian_rhythm)*

## Requirements

* a tp-link LB120 (tried and tested)
* Bash Shell ...
* pre-installed on Linux and MacOS
* can be installed on rooted Android and [Windows](https://msdn.microsoft.com/en-us/commandline/wsl/install-win10)
* [NodeJS](https://nodejs.org/en/)
* tplink-lightbulb nodejs controller

## Application

* Guess you have already installed [NodeJS](https://nodejs.org/en/).
* Install the tplink-lightbulb nodejs controller.
* [tplink-lightbulb](https://github.com/konsumer/tplink-lightbulb) `npm i -g tplink-lightbulb`.
* Download the sunrise.alarm.sh and make it executable `chmod +x sunrise.alarm.sh`
* Find your bulb `tplight scan`.
* Edit sunrise.alarm.sh -> line:10 (enter your bulb's IP address). *Better to assign a permanent IP to your bulb. Check your router/DHCP-server*
* Execute sunrise.alarm.sh `./sunrise.alarm.sh` and input the desired wake-time in HH:MM format.
* It is recommended to execute it on your home/office server (remotely via ssh) using a [screen](https://www.gnu.org/software/screen/manual/screen.html) or [tmux](https://github.com/tmux/tmux/wiki) session and detaching from it.
* In any case the computer/device running the script must be left turned on.
* You can create a symlink to /usr/local/bin `ln -s ./sunrise.alarm.sh /usr/local/bin/sunrise.alarm.sh` in order to execute sunrise.alarm.sh from anywhere as a command.
* Wait ...to wake up.
57 changes: 57 additions & 0 deletions bash-script/sunrise.alarm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# A simple bash script alarm to mimic a "natural" sunrise light wake-up.
#
# This code is under MIT licence, you can find the complete file here:
# https://github.com/Gregory-K/tplight-circadian-alarm
#

# enter your bulb's IP address
bulb=xxx.xxx.xxx.xxx

echo "What time do you want to wakeup? (HH:MM)"
read target

# convert wakeup time to seconds
target_h=`echo $target | awk -F: '{print $1}'`
target_m=`echo $target | awk -F: '{print $2}'`
target_rh=`dc -e "$target_h 1 - p"`
target_s_t=`dc -e "$target_rh 60 60 ** $target_m 60 *+p"`

# get current time and convert to seconds
clock=`date | awk '{print $4}'`
clock_h=`echo $clock | awk -F: '{print $1}'`
clock_m=`echo $clock | awk -F: '{print $2}'`
clock_s=`echo $clock | awk -F: '{print $3}'`
clock_s_t=`dc -e "$clock_h 60 60 ** $clock_m 60 * $clock_s ++p"`

# calculate difference in times, add number of sec. in day and mod by same
sec_until=`dc -e "24 60 60 **d $target_s_t $clock_s_t -+r%p"`

echo "Sun will rise at $target_rh:$target_m."

sleep $sec_until

echo "Sunrise begins!"

# rise
tplight on $bulb -b 5
tplight temp $bulb 2700
sleep 300
# 00:05
tplight on -t 300000 $bulb -b 25
sleep 300
# 00:10
tplight on -t 600000 $bulb -b 35
sleep 600
# 00:20
tplight temp -t 30000 $bulb 3000
tplight on -t 600000 $bulb -b 50
sleep 600
# 00:30
tplight temp -t 30000 $bulb 4000
tplight on -t 600000 $bulb -b 70
sleep 600
# 00:40
tplight temp -t 30000 $bulb 5000
tplight on -t 600000 $bulb -b 100
# 00:50

0 comments on commit d285638

Please sign in to comment.