How to Automate the Turn-On Time of a Deco Light

I own a decorative light for the winter which I controlled using a simple time switch in the past. The time of dusk is continually shifting, so I had to adjust the turn-on time multiple times each year.

This year, I planned to automate the turn-on time. I tried to find a light controlled switch, which automatically enables the decoration on dusk and disable it on dawn. I saw no suitable one.

I ended adding an own switching circuit to the decoration. This article describes how to build an own controller as I did and highlights a few problems you may encounter.

The Issues with Off-the-Shelf Solutions

My requirements for the off-the-shelf solutions were:

  • Setting to adjust the light level.
  • Suppression/identify the light from the decoration.
  • Turn off at a given time or dawn.
  • It shall work at a temperature of -10ºC.

Sadly, I found no simple device, which matched all my requirements. I also noticed, most of these devices had horrible ratings and reviews – mainly because they lacked the described features.

Adjusting the light level seems a straight forward requirement. The brightness, where you like to turn the decoration on is a matter of personal taste. Most devices I found do not let you adjust this.

If the decoration is turned on, it will naturally get brighter outside. If the switch does not compensate for this fact, the light will start to blink. In this case, you had to place the sensor somewhere carefully it is not affected by the light of the decoration.

Most devices just let you select a duration, how long the light stays on. This is the cheapest way to implement a device like this. It makes not much sense though. Because the time of the dusk is moving, the time when the light turns off shifts as well. Useful is either turning the light off at dawn, or at a fixed time.

Then, there I found one device which had all the previous features, but it was rated to indoor use only. The minimum working temperature was 5ºC.

Initial Situation

The initial situation is shown in the following illustration:

A timer connects to the mains plug. The mains adapter of the decoration connects to this timer and converts the 240V AC power to 24V AC. This AC voltage is somehow a standard way to power old, filament lamp based decorations.

Modern LED decorations need to be DC-powered, to reuse the old AC power plugs, an AC/DC converter is put in front of the actual light. After the converter, you have 24V DC in theory. If you measure the voltage with an RMS multimeter, you will see 24V on display. The AC/DC converter is as simple as possible, and you have rectified ~42V on this line.

Where to Place the Switch

Adding the switch to the mains line would be the best and most efficient solution. It would completely switch off the power and stop any no-load current. Also you could plug any number of decorations into this switched main line and control all of them synchronously.

It is also the most demanding place to place the switch. The mains power, with 110V or 240V AC, can be really dangerous. Combined with the difficulties of outdoor usage, it is no real option for a quick automation solution. If you lack the required education, please do not consider this option at all.

Alternatively use a pre-made solution, where the mains switch is properly implemented and enclosed and you can control it using an extra-low voltage device.

In contrast, adding a switch in front of the decoration, at the low voltage side, is dead simple and safe. Most of the complex work is done and you can also easily tap into this wire to get power for your controller.

Adding the Switch

I use an enhanced P-channel power MOSFET as a switching component. I cut the wire at a suitable place between the AC/DC converter and the decoration and connect it to a small stripboard.

The circuit for the switch part is shown below.

The power supply is connected to the left side, the decoration is connected to the right side. To control the switch, a signal wire is connected to this circuit, shown towards the bottom of the circuit in the schema above.

The cable to the controller has three wires. VCC, GND and the switch line. To enable the decoration, the switch line has to be drawn to GND. This allows controlling the switch using a 3.3V or 5V logic and an N-Channel MOSFET.

Choosing the Right MOSFET

Choosing the right MOSFET for the task is important. In this configuration, you like to check the following parameters:

  • P-Channel MOSFET
  • Drain-Source Voltage (VDS)
  • Continuous Drain Current (ID)
  • Maximum Power Dissipation (PD)
  • Gate-Source Threshold Voltage (VGS)

In my case, the DC voltage after the AC/DC converter is a rectified voltage between 1V and 42V. Therefore, the MOSFET has to handle at least 42V drain-source voltage (VDS).

Make sure you add a large safety margin to this value. There can be voltage spikes from the mains line, which can rise the usual voltage by a few volts.

I used the Vishay IRF9530 for my solution. It has the following maximum values:

Drain-Source Voltage (VDS)-100V
Continuous Drain Current (ID)-12A
Maximum Power Dissipation (PD)88W
Gate-Source Threshold Voltage (VGS)-2.0 – -4.0

The LEDs in my decoration consuming just around 120mA, with the 12A maximum I am well inside of the specification range of the continuous drain current. If you have larger currents in your project, make sure you also add a heat sink to the MOSFET.

I recommend measuring the current of the decoration after cutting the wires. This is the best way to get a realistic value. Make sure you also look into the maximum and minimum voltage you get, not only the measured RMS value. Often, the AC power is only rectified, but not regulated and smoothed.

The gate-source threshold voltage is important to calculate the resistor for the pull-up. If the input voltage is 42V, you need to pull this voltage to 38V to enable the MOSFET. With this low threshold voltages, this is very simple to do.

If you have some unusual high gate threshold voltages in the FET specification, better search an alternative. All common power MOSFETs have threshold voltages in the range between 1V and 4V.

Sealing the Case

If you seal electronics for outdoor use, water is really a problem. It creeps along wires into the case and causes endless problems. To prevent this, just seal the electronic parts from the environment with a layer of coating.

