Concat a variable with a string to get a another variable value

I googled for an hour and could not find an example of this…

variables:
  off_state0: !input 'off_state0'
  off_color0: !input 'off_color0'
  off_state1: !input 'off_state1'
  off_color1: !input 'off_color1'
trigger:
  - alias: DeviceStateTrigger
    platform: state
    entity_id: 
    - !input 'target_entity0'
    - !input 'target_entity1'
    variables:
      target_entity0: !input 'target_entity0'
      target_entity1: !input 'target_entity1'
      button_id: >
        {% if trigger.entity_id == target_entity0 %}
          0
        {% elif trigger.entity_id == target_entity1 %}
          1
        {% endif %}
      off_state_trigger: "{{ "off_state" ~ button_id }}"

So I want to concat the string “off_state” with the value of button_id (let’s say it’s 0), so I then have “off_state0” which I then need to get the value of in a condition in the action block like:

data:
  parameter: '{{ (button_id | int) + (toggle_offset | int) }}'
  value: '{{ off_state_trigger }}'

I know the variable is passing down, as it shows up as ‘0’ without the concat string.

TIA

You could not find an example because no part of that will work.
1: Variables do not exist until after the trigger. They are not rendered at all.
2: I do not get nor is it a valid construct to have a variable key under a state trigger.

So just do your trigger, then after the trigger you can create variables or a condition section or an action section.

Perhaps i gave too much context… are you saying there is no way to concat a text string and a variable value to define another variable name?

var1: 0
var2: text ~ {{ var1 }}

Where var2 is “text0”.

@Sir_Goodenough , @rwalker is trying to use it in a condition within the action block… so in a choose or if. that should be ok… I’m guessing you thought he meant the condition block of the overall automation

@rwalker you can use variables to build more variables as long as they are properly scoped.

please post the full automation that you wish to work… not clips, but the whole thing so that we can make sure the variables are visible and properly scoped

If anyone else stumbles on this page, I solved this by creating a map and referencing the map like this:

variables:
  targets:
    DeviceStateTrigger0:
      button_id: 0
      off_state: !input 'off_state0'
      off_color: !input 'off_color0'
      on_state: !input 'on_state0'
      on_color: !input 'on_color0'
      unavail_state: !input 'unavail_state0'
      unavail_color: !input 'unavail_color0'

trigger:
  - alias: DeviceStateTrigger0
    id: 'StateTrigger'
    platform: state
    entity_id: !input 'input_entity0'

Psuedo code:
value: '{{ targets[trigger.alias].off_state }}'