Python alarm running on a Raspberry Pi which controls a LED strip. An alarm clock that is not like any, it imitates the sunrise.
It has a simple web interface where the alarm time can be set, for this purpose the web server only turns on in a specified time period. The web interface turns back on before the alarm goes off, so it can be turned off without waiting. The alarm time indicates when the sunrise is at its brightest, yellow phase. To turn off the alarm a passcode is required which is different for each day of the month. The light goes off, the web server goes off again.
Read more about it in my blog post series: Sunrise Alarm Clock Using A LED Strip Series.
It works with Python 3.8 or higher (tested with Python 3.10), install the dependencies from the requirements.txt
.
There are some basic settings in environment_variables.py
Name | Type | Description |
---|---|---|
DEV_MODE |
bool |
If it is on, then a PySimpleGUI window will serve as the LED instead of changing the actual PI's state (with pigpio ). |
WEB_SERVER_IP |
str |
Web server IP address. |
WEB_SERVER_PORT |
int |
Web server port. |
PASSCODES_JSON_PATH |
str |
Where the passcodes are held for each month day. |
ALARM_JSON_PATH |
str |
Where the main alarm/sunrise config is at. |
SETTINGS_JSON_PATH |
str |
The alarm time and web server settings file path. |
RGB_PINS |
dict |
The GPIO pin number for each color: red , green , blue . |
CLEVER_SLEEP_SECS_SEGMENTS |
int |
How frequently the alarm will check if it has been turned off. |
Before starting make sure to run generate_passcodes.py
. This will write out the passcodes for each day. These are shown once, then they are hashed. Write these down in order to stop the alarm later. 31 passcodes are generated, meaning the passcodes are same for each month. (The hashed passcodes will be at PASSCODES_JSON_PATH
.)
There is a basic alarm included in the repository (alarm.json
). Which is a sunrise that is about 15 minutes long. Feel free to use this, or you can create your own one with the easy methods I made.
The JSON must be an object. It operates with steps. It has 3 settings:
wait_time
: This is the default wait time in seconds, it is like a variable that can be reused. This is required.when_yellow
: When will the alarm turn yellow, meaning the sun came up fully. It is necessary because, based on this, the light will be completely yellow at the set alarm time. The sunrise will start atalarm_at - when_yellow
. It is in seconds. This is required.repeat_last
: A number to repeat last X steps. Not required.
Steps change the light, the code will execute step after step. It is an array. There are two actions: range
and transition
each iterate and change the rgb colors based on the modify
. Properties of a step
:
sleep
: How much time should the step wait, or should it wait (ifrange
ortranstion
is defined) after each modify related iteration. Can be any number or"wait_time"
. This is required. (Note: a simple wait step can be created too.)range
:start
,stop
,step
these 3 properties can be set (integers), it is a Python range in a for loop where each iteration themodify
is run.transition
: To calculate the transition to a color.red
,green
,blue
can be set (integers). Steps can be defined with thesteps
property, the default is 255 meaning it will step the smallest possible.modify
: What will be modified at this step or (ifrange
ortranstion
is defined) at each iteration. Any arithmetic calculation can be used (parentheses too). Few built in variables can be used:red
,green
orblue
to get the current color values.- If it is running in a
range
, then usei
to get the current iteration's number. - If it is running in a
transition
, thenr
g
b
can be used to get the transition related values.
Make sure you restart the app after editing server_state
settings. The alarm will be scheduled after the web server goes off.
alarm_at
: When the alarm will go off, the web interface will change this. It is in HH:MM format (string).server_state
:turn_on_at
: When the web server should turn on at, so the alarm time can be set. It is inHH:MM
format (string).turn_off_at
: When the web server should turn off at, so the alarm can be scheduled. It is inHH:MM
format (string).turn_on_before_alarm
: How many seconds before the sunrise start the web server should turn on, so it can be turned off before the alarm goes off. It is a number.
Any contribution is welcome. I made this for myself. No updates will come till someone requests it, or I need another feature // I discover something.