Can't understand issue with this blueprint

Hey everyone,

I’m kind of new to Home Assistant, I just migrated from Fibaro Home Center 2, and really happy so far!

I was playing with blueprints, and wanted to build one, based on a built-in one (motion-activated light) but taking into account that a button can be pressed in-between.

Here’s what I came up with:

blueprint:
  name: Motion-activated Light with button
  description: Turn on a light when motion is detected.
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          filter:
            device_class: motion
            domain: binary_sensor
    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

# 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"

action:
  - alias: "Turn on the light"
    service: light.turn_on
    target: !input light_target
  - alias: "Wait until there is no motion from device or light turned off manually"
    wait_for_trigger:
      - platform: state
        entity_id: !input motion_entity
        from: "on"
        to: "off"
      - platform: state
        entity_id: !input light_target
        to: "off"
  - if:
      - condition: state
        entity_id: !input light_target
        state: "off"
    then:
      - stop: ""
    else:
      - alias: "Wait the number of seconds that has been set or light turned off manually"
        wait_for_trigger:
          - platform: state
            entity_id: !input light_target
            to: "off"
        timeout: !input no_motion_wait
        continue_on_timeout: true
      - if:
          - condition: state
            entity_id: !input light_target
            state: "off"
        then:
          - stop: ""
        else:
          - alias: "Turn off the light"
            service: light.turn_off
            target: !input light_target

However, when I try to use it, there is an error message saying:

Message malformed: Entity entity_id is neither a valid entity ID nor a valid UUID for dictionary value @ data[‘action’][2][‘if’][0][‘entity_id’]

I spent quite some time trying to understand, google, etc. to no avail.

Any hint on what could be wrong with entity_id: !input light_target apparently.

Thank you for your help!

Well… it doesn’t look like an entity ID. :grin:

Your selector for the light is a target, and you look for the state of the light entity at least 2 times.

It’s a target or an entity, not both.

Thank you.

I’m still not very comfortable with selector > entity and selector > target > entity and how to write actions for them, but I eventually got it working.

This might help from Petro…

petro — 08/22/2023 1:59 PM
A target selector returns a dictionary containing entity_id key 
with a list of entities.  e.g.
{'entity_id': [ ., ., . ] }

or the YAML variation
entity_id:
- .
- .
- .

So, when you use entity_id: !input <some_target_selector> and
you select entities... 
you end up feeding this to the YAML:
entity_id:
  entity_id:
  - .
  - .

Instead of the desired
entity_id:
- .
- .

That's why you can't use target selector
entity selector always returns a list of entities, 
which is just [ ., ., . ] 
or the YAML equivalent:
- .
- .
- .