Automation - trigger.id not working in Script

Hello together,

i am trying to get the trigger.id from a automation as variable to a script.

When i am trying to compare if the trigger.id is like the text from the trigger in the automation it works. When i send the trigger.id as variable to the script. The script see the the right text but i am not able to compare. its never true.

Automation:

alias: Test - Trigger.id
description: ""
triggers:
  - trigger: time_pattern
    id: AlleSekunden
    seconds: /30
    enabled: true
conditions: []
actions:
  - action: script.testvar_telegram
    metadata: {}
    data:
      variables:
        trigger_automation: "{{ trigger.id }}"

Script

alias: Test-Trigger.id
sequence:
  - if:
      - condition: template
        value_template: "{{ 'AlleSekunden'  == trigger_automation }}"
        enabled: true
    then:
      - action: notify.telegram
        metadata: {}
        data:
          message: "{{ trigger }}"
          title: Trigger-Test
        enabled: true
description: ""

Working inside of the automation

alias: Test - Trigger.id
description: ""
triggers:
  - trigger: time_pattern
    id: AlleSekunden
    seconds: /30
    enabled: true
conditions: []
actions:
  - if:
      - condition: template
        value_template: "{{trigger.id == \"AlleSekunden\"}}"
    then:
      - action: notify.telegram
        metadata: {}
        data:
          title: Test
          message: "\"{{trigger.id}}\""
    enabled: true

Can anybody help me here?

trigger.idx is not trigger.id

Sorry, i was trying a littlebit and this was a test. Sorry. I am using only trigger.id.
but the problem is like before.

If you are using trigger.id in the automation, then use “AlleSekunden” in the script, but you need to fix the script call too. When calling directly you don’t have to use variables. If you want to have trigger in the script you need to include it in the values that are passed…

You may run into some issues passing triggers. IIRC, the trigger is going to be passed as a JSON string. But many triggers contain objects that are not JSON-serializable like datetime objects. If there are particular parts of the trigger you want access to, it may be better to just pass them explicitly.

alias: Test - Trigger.id
description: ""
triggers:
  - trigger: time_pattern
    id: AlleSekunden
    seconds: /30
    enabled: true
conditions: []
actions:
  - action: script.testvar_telegram
    metadata: {}
    data:
      trigger_id: "{{ trigger.id }}"
      trigger_json: "{{ trigger }}"
alias: Test-Trigger.id
sequence:
  - if:
      - condition: template
        value_template: "{{ 'AlleSekunden'  == trigger_id }}"
        enabled: true
    then:
      - action: notify.telegram
        metadata: {}
        data:
          message: "{{ trigger_json }}"
          title: Trigger-Test
        enabled: true
description: ""

Hi TheDeath24,

First problem:
You state you want the trigger id, but you send the trigger index.
Automation trigger variables - Home Assistant.

second problem, you need to catch this:

in the script with a field
Scripts - Home Assistant.
or a variable before you can use it.

1 Like

You are right. But its also not working.


grafik

Review my post above, I think I was editing it when you copied that… one variable in the automation was missing and one was under the variables key when it didn’t need to be.

Hi @Didgeridrew,

okay understand. i tryed it like you showed, but the compare isn´t working in the script. I see that the trigger object is now complete in the script. But i am didn´t able to compare the trigger.id with the text.

are you tried this in your system? or you only write the correcting?

Thanks and Regards TheDeath24