Automation - Use motion to turn on light for some time using several conditions

Hi all,

I have a Philips Hue Outdoor Motion Sensor in the garden. The garden lights are automated through some Z-Wave Smart Plugs.

My ambitions it to have the following automation. If

  • the motion sensor detects motion, and
  • the time is between sunset and sunrise, and
  • the light is not yet on

then turn on the light for 20 seconds.

I seem to get most of the automation working, except for the 20 second time rule. Below the code I’ve used. Any help would be highly appreciated :slight_smile:

alias: Test
description: ""
trigger:
  - type: motion
    platform: device
    device_id: e571f625f4b2e2f2b2a559ca60bf928a
    entity_id: binary_sensor.hue_outdoor_motion_sensor_1_motion
    domain: binary_sensor
condition:
  - condition: sun
    after: sunset
  - condition: device
    type: is_on
    device_id: a0d8b076a688dbfecf2f9c4cf79744e0
    entity_id: light.stopcontact_lamp_spotjes
    domain: light
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.stopcontact_lamp_spotjes
mode: single
alias: Test
description: ""
trigger:
  - type: motion
    platform: device
    device_id: e571f625f4b2e2f2b2a559ca60bf928a
    entity_id: binary_sensor.hue_outdoor_motion_sensor_1_motion
    domain: binary_sensor
condition:
  - condition: sun
    after: sunset
  - condition: device
    type: is_on
    device_id: a0d8b076a688dbfecf2f9c4cf79744e0
    entity_id: light.stopcontact_lamp_spotjes
    domain: light
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.stopcontact_lamp_spotjes
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.stopcontact_lamp_spotjes
mode: single

Thanks a ton, BebeMischa. How obvious, but I’ve clearly looked too much a the screen for missing this option. Really appreciate your fast and clear response. :slight_smile:

1 Like