Use entity from input selector action

Input like this:

    input_action:
      name: ActionInput
      default: []
      selector:
        action:

And let’s say you enter something like:

'input_action': [{'service': 'light.toggle', 'metadata': {}, 'data': {}, 'target': {'entity_id': 'light.livingroom'}}]

To be used like this:

trigger_variables:
  input_action: !input 'input_action'

trigger:
  - platform: state
    entity_id: '{{ input_action[0].target.entity_id }}'

Is this possible? I have tried so many different ways and nothing seems to not generate an error.

neither a valid entity ID nor a valid UUID for dictionary value @ data['entity_id']. Got None

Action statements are a dictionary. You are trying to code it like it’s a list.
Neither one is correct, it needs an entity_id.

So like that, no, you can’t do it. I don’t know any way to make it work either.

I know you are likely using this in a blueprint, but it is really a data structure and template question, so I will switch up the category a bit for you to get the right eyes on it.

1 Like

It even says in the error message it’s a dictionary…

But when I try:

entity_id: '{{ dict.values(input_action[0].target.entity_id) }}'

or

entity_id: '{{ dict.values(input_action[0].entity_id) }}'

It gives same error.

It says in the error it’s a dict but looking for an entity_id…

Here is the solution, it’s a dictionary of lists (which was throwing me off):

enitity_id: '{{ input_action[0].target.entity_id }}'

That will get you the first entity defined in the action block.

State triggers do not allow templates anywhere but duration.

Yeah, the dictionary lookup works… but you can’t use it for entity_id. Is there any way to do what I’m trying to do?

It’s not clear to me exactly what you are trying to do…

I want to use the entity_id from the action selector in a trigger so it doesn’t need to be entered multiple times. Right now, you define an action and then select the same entity again in an entity input. Trying to get rid of the redundant steps.

But what do you want the trigger to be?

AFAIK, you’re basically going to be limited to Template triggers and Event triggers… but I am not much of a Blueprint creator so I haven’t tested the concept.

Once again huge credit @Blackymas for the NSPanel blueprint which I got idea from:

trigger_variables:
  input_scene5: !input 'scene_5'
  input_entity0: !input 'input_entity0'
  trigger_entity0: '{{ input_entity0 if input_entity0 else input_scene5[0].target.entity_id if input_scene5 | count > 0 else input_entity0 }}'

trigger:
  - platform: event
    event_type: state_changed
    event_data:
      entity_id: '{{ trigger_entity0 }}'
    id: 'StateTrigger'
    alias: DeviceStateTrigger0