Sleep training with a raspberry pi

I used to wake up in the middle of the night and I would often check my watch or a clock to see what time it was. Seeing that it was 2 or 3 am would often make me more anxious and I would have a hard time falling asleep. I wanted to train my mind to wake up naturally around 4:30 am with a light. Basically I didn’t want to use sound, because I didn’t want to wake up early if I didn’t need to, and I didn’t want to wake up anyone else nearby. I wanted a light that would automatically turn on between 4:30 am to 6 am. So if I woke up earlier, I would just open my eyes and see if the light was on, if it was on I could get up, if it was off, I would just tell my stuff, I can get more sleep. I searched around on amazon and surprisingly couldn’t find something that did this. I was also unable to use my iphone, there is no automation to have the screen stay on with a schedule. So I grabbed a raspberry pi I already had and bought a $2 usb light. I thought I would need to write code to turn on/off the usb light, but it was just a simple cli command. The pi also is synced with ntp, so the time is always correct and I can take the device with me if I ever need to travel and keep my schedule. And I love the feeling of sshing into a tiny server on my network, technology can be amazing at times. I now have a $20 fully programmable silent alarm with no clock! Here is my crontab:

30 4 * * * echo ‘1-1’ | sudo tee /sys/bus/usb/drivers/usb/bind

0 6 * * * echo ‘1-1’ | sudo tee /sys/bus/usb/drivers/usb/unbind

This works great and I got great use out of my raspberry pi.

Leave a comment

Your email address will not be published. Required fields are marked *