Garage Lights Automation: Solving the Daytime Trigger Issue

I’ve been working on perfecting my garage lights automation, and I wanted to share my journey in case it helps others who might be facing similar challenges. The goal was simple: have the garage lights turn on when the garage door opens, but only during darker hours—specifically, a bit before sunset and a bit after sunrise. The automation itself works flawlessly when the conditions are met, but I noticed an unexpected behavior—it was triggering all day long, regardless of the time. This was perplexing and a bit frustrating, to say the least.

After some trial and error, I realized the issue stemmed from how the conditions were structured. The original setup used a combination of state triggers and time-based conditions, but it wasn’t accounting for the fact that the time-based conditions needed to be active only during specific periods. I decided to break it down step by step.

First, I simplified the triggers to focus solely on the garage door sensors. This meant removing the time-based conditions from the trigger section and instead incorporating them into the conditions. By doing this, I ensured that the automation would only activate during the designated ‘darkness’ window. I also restructured the actions to clearly separate the ‘lights on’ and ‘lights off’ sequences, making the logic more straightforward.

Here’s the revised setup that worked for me:

yaml

  • alias: Garage Lights
    description: Garage Lights On when any door is open between sunset and sunrise
    trigger:
    • platform: state
      entity_id: binary_sensor.garage_door_sensor
    • platform: state
      entity_id: binary_sensor.house_garage_door_sensor
      condition:
    • condition: or
      conditions:
      • condition: sun
        before: sunset
        before_offset: -00:30:00
      • condition: sun
        before: sunrise
        before_offset: 00:30:00
        action:
    • choose:
      • conditions:
        • condition: or
          conditions:
          • condition: state
            entity_id: binary_sensor.garage_door_sensor
            state: ‘on’
          • condition: state
            entity_id: binary_sensor.house_garage_door_sensor
            state: ‘on’
            sequence:
        • service: switch.turn_on
          target:
          entity_id: switch.garage
      • conditions:
        • condition: and
          conditions:
          • condition: state
            entity_id: binary_sensor.garage_door_sensor
            state: ‘off’
          • condition: state
            entity_id: binary_sensor.house_garage_door_sensor
            state: ‘off’
            sequence:
        • service: switch.turn_off
          target:
          entity_id: switch.garage
    • default:
      mode: single

This revised version ensures that the lights only respond to door activity during the specified ‘darkness’ window. It’s been running smoothly for a few days now, and I’m thrilled with the result. The key takeaway here is the importance of carefully structuring conditions and triggers to avoid unintended behavior.

I’d love to hear if anyone else has tackled similar automation challenges or has tips for refining these kinds of setups. Happy automating! :rocket: