The motion activated light blueprint is nearly perfect, it’s just missing conditions: It should only activate when the sun has set and people are in the house.
Without writing this myself from scratch, does anyone have an updated blueprint to share?
(PS: Kinda mind blowing that this basic thing is not included in the default…)
I personally prefer to use a illuminance sensor instead of Sun’s position, so it will work in a cloudy dark day.
Also, I have a helper (toggle) which will be on when the apartment is empty (controlled by another automation) and then I use this as a “override entity” in other automation.
I have more of those “override entities” (usually toggle helpers), lime “Party mode”, “Travel mode”, “Maintenance mode”, etc.) used to prevent the different automation to run.
Maybe I misunderstand but when I use the blueprint I do not see an option to add conditions myself.
Yes, I could create this for myself entirely from scratch but then I have to deal with timeout etc (the included blueprint has the option to set the “Wait Time”. Hence I would like to use a blueprint.
You haven’t informed which blueprint you are using… Maybe you should publish this in the Blueprint thread.
There are dozens of blueprints related to control lights with a motion sensor.
By the way, you can always edit a blueprint you are using. Just find the file under /config/blueprints and do the changes you want. But please don’t edit it if you are not sure about what you are doing, as you can have undesired results.
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
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
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