Motion Activated Light, but with conditions

Since Edward created the solution for this, HA has added a condition selector.
Here is exactly what Edward wrote, but instead of locked in conditions, I inserted the condition selector code, so the user can write their own condition when they set up their automation. Or just leave it blank, and it will run without conditions…

blueprint:
  name: Motion-activated Light (With condition selector that can be set by user at automation build.)
  description: Turn on a light when motion is detected.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          filter:
            domain: binary_sensor
            device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    additional_conditions:
      name: Additional conditions
      description: |
        Extra conditions you may want to add to this automation 
        (Example: Home occupied, TV on, etc)
      default: []
      selector:
        condition:
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    sun_entity:
      name: Sun entity
      description: This is normally "sun.sun".
      default: sun.sun
      selector:
        entity:
          filter:
            domain: sun
    home_entity:
      name: Home entity
      description: This is typically "zone.home".
      default: zone.home
      selector:
        entity:
          filter:
            domain: zone

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

  # If you see 'Missing property 'conditions' it is a false error.
  # See https://github.com/keesschollaart81/vscode-home-assistant/issues/2786
condition:
  - alias: User pick
    condition: !input additional_conditions

action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target
3 Likes