Automation Trigger Condition

I need some help.
I want to make and automation that is triggered from others differents automations and depends of
what is make someting but i don’t know how:
Automation that Triggers:

- id: '1575543714469'
  alias: ProvaScriptSto
  description: ''
  trigger:
  - entity_id: alarm_control_panel.allarme
    platform: state
    to: disarmed
  condition: []
  action:
  - data:
      entity_id: automation.TestErrorAut
    service: automation.trigger

Automation that is triggered

- id: '1575544514622'
  alias: TestErrorAut
  description: ''
  trigger: []
  condition: []
  action:
  - data:
      message: "{% if trigger.entity_id == 'automation.A' %}\n  Funziona\
        \ Message A\n{% elif trigger.entity_id == 'automation.B' %}\n\
        \  TestB\n{% elif trigger.entity_id == 'automation.C'\
        \ %}\n  TestC\n\
        {% endif %}\n"
    service: notify.telegram

I don’t think that your method is possible. If you trigger the automation from another automation, you can’t use trigger to find out which automation triggered it.
You could do this with a script and passing a variable to the script, but I have a feeling, that there is an easier solution for your problem.

Could you please explain what the end goal of these automations is?

Do you want a different message to be sent based on what mode your alarm system is changed to? If so, use something like this:

  trigger:
  - platform: state
    entity_id: alarm_control_panel.allarme
  action:
  - service: notify.telegram
    data_template: 
      message: >
        {% set state = trigger.to_state.state %}
        {% if state == 'disarmed' %}
          [message if disarmed]
        {% elif state == 'armed_home' %}
          [message if armed home]
        ...
        {% else %}
        {% endif %}

Add additional elif statements for the additional alarm modes that your system supports where the ... is above.

Yes, Thanks for your reply.
I need one Master automation that in the action call other automations, because if i put for example notify.telegram inside the master automation and the execution of telegram notify fail other action after this won’t be executed.
My solution is Make One Automation only for Telegram notification, one only for App notification ecc… and call from another automation so if telegram automation fail the app notification also will triggered and send my message.
I’m not sure if i’m clear sorry…
Stefano

Thanks a lot, this is correct but for example i want to receive message via telegram and notify.app, if action telegram that is first fail the action notify.app never trigger so need to use different automation related to service (telegram, app, alexa, ecc…)

Then it’s better to make a script and call the script. The script will ignore it if an action fails and just continues.

So create one script to handle all your notifications and pass the message as a variable from the automation to the script. There’s a chapter in the above link “passing variables to scripts”, which explains how this works.

2 Likes

Thanks a lot for your reply.
i have tried with script but i don’t know why but if the script fail the automation also fail and won’t continue with other action.
My test:
Automation:

- id: '1575543714469'
  alias: ProvaScriptSto
  description: ''
  trigger: []
  condition: []
  action:
  - data:
      entity_id: script.1575190959902
    service: script.toggle ------- USED script.on
  - data:
      message: Notifica da Automazione
    service: notify.telegram

Script 1

'1575190959902':
  alias: Test
  sequence:
  - data:
      message:
    service: notify.lannouncer
  - data:
      message: Prova Test
    service: notify.telegram

The data for lannouncer is not correct infact i can’t receive notification via telegram (automation) and telegram (script)
Script 2

'1575190959902':
  alias: Test
  sequence:
  - data:
      message: Prova Test
    service: notify.telegram
  - data:
      message: 
    service: notify.lannouncer

I can receive only the notification via telegram (script) not the automation.
in the other approach (via automation) all works, if the second automation encounter an error the Master automation continue and send me the notification.
I have solved this problem by use script.on instead of script.toggle, but if the script in your action encounter and error won’t do the next action (for now is not a problem for me)
i will study the link that you have send to me!! Thanks.

Put the action that turns on the script at the end of the automation then. Anyway it may be a better idea to find out why the actions fail and fix this.

It depends, somethimes i use Lannouncer and when not respond the action fails, sometime i use some battry sensor and when the battery died won’t works again, sometimes my philips hue hub become unreachable and again wont works because the hue bulb become unavailable…
sorry for my bad english… :frowning:
Stefano

No worries english is also not my native language. I assume you’re from Italy, right?

I’m not sure if I understood correctly, do you want to still receive a message even if the action failed?
Let’s say you have an automation that triggers when everyone left the house. It turns off the lights in the house and sends you a notification that the lights have been turned off. Now say you’re bulb is unavailable and therefore the action fails, but with your idea you would still receive a notification that the lights have been turned off. Do you really want this behavior? This way you’ll never know if your action worked or not.

Or see my reply in the other topic you created where you’re basically asking the same question:

Thanks a lot for your reply Phil and for your exaustive reply.
In this thread i have asked one different thing, if you see the first post, but after that we have found a different approach that is the same of the other thread.
Really thanks a lot for you help and fast reply and also for you presence in this forum.
i will read your post and will tell to you

Ok i have read your post @pnbruckner and its an ingenius workaroud.
for my needed i need both solution, thanks to you i know that i can execute a script without stop the master automation and thanks to @Burningstone i can create only one script for telegram notification and pass the message variable by automation instead of create one script for alarm notification, one script for water notification etc…
So in the end really thanks at both i have found the solution at my problem and only in about 1h!!!
I’m so happy now :smiley:
Stefano

2 Likes

The bulb is only an example
you understood perfectly!! Thanks :smiley: