Every year, the exterior holiday lighting gets reluctantly set up. It’s part of McMansion life, a requirement to appear as though you’ve made an attempt to decorate for the season. Between the colored optical projectors, to strings of lights haphazardly strung around the front porch, it all ends up needing to be plugged in and turned on/off. For years, the solution to this was a mechanical timer, with on and off markers which could be inserted around the ring to turn the timer on and off at the right time. This was all fine and good, but with little precisoin, no adjustability for the seasons or special events, and the inevitable time error if there is ever a power outage. But! No more! We can fix all of this with Home Assistant.

Sonoff Smart Plugs

Any smart plug will work for this, as long as it works with Home Assistant. I have a Sonoff S26 which is flashed with Tasmota (see Tasmota Day for instructions), and this allows me to keep all of the control on my local network (no cloud dependencies) and trust in the integrity of the firmware. Tasmota speaks MQTT natively, and I will add it as an MQTT switch in my switch.yaml file. Note that there is a Tasmota integration which you can use directly, but my Sonoff’s are still setup with the MQTT topic structure from when I used Node-Red entirely, so I’m doing it this way.

MQTT config:

  #Holiday lighting switch via Sonoff relay with Tasmota
  - platform: mqtt
    name: Holiday Lights
    unique_id: holiday_lights
    #Command to switch
    command_topic: "raw/tasmota_B70C5D/cmnd/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true
    #Availability of switch
    availability:
      - topic: "raw/tasmota_B70C5D/tele/LWT"
        payload_available: "Online"
        payload_not_available: "Offline"
    #Status of switch
    state_topic: "raw/tasmota_B70C5D/stat/POWER"
    state_on: "ON"
    state_off: "OFF"

Sun Based Timers

I started with a simple sun based timer. I used a single automation instead of an on + off automation to reduce clutter in my Automations page, but it has a trigger for each event instead of a delay to turn the lights off (which could fail due to server restarts duringt the delay time). I decided that 30 minutes after the sun is below the horizon was a good time to turn the lights on, and 4 hours after that is a good time to turn them off. As the seasons progress, this will gradually turn the lights on earlier. Because Daylight Savings Time is the the worst, it’s basically dark out the entire time I’m at home, so I need many hours of holiday lights to cheer me up.

If I have an event, I can always turn off the automation and manually control the lights. If I setup a more complex lighting system in the future, you followers will be the first to know.

Here is the automation I setup, in YAML form. You should be able to copy it in as YAML and then switch back to the visual editor without issues. I like using a single automation with multiple triggers for both on and off, since it reduces the visual clutter in the automations editor, but really this could have been done with two simple automations instead.

alias: Holiday Light Timer
description: ''
trigger:
  - platform: sun
    event: sunset
    id: 'On'
    offset: '+30:00'
  - platform: sun
    event: sunset
    id: 'Off'
    offset: '+4:30:00'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'On'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.holiday_lights
    default:
      - service: switch.turn_off
        target:
          entity_id: switch.holiday_lights
mode: single