Automation using id of trigger

I want to set input_number.rollo_manuell_betaetigt by binary code (eg 1= cover 1; 2=cover 2, 4=Cover3…) triggered by the change of state of the cover (if somebody has manually changed the cover).

My idea is to use the id of the trigger for setting the input_number.
but I did not find a way use it - how can I user the id of the trigger as value inside the value calculation?
states(“input_number.rollo_manuell_betaetigt”)|int + id|int
Or is there another way to do it?

description: Rolle manuell Betaetigt
id: rollo_mauell_betaetigt
mode: single
trigger:
  - platform: state
    entity_id: cover.rollo_mitte_links
    id: "4"
  - platform: state
    entity_id: cover.mitte
    id: "8"
condition:
 
action:
  - service: input_number.set_value
    data:
      entity_id: input_number.rollo_manuell_betaetigt
      value: >
        {% if (states("input_number.rollo_manuell_betaetigt")|int|bitwise_and(id|int) != 0) %}
            {{ states("input_number.rollo_manuell_betaetigt")|int + id|int }}
        {% else %}
            {{ states("input_number.rollo_manuell_betaetigt")|int }}
        {% endif %}
alias: rollo_manuell_betaetigt
{{ (states("input_number.rollo_manuell_betaetigt") | int) + (trigger.id | int) }}

trigger.id seems to create an error:
Fehler: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘id’
it looks like trigger has no attribute id

2024-05-11 18:10:26.559 ERROR (MainThread) [homeassistant.components.automation.rollo_mauell_betaetigt] rollo_mauell_betaetigt: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'dict object' has no attribute 'id'
2024-05-11 18:10:26.568 ERROR (MainThread) [homeassistant.components.automation.rollo_mauell_betaetigt] Error while executing automation automation.rollo_mauell_betaetigt: Error rendering data template: UndefinedError: 'dict object' has no attribute 'id'

that is the action part

service: input_number.set_value
data:
  entity_id: input_number.rollo_manuell_betaetigt
  value: >
    {% if
    (states("input_number.rollo_manuell_betaetigt")|int|bitwise_and(trigger.id|int)
    != 0) %}
        {{ (states("input_number.rollo_manuell_betaetigt") | int) + (trigger.id | int) }}
    {% else %}
        {{ states("input_number.rollo_manuell_betaetigt")|int }}
    {% endif %}

If you attempt to test the automation by executing its Run command, the trigger variable will be undefined (and produce an error message regarding trigger.id).

The trigger variable only exists when the automation is triggered by one of its triggers.

1 Like