Automation Template and concatenate names

Hi everyone,

I’am struggeling with something for a while now and well, sometimes it’s good to ask others for help.

I want to let’s say “generate” a counter name with the last trigger in my automation.
Something like that.

{% if states('counter."{{ trigger.entity_id.attributes.friendly_name }}"_credits_buanderie >= 1') %}true{% else %}false{% endif %}

In almost any programming language it’s easy to concatenate strings with variables, but I’am clueless

Any ideas?

You can use ~ or + to concatenate strings, but you do not nest templates inside templates … {% {{}} %} is invalid.

The concatenation would look something like:

'counter.'~ trigger.entity_id.attributes.friendly_name ~ '_credits_buanderie'

But trigger.entity_id.attributes.friendly_name is not a valid trigger variable. You will need to clarify what you are trying to do.

As simple as this:

{{ states('counter.'~ trigger.entity_id.attributes.friendly_name ~ '_credits_buanderie') | int(0) >= 1  }}

However, what is the trigger you are using that produces this?
trigger.entity_id.attributes.friendly_name

If it’s a State or Numeric State Trigger, you can simply use this:
trigger.to_state.name

{{ states('counter.'~ trigger.to_state.name ~ '_credits_buanderie') | int(0) >= 1  }}

I’am using this to give access to a laundry machine.

It’s an

input_boolean.100
input_boolean.200

For example, for the room 1 there is one, another for the room 2 and so on. So I’am taking the name to reuse it on my automation. This way I dont have to have many automations doing the same thing.

OK but that doesn’t answer the question:

what is the trigger you are using that produces this?
trigger.entity_id.attributes.friendly_name

Automation Triggers

Input boolean

That’s an entity_id of an Input Boolean (one of several kinds of helper entity) and not a trigger.

Look at the list of available triggers in the link I posted above and let me know which one you are using.

Oh ok, it’s the #state-trigger

And everything is working nice.

But I wonder if I can simplify everything passing an custom info into the input_button

If I go to Developper tools and States tab I can find my button and add properties.

editable: true
icon: mdi:washing-machine
friendly_name: Machine 1
room: 100

How can I access this new room property?

This way I can make only one input_button and change this property into the frontend.
That make sense?

You don’t… there is no built-in function or service call to alter the value of attributes of a helper.

This topic seems to have veered into X-Y problem territory. Post your automation and a description of your goals and needs.

Good because that means this shorter version of the template will work:

{{ states('counter.'~ trigger.to_state.name ~ '_credits_buanderie') | int(0) >= 1  }}

If you use that method to add an attribute, it’s not permanent and will disappear after you restart Home Assistant.

You can add custom attributes to an entity via Manual Customization. A custom attribute created this way doesn’t disappear after a restart. However, you cannot create an attribute, or change its value, via the frontend or via a service call.

Ok thanks for your advice very appreciated.

Have a nice evening/day