Calling an input by it's name stored in a variable?

This might be obvious, but I’m still getting my head around syntax,

Lets say I have an input in a blueprint:

    switch_1_click:
      name: Switch 1 Click
      default: []
      selector:
        action: {}

Normally, I can call that as follows:

  - sequence: !input switch_1_click

Is there any way to call the input if the name “switch_1_click” is stored in a variable?

If it is stored in a script variable, you can retrieve it using templating. But you can’t just store the name, you have to store the complete value of the input:

variables:
  switch_1_click: !input switch_1_click 

Just remember that the selector you have chosen will return a list of action objects so you will need to use a “Repeat for each” and apply each attribute. So, in theory, you could do something like:

Example Using Repeat
blueprint:
  name: Example
  description: Example
  input:
    switch_1_click:
      name: Switch 1 Click
      default: []
      selector:
        action: {}
triggers:
  - trigger: state
    entity_id: sensor.example
variables:
  input_actions: !input switch_1_click
actions:
  - action: some_action
    ...
  - repeat:
      for_each: "{{ input_actions }}"
      sequence:
        - action: "{{ repeat.item.action }}"
          data: "{{ repeat.item.data | default({}, true) }}"
          target: "{{ repeat.item.target | default({}, true) }}"

But you will run into issues if the user includes some of the weird actions like delay, so it is better to use the actions key to merge your list of actions:

blueprint:
  name: Example
  description: Example
  input:
    switch_1_click:
      name: Switch 1 Click
      default: []
      selector:
        action:
triggers:
  - trigger: state
    entity_id: sensor.example
actions:
  - action: switch.toggle
    data: {}
    target:
      entity_id: switch.example
  - actions: !input switch_1_click

Thanks for your responce, but I’m not sure how the second option uses a variable (which is important) but I’d like to avoid the issues with Delay you mentioned for the first option.

It may be because my blueprint is somewhat more complicated, so let me give a more concrete (but still simplified) version:

blueprint:
  name: Example
  description: Example
  input:
    remote:
      ...
    active_switch:
	  ...
    switch_1_click:
      name: Switch 1 Click
      default: []
	  selector:
	    action: {}
    switch_2_click:
      name: Switch 2 Click
      default: []
      selector:
	    action: {}
trigger:
  - trigger: event
    event_type: zha_event
    event_data:
      device_id: !input remote
action:
  - variables:
      full_command: "{{ trigger.event.data.command }}"
      button_code: "{{trigger.event.data.args.button}}"
      short_command: "{{trigger.event.data.args.press_type}}"
      active_switch_entity: !input active_switch
      active_switch_name: "{{ states(active_switch_entity) }}"
  - choose:
      - conditions:
          - "{{ short_command == 'click' }}"
        sequence:
          - action: input_text.set_value
            target:
              entity_id: "{{ active_switch_entity }}"
            data:
              value: "{{ button_code }}"
          - call input named in full_command variable

In this example, the variable values would be:

  • full_command = “switch_1_click”
  • button_code = “switch_1”
  • short_command = “click”

Other short_command values could be “double_click” or “long_press”. These values come off of the device.

The very last line is where I’d like to call switch_1_click by the value stored in the full_command variable. I know I could put in a choose with tests for each possible value of full_command, but I’d like to avoid that if possible.

Input variables are a type of variable, you have not specifically named the type that you were asking about. By your configuration example it looks like you are asking about script variables.

As far as I am aware, there is no way to do what you are asking. The closest thing would be to set up options in the Choose action using full_command instead of short_command, then merge the actions with an input variable as previously shown.

...
  - choose:
      - conditions:
          - "{{ full_command == 'switch_1_click' }}"
        sequence:
          - action: input_text.set_value
            target:
              entity_id: "{{ active_switch_entity }}"
            data:
              value: "{{ button_code }}"
          - actions: !input switch_1_click
....