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.

Get started

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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
3 Likes

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?

1 Like

What do you mean?

1 Like

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

Take a look to my blueprint, i made a condition for run only during the afternoon.

2 Likes

I use this Blueprint all the time. I wanted to try and modify it to select color, kelvin or brightness. Any thoughts on how to do that?