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

The Home Assistant Cookbook - Index.

30 Likes
The Home Assistant Cookbook - Index
If no motion for 4 minutes turn off, but if motion, reset the 4min timer
Best Practises for Motion Activated Lights
Turn on light on motion, but after delay, then turn off
Motion activated light
Motion Detector - pause countown to turn off light when motion is detected still
Problem With Motion Sensor Automation
Two IKEA Vallhorn ZHA movement sensor logic
Hue motion sensor: How to set the timeout for occupancy?
Can i reliably use PIR sensors in kitchen to control lights without them switching the lights off when i’m still in kitchen
Motion-activated Light Blueprint really needs a "time of day" IF
Motion detection on/off mistake
Complex automation problem - combining timer, motion sensor, button and light
Motion activated lights switch on and off
How to turn off light if no motion is detected for 10 minutes?
Motion-Activated Porch Light Automation
Simple Lights on when presence and off when clear
Using ELK Motion to trigger Zwave Switch
Timer is not resetting
Keep light on with presence
Excessive memory usage when two automations enabled
Cannot get PIR Automation working,
Motion sensor - turn off when no motion, but light has been manually turned on
Occupation groups suddenly not working correctly
Slow motion detection vs Motion light by HA
Automation for motion controlled light
Home Assistant Cookbook - Discussion Thread
Motion sensor re-trigger
Wetting my nose with autmations: how to merge?
Another motion and switch automation test approach - advice needed
Automatic lights at certain time intervals
Switch off lighting after a certain amount of time (cancelqueuedcommands)
Trying to create if then else, type construct
Timer/Schedule based control
Automation lights based on motion or door sensor will not not work
How to write a single automation for a motion-triggered light with time-out for turning off?
Automation Etiquette ~ Turning on Lamp Multiple times with a PIR
How to add an additional condition to a motion controlled light YAML
Using zigbee smart sensor model C3007 to automate my 4 rooms. Having so much issues
How to turn off lights when all PIR sensors are not occupied OR unavailable, for 5 minutes
How to capture a trigger event in UI
Home Assistant Cookbook - Discussion Thread
Single run automation being retriggered
Voice assistants 2
Automation trigger works but action doesn't run
Home Assistant Cookbook - Discussion Thread
How to add timer to my first automation
Why the light stays on when motion is long gone?
Noob questions!
Logbook question
Confused on FORor Duration in Automations using Aqara P1 Sensors & ESPHome
[general advice] How to group and streamline automations (today)?
Motion activated lights automation help
Question regarding binary sensor automation
Config to switch off a light when no motion is detected
Help with Yaml code for PIR Occupation
Advanced Automations in Home Assistant
Automation to turn light on after motion, THEN OFF after a period of time?
No Motion - turn off lights
WTH I can not easily set a one-time-use switch on/off timer without
WTH I can not easily set a one-time-use switch on/off timer without
Home Assistant Cookbook - Discussion Thread
Automation Delay Timer Control
Automation/Script for turning on/off lights
Combine on and off into the same automation
Start second timer after first finished
Automation Mode: Restart - Correct Logic - No Blind Alleys
Switch lights off after 5 minutes automatically
How to use one Aqara P1 sensor to turn lights on then off
Hold lights while on sensor on
Time to leave the light on after last motion is detected problem
Waterproof / outdoor Motion Sensor recommendations
Do something when light is turned off, but only if it has been on for at least 15 minutes
Motion activated lights automation problem after HA reboot
Sonoff 4ch - motion/door sensor activated, timer turn off
Blocking an automation
Motion lighting
Automation fundamentals
Simple automation not behaving as expected
How to restart automation (stop motion) is started and when there is motion it restart
Home assistant motion sensor lighting
Keeping Fully Kiosk dashboard awake
Wait until "FOR" but in the middle of the Node RED flow
Cancelling an automation
Philips Hue Sensor + Illumiance Automation issue
Automation.turn_on giving odd results
Motion Sensor Continual detection results in lights off
Motion light doesn't switch off
Motion sensor to action problem

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

3 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