I just can’t seam to work this one out.
I am trying to do a blueprint sensor light and I have got everything working until I turn the light on manually and then the light goes OFF with the motion_trigger / time_delay.
Because I am using a “target” for the lights some could be ON and some could be OFF manually. I would like to stick with “target” rather then just “entity”.
I would like the ones that are OFF to use the motion sensor trigger (If OFF then turn ON with motion_trigger and then turn OFF with the time_delay) and the ones ON to just stay ON.
My idea was to have a condition that looks to see if the lights are OFF. But I don’t think that is the correct way to do this and the condition below doesn’t work. I tried a boolean so if that was “true” it would make this option work, but I just can’t work this out.
I am at a loss, could anyone show me how to do this?
blueprint:
name: Sensor Light
description: >
# SENSOR LIGHT
domain: automation
input:
motion_trigger:
name: Motion Sensor
description: The Motion Sensor that turns the lights ON and OFF
selector:
entity:
domain: binary_sensor
device_class: motion
light_switch:
name: Lights
description: The lights that get turned on by the motion sensor
selector:
target:
entity:
domain: light
time_delay:
name: Time Delay
description: Time to leave the light on after last motion is detected.
default: 5
selector:
number:
min: 0
max: 30
step: 0.5
unit_of_measurement: minutes
boolean_light_switch:
name: Light Switch Manual By-pass (Optional)
description: If the lights are turned ON manually they will stay On until lights are turned OFF manually
default: false
selector:
boolean:
sun_elevation:
name: Sun Elevation (Optional)
description: This is the angle between the sun and the horizon. Negative values mean the sun is BELOW the horizon. If you don't see a number value next to "degrees" then this function is disabled. A good starting poit for when it gets dark is -1.5
default: none
selector:
number:
min: -10
max: 5
step: 0.5
unit_of_measurement: degrees
# If motion sensor turns ON again within the time delay, it will restart the script.
mode: restart
max_exceeded: silent
variables:
motion_trigger: !input motion_trigger
light_switch: !input light_switch
time_delay: !input time_delay
boolean_light_switch: !input boolean_light_switch
sun_elevation: !input sun_elevation
trigger:
platform: state
entity_id: !input motion_trigger
from: "off"
to: "on"
# All Conditions
condition:
# Check if light is off
- condition: state
entity_id: !input light_switch
state: 'off'
# Check sun elevation input
- condition: template
value_template: "{{ (sun_elevation == none) or (state_attr('sun.sun','elevation') <= sun_elevation | float(90)) }}"
action:
- alias: "Turn on the light"
service: switch.turn_on
target: !input light_switch
- alias: "Wait until motion sensor is off"
wait_for_trigger:
platform: state
entity_id: !input motion_trigger
from: "on"
to: "off"
- alias: "Wait the number of minutes that has been set"
delay:
minutes: !input time_delay
- alias: "Turn off the lights"
service: switch.turn_off
target: !input light_switch