Add trigger id as a param when calling an automation

Hi!

When you use automations you get them to be triggered by some automatic events, but it’s also handy to be able to launch them manually. We have the service automation.trigger for that, which is great, but it would be great if the trigger id could be passed.

When using automations for some daily tasks, like rolling up/down window blinds for example, you usually have an automation to roll them up in the morning and another one to roll them down in the evening. That’s a lot of integrations it you want different times for some blinds. Using the trigger id is great, as you have half of them. Something like this automation:

alias: example
trigger:
  - id: 'off'
    platform: sun
    event: sunrise
  - id: 'on'
    platform: sun
    event: sunset
condition: []
action:
  - service: 'switch.turn_{{ trigger.id }}'
    target:
      entity_id: switch.whatever

This works like a charm and avoids you to have two different automations. Problem comes when you want to call this automation manually: as you can’t pass the trigger param, you can’t.

Any chances to add the trigger as a param to the automation.trigger service call?

Thanks!

PS: Yes, this could be donde using a script that you call manually and also from the automation, but it’s madness having things in both sides unless it’s handy and you will end up with 2 automations and 1 script.

Probably not.

How is calling one service, automation.trigger, more handy than calling another service, script.blinds_up?

You can have as many or few automations and scripts as you want, including just 1 of each…

Automation Examples

1 or more Automations with 2 scripts

alias: example
trigger:
  - id: 'up'
    platform: sun
    event: sunrise
  - id: 'down'
    platform: sun
    event: sunset
  - id: 'down'
    platform: state
    entity_id: zone.home
    to: 0 
condition: []
action:
  - service: 'script.blinds_{{ trigger.id }}'

OR 1 or more automations, just one script…

alias: example
trigger:
  - id: 'off'
    platform: sun
    event: sunrise
  - id: 'on'
    platform: sun
    event: sunset
  - id: 'on'
    platform: state
    entity_id: zone.home
    to: 0 
condition: []
action:
  - service: script.blinds
    data:
      action: "{{ trigger.id }}"

As I said, totally possible to do it… having more “things” (automations/scripts). I just though that adding one parameter will add possible functionality and reduce the number or automations/scripts you need to have in HA.

It’s a matter of giving a much better user experience by just adding ONE parameter to a function, not a bug or anything.

I came across this post searching for exactly what the title says. I use trigger IDs a lot in automations to reduce the number of automations and simplify management. but when I call an automation from an automation I cannot pass the trigger ID. I agree with luixal, this would be a very handy feature. has this ever been requested?

I can’t remember, but I think I never opened an FR in github.

Anyhow, this thread has only 4 upvotes so… not many people needing this I guess.

According to the docs, this should be possible… but it does not work. I opened an issue asking for clarification in late June. So far, there has been no comment on whether this is a documentation error or a bug.

Also, consider the fact that adding just the trigger ID may have limited use since the rest of the trigger variable won’t be populated with values.

Related FR threads:

1 Like

Just tried to get some attention with a comment xD