Turn on lights when I open the front door

Hi everyone.

I am trying to automate my hallway lights when I come home.

I have a HUE motion sensor outside the door, and on the door I have a Aqara contact sensor.

What I am trying to achieve is to turn on the lights when I come home, that is, HUE motion sensor detects the motion outside the door and when the Aqara contact sensor on the door state changes to open the lights turn on. I don’t want the hallway lights to turn on when I open the door and I am about to leave, so, the order of state changes matters. First motion/occupancy detected, then binary sensor on the door changes to open, only then will the light turn on.

Any idea how to achieve this with a automation ?

Thanks.

1 Like
alias: Entrance Light
description: ''
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.entrance_door
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.sonoff_motion_sensor
    state: 'on'
action:
  - service: light.turn_on
    data: {}
    entity_id: light.entrance

1 Like

Perfect.

That state from, to was the missing piece. Thanks buddy.

I’m not sure that really was the missing piece.

A binary sensor, during normal operation, only ever has two states - on and off. so the only state it can usually come from is off. The only other state it could have if something has failed is ‘unavailable’.

Instead of using the Trigger type State from - to I was using Trigger type Device and the trigger was contact is open. I wasn’t aware of the State trigger :upside_down_face:

While I don’t use the UI editor and therefore don’t use the device triggers I would assume that “contact open” from a device is functionally equivalent to “to on” from a state trigger.

But if it’s working then that’s all that really matters.