Motion activated lights automation

This gets asked a lot so here is an example for automating a light to come on with movement and go off after there is no movement for a short time.

trigger:
  - platform: state
    entity_id: binary_sensor.your_motion_sensor_here # change this
    to: 'on'
  - platform: state
    entity_id: binary_sensor.your_motion_sensor_here # change this
    to: 'off'
    for:
      minutes: 2 # adjust as necessary 
action:
  - service: "light.turn_{{ trigger.to_state.state }}"
    target:
      entity_id: light.your_light_here # change this
mode: single

The Home Assistant Cookbook - Index.

17 Likes

Hehe…you should pin this one :face_holding_back_tears:

For the Node-Red folks:

I prefer this one for NodeRed :grin:

This is great, thanks for providing it @tom_l.

I’d like to have a group of 3 lights pulse on/off for say 1 minute after motion is detected. Is there a way to achieve this using your example?

Start another topic. It’s beyond scope for this one.

1 Like

4 posts were split to a new topic: Help with motion lights

Since not all motion sensor return to an ‘off’ state, you might end up with using a delay.
In that case, you need to put the automation in restart mode, so it will reset the delay when re-triggered.
f.e. my mqtt motion detector:

alias: Hallway Downstairs Light on Motion
description: Off when no motion for 3 mins
trigger:
  - alias: When motion detected hallway downstairs Pir] was trigged by MQTT
    platform: mqtt
    topic: Tasmota/tele/RESULT
    payload: D4A0EF
    value_template: '{{ value_json.RfReceived.Data}}'
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.hallway_downstairs
  - delay:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.hallway_downstairs
mode: restart

1 Like