Turn light on and off based on detected motion

This is a simple automation that turns a light on when there is motion, and turns it off when there is not.

blueprint:
  name: Motion Controlled Lighting
  description: Turn a light on and off based on detected motion
  domain: automation
  input:
    motion_sensor:
        name: Motion Sensor
        description: A sensor that detects motion
        selector:
          entity:
            domain: binary_sensor
    light:
        name: Light
        description: A light that is turned on and off
        selector:
          entity:
            domain: light
    duration:
        name: Duration
        description: How long the light should stay on for, after motion is detected, before turning off (defaults to 30 seconds)
        default: '0:00:60'

trigger:
  - entity_id: !input motion_sensor
    for: !input duration
    platform: state
    to: 'off'
  - entity_id: !input motion_sensor
    platform: state
    to: 'on'
condition: []
action:
  - data:
      entity_id: '{{light}}'
    service: 'light.turn_{{mode}}'
variables:
  motion: !input motion_sensor
  light: !input light
  mode: '{{ states(motion) }}'
mode: single
1 Like

I believe there’s already a blueprint for that built-in.

1 Like

Correct me if I am wrong. But I have not seen any built-in blueprints. Well when I got the feature noting was in there.

Look:

can’t you add time or time range to active automation?

What do you mean?

i want this auto can run 7pm - 1am , thanks

That’s not the purpose of this blueprint. You could ask on #configuration:blueprints and see if someone would make one that does that.

1 Like