Yes, and it’s quite tricky (or elegant). The blueprint uses mode “restart”, meaning everytime motion is triggered the delay to turn off is cancelled and automation’s action sequence starts again. This works because it doesn’t harm to turn an already “on” light on again.
check the blueprint’s automation part at Github (or your local drive).
It triggers only if motion is detected (off to on), turns the lights on and starts the delay to turn them off. If during that time motion is detected again, the script part is started again, effectively restarting the delay again.
Only thing that isn’t matched by this is continuous motion (trigger alwas on).
Okay, I think I’ll have to do a lot more reading on blueprints vs. automations, because I don’t understand the sequence of the blueprint. Thank you for the assist!
lines 31 to 50 is the actual automation, but instead of fixed values or entities, it uses variables (declared by !input)
lines 1 to 30 is the actual blueprint “overhead”, some metadata and the declaration of the supported !input variables.
When you create an automation based on a blueprint, that automation references the blueprint and defines values for the given variables. If you change the blueprint afterwards (and don’t break it), all automations created from that blueprint will be using the new logic.
Did you put the file into the correct location? There are no errors in it, with respect to being a blueprint, but it will fail miserable if being used as an automation’s source …
I copied the code 1:1 from my post into a file at /config/blueprints/automation/m0wlheld/motion_lights.yaml and is does not trigger an error. Also created an automation from that blueprint (yet, didn’t save it), and it appeared okay.
Looks like the issue is somewhere in my HA. Current error message points to my configuration.yaml file, stating that it “failed to load blueprint”.
Probably have to do some forensics to try and find the issue.
Edit: No longer getting an error message in the log, but still no luck in creating the lux-blueprint. The blueprint shows up, I can enter the data and then press create automation without issue, but it doesn’t result in any automation in the automation list. The weird thing is that when I go to automations.yaml, I can see the just created automation.
Don’t really understand where the issue might be. Using the original blueprint works fine.
I want to add a condition to this BluePrint. I’ve tried multiple times but it doesn’t work. I just want to check if the TV is on. If I’m watching TV it shouldn’t turn the lights on/off.
How can I add the this condition to BluePrint? Can somebody help me about this?
blueprint:
name: Presence-activated Light
description: Turn on a light when presence is detected.
homeassistant:
min_version: 2023.8.0
domain: automation
source_url: https://community.home-assistant.io/t/presence-sensor-light-automation/564590
input:
presence_entity:
name: Presence Sensor
description: Presence sensor device
selector:
entity:
filter:
domain:
- binary_sensor
device_class:
- occupancy
multiple: false
light_target:
name: Light
description: Light device
selector:
target:
entity:
- domain:
- light
bright_percentage:
name: Bright Percentage
description: Brightness level that the light will turn into once is turned on
default: 100
selector:
number:
min: 0.0
max: 100.0
unit_of_measurement: percentage
mode: slider
step: 1.0
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 0
selector:
number:
min: 0.0
max: 3600.0
unit_of_measurement: seconds
mode: slider
step: 1.0
off_transition:
name: Transition time
description: Time in seconds of transition turning off
default: 0
selector:
number:
min: 0.0
max: 60.0
unit_of_measurement: seconds
mode: slider
step: 1.0
light_sensor:
name: Light sensor
description: Light sensor to read from
default: []
selector:
entity:
filter:
domain:
- sensor
device_class:
- illuminance
multiple: false
light_threshold:
name: Light threshold
description: Light sensor‘s lower threshold
default: 200
selector:
number:
min: 0.0
max: 255.0
mode: slider
step: 1.0
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:
trigger:
platform: state
entity_id: !input presence_entity
from: 'off'
to: 'on'
condition:
- condition: numeric_state
entity_id: !input light_sensor
below: !input light_threshold
- condition: !input additional_conditions
action:
- alias: Turn on the light
service: light.turn_on
target: !input light_target
data:
brightness_pct: !input bright_percentage
- alias: Wait until there is no motion from device
wait_for_trigger:
platform: state
entity_id: !input presence_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
data:
transition: !input off_transition
mode: restart
max_exceeded: silent
Fixed the selector filters to the new format, moved mode to the end because sometimes, oddly, I have seen it cause issues located other places, and add a condition selector so that you can add any condition you like. Requires HA version 2023.8.0 or newer to handle the condition selector.
If this solves your problem please consider hitting solution checkbox here.
Thanks for posting this snippet! I had been hunting for a way to add a condition to an existing blueprint, and this was more than what I had hoped to find!
I made a copy of the “motion activated light” default HA blueprint (motion_light.yaml) and called it a “motion activated switch” blueprint (motion_switch.yaml), and then added this conditional component.
My use case: I have an overhead light which is controlled by a Z-Wave enabled wall switch in our laundry room. The laundry room happens to be attached to our garage as well, so it has no windows nor other light source and is always dark if the light isn’t on. Since we often enter the laundry room from within the house (with clothes to wash) and/or the garage with hands full (groceries, etc.), I put a motion sensor in the laundry room to assist with turning on the lights (in addition to the garage door opening triggering the light to turn on). What I didn’t want to happen was that IF the laundry room light switch was already ON for whatever reason, I wanted it to stay on and didn’t want the motion sensor blueprint routine to turn OFF the light after the timer expired. So, with the additional_conditions block, I added a check to see if the light was not already on, then the blueprint could trigger turning the light on and enable the countdown timer within the blueprint to turn it off later.
I have another automation that runs periodically to check for recent motion and turn the light off at night.