Which attribute is triggering the automation?

Hi!

I want to make an automation with multiple entities and every entity have 10 attributes.
If trigger.entity_id is for getting which entity has been triggered the automation, what should I use to find out which attribute from the entitty has triggered the automation?

Thank you in advance!

Post your trigger.

trigger:
  - platform: state
    entity_id:
      - sensor.variable_automations_run_time
    id: Automations Run Time

And this one have 5 attributes till now, but it will have more than 10 in the future

With a trigger like that, you won’t know which attribute changed without looking at the from_state and to_state. This will require templates.

Can you guide me through this? I don’t follow very good.

This will give you a list of attributes that changed.

{% set ns = namespace(changed=[]) %}
{% for k, v in trigger.to_state.attributes.items() if trigger.from_state.attributes.get(k) is not none and v != trigger.from_state.attributes.get(k) %}
    {% set ns.changed = ns.changed + [ k ] %}
{% endfor %}
{{ ns.changed }}

Be advised that the Core development team have been guiding integration developers, and users, to avoid creating sensors with multiple attributes (especially if the attributes contain non-static data).

There are several reasons for this guidance and you have encountered one of them (can’t easily tell which attribute was responsible for triggering the State Trigger).

For example, the Tasmota integration models a power-monitoring plug using multiple entities, a switch, a sensor for power, another sensor for energy, another for total energy, etc. Each entity serves a specific function, thereby making it easy for use with a trigger and to record and display its history.

@123 Ufff… I noticed something about this but I didn’t thought it is so important… :expressionless:

@petro I will try it something tomorrow, thanks!