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.

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

The Home Assistant Cookbook - Index.

27 Likes

Hehe…you should pin this one :face_holding_back_tears:

For the Node-Red folks:

I prefer this one for NodeRed :grin:

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

2 Likes

9 posts were split to a new topic: Motion Lights Help

12 posts were split to a new topic: Motion lights with presence

13 posts were split to a new topic: Motion Lights, please help

A post was split to a new topic: Stairs motion light help

2 posts were split to a new topic: PIR selection

A post was split to a new topic: Motion lights blueprint

Updated to use the new automation syntax.

Also moved a lot of support posts to their own topics.

If you have a support question then start a new topic and link to this guide.

1 Like