Target Light with OFF Condition

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. :pensive:

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. :thinking:

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

I have added a input, variable and a condition to the Blueprint. This is a switch when ON it stops the action keeping the lights ON.

I would like this to be “Optional”.

You can create the automation from a Blueprint without putting anything in but the action will not work until you select a switch entity and have it OFF.

How could I make it so you can remove the bypass switch entity (have no entity selected) and still have the action work? any ideas what I am doing wrong?

  input:
    light_switch_bypass:
      name: Light Switch Manual By-pass (Optional)
      description: Select a switch that will By-pass the motion sensor and keep the lights ON indefinitely. The switch can not be included in the "Lights" selection.
      default: none
      selector:
        entity:
variables:
  light_switch_bypass: !input light_switch_bypass
condition:
# Check if Light Switch Manual By-pass (Optional)
  - condition: template
    value_template: "{{ states[light_switch_bypass].state == 'off' }}"

All good I have worked this out… it was really simple… always the way :joy:

Would you mind sharing your solution?
I need same automatisation.
Thanks!

2 Likes

A bit late, but I’m at the same postion right now and I can’t figure it out. Would you please share your solution?
Thankyou

His blueprints are here. I bet the answer is as well…
https://gist.github.com/Blackshome

Thank you. I installed them and works beyond expectations