Another home-assistant-variables question if I may

In the documentation there is mention of friendly_name_template I am trying to use this to change the text if an attribute is set to 0 vs 1 in the same var definition. I have tried a lot of forms of the template but no joy so far.

Has anyone has success with this?

Thanks in advance!

var:
  ink_office_canon_cyan:
    friendly_name: "Office Canon CLI-251XL C"
    friendly_name_template: >-
        {% if is_state_attr('var.ink_office_canon_cyan','ordered', 1) %}
            "Office Canon CLI-251XL C -Ordered-"
        {%else%}
            "Office Canon CLI-251XL C"
        {% endif%}
    initial_value: 0
    unit_of_measurement: "%"
    value_template: >-
      {% if is_state('sensor.canon_mx920_series_cyan', 'unavailable') or
            is_state('sensor.canon_mx920_series_cyan', 'unknown') -%}
        {{ (states('var_ink.office_canon_cyan')) }}
      {%- else -%}
        {{ (states('sensor.canon_mx920_series_cyan')) }}
      {% endif %}
    tracked_entity_id:
      - sensor.canon_mx920_series_cyan
    attributes:
      ordered: >-
        {% if states.var.ink_ordered %}
          {{ state_attr('var.ink_ordered', 'office_canon_cyan') }}
        {% endif %}

Is this node red?

Well I am using a function node in node-red to program with this add in.

Function nodes use jave script, that is jinga. It should work in a home assistant template node.

Everything works except the friendly_name_template

If it does, it’s by happenstance that some commands are similar. I’ve never come across anything in the documentation that would suggest using jinga was acceptable.

https://nodered.org/docs/user-guide/writing-functions

Apologies, still rubbing sleep from my eyes. This is the var definition in the config file. I am writing all the nodes to manipulate the data flow in node-red. Spent a while simplifying the code and got rid of 2 function nodes by modifying other bits and decided using this bit would be helpful.

I found a reference that leads me to think I might need to call var.update to get the new friendly name to update. I’ll test that later today.

I think it would be wrong to have both friendly_name and friendly_name_template. You use one or the other.

The help file says the template overides the friendly name.

Reading more carefully I see where It says I can update either the friendly name using var.set or force the template to evaluate with var.update. At the computer again vs the tablet so I’ll get to better test some things out. I believe I suffer from lack of reading the full docs. Will see soon.

Sorry!

Nope, doing a var.update does not work. It seems (maybe) there is an issue with using “state_attr”. Every example in the readme uses “states” never “state” or “state_attr”. I did get a state_attr to work for me in this section but it might not be exactly legit?

    attributes:
      ordered: >-
        {% if states.var.ink_ordered %}
          {{ state_attr('var.ink_ordered', 'office_canon_black') }}
        {% endif %}

but it looks like I need to punt and find a different way to acompish my goal