ouranos6
(Ouranos6)
August 7, 2023, 10:57pm
1
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.
123
(Taras)
August 7, 2023, 11:10pm
3
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 }}
ouranos6
(Ouranos6)
August 8, 2023, 6:32am
4
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.
123
(Taras)
August 8, 2023, 12:00pm
5
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
123
(Taras)
August 8, 2023, 2:39pm
7
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.
ouranos6
(Ouranos6)
August 8, 2023, 2:55pm
8
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.
123
(Taras)
August 8, 2023, 3:43pm
10
Good because that means this shorter version of the template will work:
{{ states('counter.'~ trigger.to_state.name ~ '_credits_buanderie') | int(0) >= 1 }}
123
(Taras)
August 8, 2023, 3:49pm
11
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.
ouranos6
(Ouranos6)
August 8, 2023, 7:25pm
12
Ok thanks for your advice very appreciated.
Have a nice evening/day