This might be a stupid question, but I have severe problems to understand how to use templating in YAML code. I want to iterate through a list of climate entities and update all temperature settings with data from list of input helpers. I also want to save current temperature setting to another list of input helpers before I update the temperature setting. My intention is to be able to change temperature settings for a group of thermostates and support multiple settings like at “home”, “away” etc.
I have an automation that loops through a list of items. The items is used to build up strings representing entiies. And I want to read states and attributes and update other entities. However, I end up with templates inside a template and that does not work. I have tried different variants for two days now, but I can’t figure out how to solve this.
The key here is to use methods that use strings that you can build up rather than direct references, so states(), state_attr() rather than the dot references to the entities. See the warning box on the Templating page:
Yea, i’m aware of the state_attr() and states() functions, but not the use of ~ in templates ! That caused me a lot of pain. Now everything works fine. However, first I had to fix a mistake using input_number instead och input_select…
The + symbol is often used to do the same thing but it can produce unexpected results if one or more of the items to be concatenated is a number not a string.
FWIW, here’s another way to do the same thing (without ~ ).