My fault… This condition will only run when the Sun is above the horizon. It should be bellow.
blueprint:
name: Motion-activated Light
description: Turn on a light when motion is detected.
domain: automation
source_url: https://github.com/home-assistant/core/blob/52307708c843b947a2d631f2fe7ddaa8bd9a90d7/homeassistant/components/automation/blueprints/motion_light.yaml
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
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
# 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"
## BEGIN ADDED BY ME
condition:
- condition: numeric_state
entity_id: zone.home
above: 0
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: 0
## END ADDED BY ME
action:
- service: light.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: light.turn_off
target: !input light_target
I would suggest you to do this in another file, so you keep the original blueprint intact just in case…
Hold on, I will create this new blueprint for you. Give me 5min.
Meanwhile, revert back your blueprint to the original state (removing the conditions).
I tried it and I think it worked Yaaay thank you!!
But of course, a separate blueprint would be EVEN better
Just click this button to import it as a new Blueprint:
blueprint:
name: Motion-activated Light (only when sun is up and someone at home)
description: Turn on a light when motion is detected.
domain: automation
source_url: https://community.home-assistant.io/t/motion-activated-light-but-with-conditions/466228/12
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Light
selector:
target:
entity:
domain: light
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:
domain: sun
home_entity:
name: Home entity
description: This is typically "zone.home".
default: zone.home
selector:
entity:
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"
condition:
- condition: numeric_state
entity_id: !input home_entity
above: 0
- condition: numeric_state
entity_id: !input sun_entity
attribute: elevation
below: 0
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
If you want to go for a really detailled automation with lots of conditions, you can have a look here:
But maybe that’s an overkill for your request…
Thank you for creating this. Amazing!
I am actually struggling with the import button 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)
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.
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
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.
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.
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