Templates in customize.yaml

Can I use templates in customize.yaml? I want to create a custom attribute where the value is built from a template, but it doesn’t work. Something along the lines of:

switch.xiaomi_2:
  reason: "{{ state_attr('sensor.my_attributes', 'xiaomi_2_reason') }}"

In the above case, sensor.my_attributes is an MQTT sensor that has an attribute called xiaomi_2_reason. What I’m seeing is the attribute is just being set to that string, and the template is not being interpreted. The template does work in Developer Tools.

In reality, I’m trying to do a hack to get custom attributes on an existing entity that I can set.

No.

There are options to allow you to customise the displayed entity in Lovelace.

That is sad. There’s been a few feature requests for custom attributes on entities, so I guess I will have to wait longer.

Even if that is ever implemented you probably won’t be able to use a template there.