Getting a couple errors I don't understand on automation blueprint creation

Hi,

Trying to create a few simple blueprints but not quite understanding the errors. Apologies if I have posted in the wrong area - feel free to move the topic if so.

The idea of the BP is just to turn off a light X time after it was turned on.

`Blueprint Light Power saver generated invalid automation with inputs OrderedDict([('light_target', OrderedDict([('entity_id', 'light.study')])), ('timer_wait', 5)]): Entity entity_id is neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']. Got None`

The BP script currently looks like

blueprint:
  name: Light Power Saver
  description: Turn off light X time after it was turned on.
  domain: automation
  input:
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
    timer_wait:
      name: Wait time
      description: Time to leave the light before tunring off
      default: 120
      selector:
        number:
          min: 5
          max: 3600
          unit_of_measurement: seconds

## If state of light changes restart the script.
mode: single
#max_exceeded: silent

trigger:
  platform: state
  entity_id: !input light_target
  from: "off"
  to: "on"

action:
  - alias: "Wait the number of seconds that has been set"
    delay: !input timer_wait
  - alias: "Turn off the light"
    service: light.turn_off
    target: !input light_target

any pointers to where I am going wrong?

A target type selector cannot be used as the value for entity_id in a state trigger. If you notice when you use a target type selector it lets you pick any number of areas, devices or entities. The output of that selector then looks like this:

area_id:
  - area_1_guid
  - area_2_guid
device_id:
  - device_1_guid
  - device_2_guid
entity_id:
  - light.light_1
  - light.light_2

Even if you only pick entities it still has that structure. So let’s say you just picked two lights, you’d get this:

entity_id:
  - light.light_1
  - light.light_2

Which is invalid in the entity_id field of a state trigger. That just wants a list of entity IDs, not a dictionary with a field called entity_id that contains a list of entity IDs. There’s also no way to prevent someone from picking devices and areas which is obviously invalid in that type of trigger. Essentially you can only use the target type selector in a service call, it won’t work anywhere else.

What you want in this spot is an entity selector like this:

light_target:
  name: Light
  selector:
    entity:
      domain: light
      multiple: true

This type of selector will only allow someone to pick light entities and give you back a list of entity IDs. That works great in the trigger. For the service call you’ll have to tweak it like this:

service: light.turn_off
target:
  entity_id: !input light_target
2 Likes

Thank you. I understood what different between maps/lists/items, Just hard (ish to understand from the documentation the exact format of outputs/structures. Just not used to yaml and HA’s usage of it yet - wish it was just python :slight_smile:

I dont suppose there is anyway to actually play with different types of elements/objects and be able to print out what they output or their sturcture? i.e a sandbox or something that allows print to log/file.

Sure, just do this:

blueprint:
  name: Light Power Saver
  description: Turn off light X time after it was turned on.
  domain: automation
  input:
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light
trigger:
  (whatever)
action:
  - variables:
      debug: !input light_target

Put whatever you want in trigger to make it valid. Make the blueprint into an automation then run it and look at the trace. That last step will show you what it did which includes what light_target looks like.

1 Like

I also encountered this problem, not for a trigger but for a condition, and struggeld for several hours. If I understand correctly, the cause of this problem is that a selector always results in a list. In this case it results in a list of entity_id’s. The condition cannot handle a list of entity ids; it needs exactly one entity id. That is understandable. But HA might report a more user friendly error, such as “state trigger cannot handle multiple entities”.

I hoped that setting the multiple attribute of the selector would result in exactly one entity id, and would solve this problem. But it doesn’t. If you do not specify the multiple attribute, then it is already false by default. So specifying multiple: false does not help. The multiple attribute either does not work well or it does not seem to be useful for problems like these.

As a (not so user friendly) work-around, you can apply a template trigger instead of a state trigger.
So replace

trigger:
  platform: state
  entity_id: !input light_target
  from: "off"
  to: "on

with something like this:

trigger:
  platform: template
  value_template: "{{ is_state(light_target, 'on') }}"

Note that this problem has already been reported by others in github. These issues have been closed because they were stale for 3 months :face_with_raised_eyebrow: What should I do - report the problem again?