Light Automation working odd

I setup an automation to turn my hall light when I opened the front door and the sun is set and leave the light on for 3 mins. The light comes on when I open the door but sometimes it will turn off as soon as the door closes. It should stay on for 3 mins. Here is my automation:

## Turn Hall light on when I get Home
  - alias: Turn Hall light on when I get Home
    trigger:
      platform: state
      entity_id: binary_sensor.front_door
      to: 'on'
    condition:
      condition: and
      conditions:
        - condition: sun
          after: sunset
          after_offset: "-00:30:00"
    action:
      - service: homeassistant.turn_on
        entity_id: switch.front_hall_light_switch
      - delay: '00:03:00'
      - service: homeassistant.turn_off
        entity_id: switch.front_hall_light_switch

Do you have a door sensor that is based on a magnet?

Could it be that when the door (nearly) closes, a new signal is send to home assistant that triggers something which in turn switches off the light?

Are there other automations that control the light in question?

What do you see in the home assistant log?

Yes it is a magnet sensor.

I did have a old automation that turned off the light when I left home but I’m sure it is deleted now.

I’m going to comment out where the automation turns off the light to see if that is it:

  - service: homeassistant.turn_off
    entity_id: switch.front_hall_light_switch

You can delete delay part also and create another automation for turning light off. This way it doesn’t matter how many times you opened and closed door as long as they stay closed for 3 minutes. Also add condition for front_hall_light_switch is on.

  trigger:
    platform: state
    entity_id: binary_sensor.front_door
    from: 'on'
    to: 'off'
    for:
      minutes: 3
2 Likes

Nice addition, I’m going to keep that in mind for my own home :slight_smile: