Pi-files: Frontdoor light switch based on local sunset/sunrise
I have a couple of front door LED lights which I would like to switch on automatically during the evening/night. The two conventional methods that are commonly available had their disadvantages:
A timer switch is the easiest and cheapest solution, but doesn’t take into account day light savings. Besides that, in Einhoven, the Netherlands where I live in december the sun sets around 16:30 while in June it doesn’t get dark before 22:00. A simple timer doesn’t take that into account either.
Since you only want the lights on when it gets dark, instead of time you can also use a light sensor to distinguish day and night. You have these front door lights that have this built in. The problem that I had with these devices is that they start bouncing (‘flickering’) around sunset/sunrise. They constantly turn on/off which causes damage to the LED lights I was using. This cost me already several expensive led lights.
Since I already have a Raspberry Pi installed in the hall way (used for the doorbell alert) I might as well hook up the front door lights. You can find on the Internet all sorts of timetables for the sunset/sunrise, so my Rpi should be able to use that same information as well. A small search on the world wide web led me to a Python package called PyEphem. This package can be used to do astronomical calculations and can tell you for example where a certain object (e.g. the sun) is with respect to the observer (which is me standing in my front yard). Very conveniently it also can calculate for you the upcoming sunset and sunrise. Isn’t that exactly what I need?!?
The LED lights are powered with a 12V AC-DC transformer. I put together a small electronics board to be able to use the GPIO’s 3V3 of the Rpi to switch the 12V LEDs. I used a IRL3103 N-FET. This is not really a deliberate choice but like most of my transistor/FET choices based on what I have lying around in the lab. Be aware that the N-FET needs to be able to switch with a Gate-Source voltage of 3V3. For example an IRF540 (which I used for a motion detector for a 12V ledbar) doesn’t switch with this voltage (Here I solved it by using a smaller BS170 N-FET and use that to switch a IRF 9540 P-FET). I added a manual switch to override the automatic switch in case I just want to turn on the lights. Parallel to the front door LEDs is a test led with a resistor onboard to be able to test the functionality without having to connect the actual front door lights.
For more detail: Frontdoor light switch based on local sunset/sunrise