Make sure you test the switch before sealing it. It is very annoying to peel the electronics out of the heat shrink tube and remove the coating if it does not work as expected. Also, test the switch after sealing.

I first use a heat shrink tubing to enclose the board with the MOSFET. While the material is still hot, I added the two zip ties to the ends. Next, I filled the whole enclosure with DOWSIL 3140 RTV Coating.

To get this result, I used a syringe with a needle to fill the tube from the middle. The needle needs to have a large diameter to work with the thick coating fluid.

If you do this correctly, there is no space left where moisture can creep into the enclosure. Electronics protected like this, withstand harsh outdoor conditions over many years.

Create the Controller

The controller is just connected using the three wires branching from the switch. There is almost no current involved for the controller, therefore you can use a very thin signal wire.

This control wire can bridge large distances. You can either place the controller near the decoration or use a long wire to place it somewhere protected from the environment.

You can use any micro controller to control the lights of the decoration. The board shown above is not the final version, I changed the voltage converter later to a more reliable one.

I used the following components to implement the dusk/dawn sensor:

The schema of my controller is shown below:

There are two important parts in the circuit. First, there is the N-channel MOSFET Q2, where I used the cheap 2N7000 from Diotec. It is required to decouple the high voltage from the switch to the logic. If you connect the switch line directly to the microcontroller (don’t!), you put the rectified 42V to the chip – which will most likely kill it.

Using an N-Channel MOSFET, the reference voltage to enable the FET is GND, which has a defined level. Therefore raising the voltage over 3V on the gate, will enable the FET and pull the voltage on the gate of the P-channel MOSFET to GND.

The second important part is the voltage converter. I used a relatively expensive Recom R-78C5.0-1.0 for this task. It is a switched voltage converter which contains everything required for the task. No additional capacitors are required. This component even handles the rectified voltage with no complaints.

I recommend using a switched voltage converter like this. Cheaper LDO converters are not very efficient if you convert 42V down to 5V. Cheaper components will need additional components, like capacitors and inductors.

The Adafruit Trinket 5V is the perfect solution for a simple controller like this. It is really cheap and provides enough CPU power with the ATtiny85 even for complex tasks.

Sealing the Controller

Sealing the controller is like sealing the switch. I also used heat shrink tubing as a first enclosing, then filled the tube with DOWSIL 3140 RTV Coating from the middle.

First I added coating around the USB connector and let it dry. I did this to prevent coating fluid enter the connector when I fill the tube.

Make sure to program and test the controller before sealing it. Removing the heat shrink tubing and coating is very annoying.

Programming the Microcontroller

The following code is an early version I used for the controller, feel free to use it in your own project. Please accept my apologies for the lack of documentation in this code.

const auto cLedPin = LED_BUILTIN;
const uint8_t cSwitchPin = 0;
const uint8_t cSensorPin = 2;
const uint8_t cSensorInput = 1;
const int cLightThreshold = 0x10; // The threshold value for the light.

const int cSwitchDelay = 60; // 1 min
const int cSwitchBlockDelay = 600; // 10 min

bool gState = false; // The current state of the light.
int gSwitchCounter = 0; // The current counter for a switch.
int gSwitchBlockCounter = 0; // A counter to block switching back.

void setup() {
  // Set the modes of the used pins.
  pinMode(cLedPin, OUTPUT);
  pinMode(cSwitchPin, OUTPUT);
  digitalWrite(cSwitchPin, LOW);
  pinMode(2, INPUT);
  // Blink the LED to indicate start of the software.
  for (uint8_t i = 0; i < 8; ++i) {
    digitalWrite(cLedPin, HIGH);
    digitalWrite(cLedPin, LOW);

int readSensor() {
  // Interpolate a series of readings.
  int result = 0;
  const uint8_t readCount = 15;
  for (uint8_t i = 0; i < readCount; ++i) {
    result += analogRead(cSensorInput);
  return result/readCount;

void loop() {
  if (gSwitchBlockCounter > 0) {
    digitalWrite(cLedPin, HIGH);
    digitalWrite(cLedPin, LOW);
  } else {
    // Read the current sensor value.
    const int value = readSensor();
    const bool detectedState = (value <= cLightThreshold);
    digitalWrite(cLedPin, (detectedState?LOW:HIGH));        
    if (detectedState == gState) {
      gSwitchCounter = 0;
    } else {
      if (gSwitchCounter >= cSwitchDelay) {
        // Switch the light.
        gState = detectedState;
        gSwitchCounter = 0;
        digitalWrite(cSwitchPin, (detectedState?HIGH:LOW));        
        gSwitchBlockCounter = cSwitchBlockDelay;

Further Development Inspiration

  • You can use a more powerful microcontroller.
  • A different voltage, e.g. 3.3V, for the control board is no problem.
  • You can add a real time clock to also use the time if the day.
  • Detect light changes after enabling the switch and calculate the required difference for dawn detection.
  • Calculate the time between dusk and dawn and calculate the middle as turn-off time.
  • Add a PIR sensor to detect motion and only enable the decoration if someone is around the house.


Automate the on and off time of decorations is safe and simple on the low voltage side. It can be done with a few components and let you write your own automation code.

If you have questions, miss some information or just have any feedback, feel free to add a comment below.

Have fun!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.