Blueprint Action Condition Help

Hi,

I am having some trouble with a blueprint that i modified last night. I am trying to add a condition to an action but not having much luck.

I have duplicated and modified the included ‘Motion-activated Light’ blueprint to include a condition for after sunset and also only to turn off if a switch is off.

The logical process is: motion is detected > Check if after sunset > Turn on light > Check if manual override switch is off > Delay for X time > Turn Off

If the manual override switch is ON then I do not want it to proceed and to end the automation. This is easy to do with 2 automation but I like the simplicity of using blueprints going forward.

Here is my blueprint:

blueprint:
  name: Motion-activated Light (After Sunset with Override)
  description: Turn on a light when motion is detected after sunset.
  domain: automation
#Modified from   source_url: https://github.com/home-assistant/core/blob/3ae527c1585d7384688a512ffcf92293999ad749/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
    manual_override:
      name: Manual Override
      description: When the manual override is switched on the light will stay on.
      selector:
        target:
          entity:
            domain: input_boolean
    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"

condition:
  - condition: or
    conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise

action:
  - service: light.turn_on
    target: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - condition: state
    entity_id: !input manual_override
    state: 'off'
  - delay: !input no_motion_wait
  - service: light.turn_off
    target: !input light_target

If i hash out this it will work fine, obviously without the manual override check:

  - condition: state
    entity_id: !input manual_override
    state: 'off'

And the Automation:

- id: '1611050128472'
  alias: LIGHTS - Deck Path 1 (Stair Zone)
  description: ''
  use_blueprint:
    path: homeassistant/motion_light_options.yaml
    input:
      no_motion_wait: '120'
      light_target:
        entity_id:
        - light.deck_path_light_1
      manual_override:
        entity_id: input_boolean.lights_all_back_keep_on
      motion_entity: binary_sensor.deck_stairs_ai_zone

And the error:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:517
Integration: Automation (documentation, issues)
First occurred: 9:37:34 AM (4 occurrences)
Last logged: 9:37:34 AM

Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_1_ai_zone'), ('light_target', OrderedDict([('entity_id', ['light.deck_path_light_1'])])), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')]))]): Entity ID entity_id is an invalid entity id for dictionary value @ data['action'][2]['entity_id']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_2_ai_zone'), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('light_target', OrderedDict([('entity_id', 'light.deck_path_light_2')]))]): Entity ID entity_id is an invalid entity id for dictionary value @ data['action'][2]['entity_id']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_3_ai_zone'), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('light_target', OrderedDict([('entity_id', 'light.deck_path_light_3')]))]): Entity ID entity_id is an invalid entity id for dictionary value @ data['action'][2]['entity_id']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('light_target', OrderedDict([('entity_id', ['light.deck_path_light_1'])])), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('motion_entity', 'binary_sensor.deck_stairs_ai_zone')]): Entity ID entity_id is an invalid entity id for dictionary value @ data['action'][2]['entity_id']. Got None

Any help is greatly appreciated. Thanks!
David

How about:
Add the following as a section above trigger

variables:
  manual_override: !input manual_override

and then change

  - condition: state
    entity_id: !input manual_override
    state: 'off'

to

  - condition: template
    value_template:: {{ states[manual_override].state == ''off'' }}

Thanks, however i am getting this error:

Logger: homeassistant.util.yaml.loader
Source: util/yaml/loader.py:75
First occurred: 2:19:34 PM (1 occurrences)
Last logged: 2:19:34 PM

while parsing a flow mapping in "/config/blueprints/automation/homeassistant/motion_light_options.yaml", line 67, column 23 expected ',' or '}', but got '[' in "/config/blueprints/automation/homeassistant/motion_light_options.yaml", line 67, column 31

Any ideas? Thanks

Single apostrophe either side of the squiggly brackets ‘{{…}}’

Thanks, though still no luck - I get this when reloading the automations:

Logger: homeassistant.components.automation
Source: components/automation/__init__.py:517
Integration: Automation (documentation, issues)
First occurred: 5:59:14 PM (4 occurrences)
Last logged: 5:59:14 PM

Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_1_ai_zone'), ('light_target', OrderedDict([('entity_id', ['light.deck_path_light_1'])])), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')]))]): extra keys not allowed @ data['action'][2]['value_template:']. Got None required key not provided @ data['action'][2]['value_template']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_2_ai_zone'), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('light_target', OrderedDict([('entity_id', 'light.deck_path_light_2')]))]): extra keys not allowed @ data['action'][2]['value_template:']. Got None required key not provided @ data['action'][2]['value_template']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('motion_entity', 'binary_sensor.deck_path_3_ai_zone'), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('light_target', OrderedDict([('entity_id', 'light.deck_path_light_3')]))]): extra keys not allowed @ data['action'][2]['value_template:']. Got None required key not provided @ data['action'][2]['value_template']. Got None
Blueprint Motion-activated Light (After Sunset with Override) generated invalid automation with inputs OrderedDict([('no_motion_wait', '120'), ('light_target', OrderedDict([('entity_id', ['light.deck_path_light_1'])])), ('manual_override', OrderedDict([('entity_id', 'input_boolean.lights_all_back_keep_on')])), ('motion_entity', 'binary_sensor.deck_stairs_ai_zone')]): extra keys not allowed @ data['action'][2]['value_template:']. Got None required key not provided @ data['action'][2]['value_template']. Got None

Same issue if i change to this:

  - condition: template
    value_template:: '{{ states[manual_override].state == "off" }}'

or

  - condition: template
    value_template:: '{{ states[manual_override].state == off }}'

Actually i think it was the double colon after value_template. I have fixed that up but now getting this error when the motion sensor is triggered:

Logger: homeassistant.helpers.condition
Source: helpers/condition.py:458
First occurred: 6:10:56 PM (2 occurrences)
Last logged: 6:10:57 PM

Error during template condition: UndefinedError: homeassistant.helpers.template.AllStates object has no element {'entity_id': 'input_boolean.lights_all_back_keep_on'}

Sorry for the spam but I have figured it out, took a while…

After ripping it all, starting fresh and adding code 1 by 1 I have tracked it down. It was the target: for the manual_override selector - removing that resolved the issue.

Here is the working code:

blueprint:
  name: Motion-activated Light (After Sunset with Override)
  description: Turn on a light when motion is detected after sunset.
  domain: automation
#Modified from   source_url: https://github.com/home-assistant/core/blob/fd363f9c3a02abb29db2af2d1641586828fb30e5/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
    manual_override:
      name: Manual Override
      description: When the manual override is switched on the light will stay on.
      selector:
          entity:
            domain: input_boolean


# 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: or
    conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise

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
  - condition: state
    entity_id: !input manual_override
    state: "off"
  - service: light.turn_off
    target: !input light_target

Good work…