Turn light on and off based on detected motion (with time range condition)

Based on system HA motion activated light but improved with Switch domain and also time range condition. So you don’t need to a light but also a switch like sonoff or smart plug.

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

For example i use this blueprint for turn on or off my christmas tree led lights (controlled by a smart plug)

Next improvement will be considering sun condition i think.

More info here on GitHub Repo

blueprint:
  name: Motion-activated Light Switch
  description: Turn on a switch when motion is detected.
  domain: automation
  source_url: https://github.com/fabiosoft/HA-Motion-activated-Light-Switch/
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    light_target:
      name: Light Switch
      selector:
        target:
          entity:
            domain: switch
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds
    start_time:
      name: Start Time
      description: Time action should start
      default: "17:00:00"
      selector:
        time:
    end_time:
      name: End Time
      default: "00:00:00"
      description: Time action should stop
      selector:
        time:

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"
condition:
  alias: "Time 17~00"
  condition: time
  # At least one of the following is required.
  after: !input start_time
  before: !input end_time
action:
  - service: switch.turn_on
    target: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: switch.turn_off
    target: !input light_target
1 Like

Hello and Happy 2022!

I had always 2 automations to turn on the lights and then another to turn off the lights. This is great Auto.
But I alreayd made some tweeks but I would love to know if its possible to also have these 2 imputs to choose.
I am trying to have a a condition that if one of the lights in the bedroom is on, then this automation wont turn on. I can put this on the code, but what i would love is to have the option on imput to choose the entities. is this possible?
and the other imput is to put the data of the light. Brightness and Color. Can we put these options to choose on the imputs?
Best regards

start with making an automation… translate the automation to a blueprint is easier

Adding sun state would be good as most of lights don’t need to come on due to natural light, but after sunset is like the lights to be triggered… Great job though :+1:

is any chance to add a blocking entity. like if a door contact its close do not turn off ???

hello, this sounds like something I was looking for.
My idea is to have a motion sensor in the hallway, which will work only between 21:00 and 07:00. The plan is, when the kids want to go to the toilet, there would be some light.
But… can this use or be adjusted to make use of dimmable light bulbs. let’s say, between 21:00 and 07:00, if motion is present, turn ON the light at 10% brightness, or something like that, so that the full 100% brightness won’t be painful for the sleepy eyes.

Thank you in advance.