Help with motion/door sensor activated light

I have a mudroom attached to my garage and want the mudroom light to turn on for 60 seconds when someone goes from the garage to mudroom only. I don’t want it to go when someone goes from the mudroom to the garage (i.e. leaving the house).

I have a motion sensor in my garage and a door sensor on the garage/mudroom door. Here’s the automation I came up with:

alias: "Motion Detected: Mudroom Light"
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.mudroom_door_sensor_opening
    from: "off"
    to: "on"
conditions:
  - condition: state
    entity_id: light.mudroom_light
    state: "off"
  - condition: state
    entity_id: binary_sensor.garage_motion_sensor_motion
    state: "on"
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.mudroom_light
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.mudroom_light
mode: single

The problem is its (understandably) still turning on when going from mudroom to garage as both sensors are ultimately being triggered in both situations. I essentially need the automation to run if the motion sensor is triggered first.

Please note: I did try swapping the door sensor and motion sensor in the automation but it did the same thing.

I’ve racked my brain trying to think of a different way to do this, and I think I’m just being dumb. Any suggestions?

Hi templeowls,

My suggestion is this scenario…

  1. trigger on the garage sensor
  2. condition that the mud light and the mud sensor be off
  3. action as a wait for trigger, and trigger on the mudroom sensor.
  4. turn on the mud light.

You may need to add a delay somewhere to fine tune, but that is where I would start.

I think that did the trick. Thanks!