Extracting an attribute

So I have a set of sensors named
Sensor.abc_label1
Sensor.abc_label2
Sensor.abc_labeln

I have also an input_select with label1, labeln as options
I need to pass the value of an attribute of one of the sensors , dynamically selected through the input select to a script.
What would be the right template?

{{state_attr ((states("input_select.whatever")),'attributename')}}

Or something like that

{% set sensor = 'sensor.abc_'~states('input_select.YOUR_SELECT_ID')  %}
{{ state_attr(sensor,'ATTRIBUTE_NAME') }}
2 Likes