In the last line, you can see that I’m trying to use a variable inside the {{ }} brackets, and that’s my question: How would this be done? It’s basically a concatenation of strings that itself should be interpreted as an object name.
I did read the Script Syntax but didn’t find a solution for my use case anywhere. You presented the solution by using “~”. Where would I find this documented?
Also, it seems like a concatenation is not possible without using a function()?
You could also use + if both parts are already strings, but the important point is that we’re using states('your_entity') and building up the string reference in that, as opposed to states.your_entity.state (or the invalid your_entity.state you were trying to use). This is almost always better: see the warning box from here.
The reason I linked the Script Syntax page is that you must use {{ repeat.item }} to reference the current room, as {{ room }} is the list of rooms as you defined it (and I see you’ve edited the original post now ).
Not sure what you mean? You can only concatenate strings — you can’t build direct references to objects if that’s what you mean.
You did this which is invalid because you cannot nest templates.
{{ climate.room_climate_{{ repeat.item }}.state }}
^^^^^^^^^^^^^^^^^
This template is nested inside
another template and that's not permitted
Didgeridrew’s suggested solution is to define a separate script variable (named climate) and then use the script variable in the template.
The only subtle difference between how he defined the script variable and my suggestion is that he used string concatenation (the tilde operator) within a template whereas I used just a template. Two ways to produce the same result.
This topic is very similar to the other topic. Originally, you had also duplicated the other topic and were instructed by a moderator to stop duplicating topics.
If a topic is solved by someone’s reply, mark their reply with the Solution tag. This places a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps other users find answers to similar questions. For more information about the Solution tag, refer to guideline 21 in the FAQ.