Template with custom_templates import does not update correctly

it’s sorted. The attributes template listeners are stored in a list, but the yaml configuration is a dictionary. When the configuration is converted from yaml to a dictionary, the attribute keys are sorted.

This of course assumes that they all ‘update at the same time’. If the templates themselves reference other entities, then the order is not “expected” because templates update based on what they are listening to.

EDIT: Now that I think about it, there’s no guaranteed order. The only guarantee is that availability resolves first, then state, then the rest in any order.

Given that attributes are evaluated in sorted order, then bat is evaluated before cat in the following example:

        attributes:
          cat: >-
            {{ this.state | int(0) * 5 }}
          bat: >
            {{ this.attributes.cat * 10 }}

That means bat uses the previous value of this.attributes.cat and not the newly computed value. As for cat it will use the newly computed value of this.state.

Is that a correct interpretation of how the system works?

You’d have to test that. HA is async and so are the attributes. I believe that would be sort order at that point but it’s hard to tell without debugging into the system with that specific test in mind. Based on the code I’ve read, I believe that particular case would be sort order.

that describes my sometimes :wink:

I didnt check before, but now I did, and couldnt find any description of this on the templates page at all, I believe it should be in the documentation for the this variable.
In a clearly accented dedicated section on this…

there is only This and linking to This

confusion arises when people mistake last (as in the final) state for current (which is also final). Maybe we should refer to the last state as ‘previous’…