Motion Activated Light, but with conditions

Thank you for creating this. Amazing!

I am actually struggling with the import button :wink: Weirdly I get the error “No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax.”

Having said that, I was just trying around because I have never used this button and find it nice to import with a simple click … but I can just copy it manually which I’ll do now

Works like a charm! Thank you very much!!
(And this also helps me a lot as a starting point for adjusting more things)

1 Like

Thanks for the reference. Yes I think for now that’s a bit too overkill.

Good to hear that.

But please be aware that with this additional complexity you can have additional unexpected results… I mean, if your phone gets ou of battery the system might interpret you are not at home and then stop your motion based lights.

The way I solved this is to use a blueprint automation for motion detection and then two additional automations to enable and disable the automation (call service automation.turn_off/on) at sunrise and sunset.

1 Like

Since Edward created the solution for this, HA has added a condition selector.
Here is exactly what Edward wrote, but instead of locked in conditions, I inserted the condition selector code, so the user can write their own condition when they set up their automation. Or just leave it blank, and it will run without conditions…

blueprint:
  name: Motion-activated Light (With condition selector that can be set by user at automation build.)
  description: Turn on a light when motion is detected.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          filter:
            domain: binary_sensor
            device_class: motion
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    additional_conditions:
      name: Additional conditions
      description: |
        Extra conditions you may want to add to this automation 
        (Example: Home occupied, TV on, etc)
      default: []
      selector:
        condition:
    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
    sun_entity:
      name: Sun entity
      description: This is normally "sun.sun".
      default: sun.sun
      selector:
        entity:
          filter:
            domain: sun
    home_entity:
      name: Home entity
      description: This is typically "zone.home".
      default: zone.home
      selector:
        entity:
          filter:
            domain: zone

# 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"

  # If you see 'Missing property 'conditions' it is a false error.
  # See https://github.com/keesschollaart81/vscode-home-assistant/issues/2786
condition:
  - alias: User pick
    condition: !input additional_conditions

action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device"
    wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - alias: "Wait the number of seconds that has been set"
    delay: !input no_motion_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target
3 Likes

Thanks a lot! Exactly what I needed.

I am totally lost… If I want to have the motion activated light only during the night (so after sunset but before sunrise), what do I need to do?

Not like this, or?

I don’t use this, I don’t know.
I just helped by adding the roll-your-own condition selector.
No idea what it does.
I use my weather station to track lux outside to enable/disable lights like these.

1 Like

Nice, but I see a problem. If you have a condition related with a luminance sensor (affected by the switched on lights), then even if you got additional movement the automation will not restart because the condition (low luminance) will not be met…

The light lux level controls a binary sensor for day or dark. That binary_sensor is a condition on my motion lights automations. The automation function is not affected by this other than to enable the function or disable that automation.
The light/dark defaults to dark so if something goes wrong, it defaults to the light working.
The light also will turn off when it kicks to day mode, so they don’t get stuck on all day (unless it is one of the timed on lights).

A lot of that is done with Tasmota and the dark/day is sent to the MQTT broker to facilitate that.

1 Like

Hello I’ve just started using Aqara FP2 for motion in my home office. I used the Blueprint provided by HA and once up and running converted it to standard Automation and added some Conditions in UI. One enhancement I would like to make is disregarding the 120 sec timer when the light switch is manually turned off so presence would trigger again if an entry to room was detected.

Is this possible?

alias: "Office: Light Presence"
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.presence_sensor_fp2_ae65_presence_sensor_1
    from: "off"
    to: "on"
condition:
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: "off"
  - condition: state
    entity_id: input_boolean.guest_mode
    state: "off"
  - condition: time
    after: "05:30:00"
    before: "23:00:00"
    enabled: true
action:
  - alias: Turn on the light
    service: light.turn_on
    target:
      entity_id: light.schneider_electric_ch2ax_switch_1_light
    data: {}
  - alias: Wait until there is no motion from device
    wait_for_trigger:
      platform: state
      entity_id: binary_sensor.presence_sensor_fp2_ae65_presence_sensor_1
      from: "on"
      to: "off"
  - alias: Wait the number of seconds that has been set
    delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - alias: Turn off the light
    service: light.turn_off
    target:
      entity_id: light.schneider_electric_ch2ax_switch_1_light
    data: {}
mode: restart
max_exceeded: silent

I do not understand your issue.
Your version has no manual triggers, so nothing in there changes what happens when you turn the light on and off manually.
The only thing that affects the 2 minute timer is the correct change of state to

Thanks for your reply. The behaviour I’m seeing is as follows.

Detect presence and light turns on, leave room and turn off zigbee light switch. Walk back in 30sec later and light does not come on. If I wait a couple of minutes and try again the light comes on. Hope I’ve been clearer.

Adjust the delay?
Can be set to whatever you want.

So if the light is turned off manually at the switch when leaving room, the 120sec timer is irrelevant and the light should turn on again with fresh motion? This is not occurring. I want the 120sec timer, but when turning off light manually I don’t want to wait for it to complete.

If you just flip the manual switch, no. If you trigger the presence sensor then it will start the automation as programmed. One doesn’t care about the other.

Is there a way to make the automation aware to disregard the 120 sec delay when the Zigbee switch is turned off?

I suggest looking thru the blueprint exchange for other versions of a motion light instead of re-inventing the steel. There are many versions there.

Besides this is a solved topic, and your question is UN-relateed to the OP’s original question other than it had the same base software.

1 Like

Thanks @Sir_Goodenough