Wednesday, December 26, 2018

Christmas Tree Timer and Switch

Didn't do the Christmas tree to music this year. I did however setup a simple timer and override switch so the tree would turn off and on automatically.

I setup a simple relay attached it to the Raspberry Pi and wrote the Python Script below. I wired up a light switch (hadn't done this before so that was fun) to the Pi with some wire nuts. The Light switch will override the timer. So if you want the tree to stay on longer just flip the switch to on.

Here are some pictures.


Look at the sweet duct tape job

The light switch was connected to GPIO pin 20 and ground. I had to use the internal pull_up_down resistor to make it work. Found a nice little function that takes in the current time, start time and end time. The function will determine if the current time is between the time range you set. Worked really well for this project.

Christmas tree would light up at 6:00AM and then turn off at 10:00AM. Then it would light up at 4:00PM and turn off at 10:00PM. It would check every 5 seconds to see if it needed to turn off or on. Then if you flip the switch it would not check for time of day and would just leave the relay in the on position.