How do I make this nested template work?

Dear all,
I am stuck. I have an automation that calls a script passing on the variable “title”. The script is supposed to fetch the input.number from different input.number helpers based on the variable. However, I have trouble getting the variable part nested in the template to work. This is what I have tried:

track_no: "{{states('input_number.bookmark_' ~ title ~ '')|int}}"  
track_no: "{{states('input_number.bookmark_{{title}}')|int}}"   

The first one seems to work in the template editor but not in the script. This is the error I get:

Got None extra keys not allowed @ data[‘sequence’][0][‘bookmark’]. Got ‘input_number.bookmark_{{title}}’ extra keys not allowed @ data[‘sequence’][0][‘track_no’]. Got "
{{states(’ ~ bookmark ~ ')|int}}"

Any ideas?
Kind regards,
Dominik

You can’t use curly brackets in curly brackets.

Post your script code.

I’m assuming that track_no is a script variable and title is a variable passed to the script.

track_no: "{{ states('input_number.bookmark_' ~ title) | int(0) }}"  

I agree with pedolsky that you should post the entire script (because it may contain more than one error).

FYI you don’t need defaults for input’s because they are always loaded w/ values and will never be unavailable.

Thank you all for your help. I will post my complete script once I am back at my PC. However, Taras suggestion works perfectly:


track_no: "{{ states('input_number.bookmark_' ~ title) | int(0) }}"

I hear that curly brackets don’t work inside of curly brackets. Can anyone suggest a good reading to learn more about the syntax. I would like to better understand what I did wrong and why it is working now. Thanks

Start here: Templating