Know why an automation is triggered

Hi all,
i have an automation with some condition in OR mode that close awning and send me a telegram notification

- alias: Awning Close
  initial_state: 'on'
  trigger:
  - platform: sun
    event: sunset
    offset: -02:00:00 #-01:30:00
  - platform: numeric_state
    entity_id: sensor.owm_wind_speed
    above: 6
  - platform: numeric_state
    entity_id: sensor.weather_yr_wind_speed
    above: 6    
  - platform: numeric_state
    entity_id: sensor.average_wind_5m
    above: 10      
#  - platform: numeric_state
#    entity_id: sensor.dark_sky_precip_intensity
#    above: 3
  - platform: numeric_state
    entity_id: sensor.weather_yr_cloudiness
    above: 30
#    for:
#     minutes: 5
  condition:
    condition: state
    entity_id: cover.tenda_cucina
    state: open
    for:
      seconds: 40  ## The screen takes some time to fully roll up or down, I don't want it changing direction half way
  action:
   - service: cover.close_cover
     entity_id: cover.tenda_cucina
   - service: notify.telegram
     data:
       message: '{{now().strftime("%Y-%m-%d %H:%M")}}: Awning closed '

I’m looking if there is a way to know which condition hit the trigger and send it via telegram

Thanks

I think adding something lik this may work, have a search on here there’s lots of examples

trigger.from_state.attributes.friendly_name

Also this should be data_template: if you are going to use templates:

   - service: notify.telegram
     data:
   - service: notify.telegram
     data_template:
       message: >
         {{now().strftime("%Y-%m-%d %H:%M")}}: Awning closed by {{'sunset' if trigger.event is defined else trigger.to_state.name}}.

If it was triggered by the Sun Trigger, it appends “sunset”.

2020-06-17 08:35 Awning closed by sunset.

If it was triggered by one of the Numeric State Triggers, it appends the entity’s friendly_name.

2020-06-17 08:35 Awning closed by Own Wind Speed.

For more information, see Available Trigger Data.

Your automation only has one condition. I think what you meant to say was, your automation has multiple triggers.

In any case, per the documentation linked to above by @123, trigger.platform will tell you the platform of the trigger that fired. So if it’s sun, then it was the first trigger, otherwise it’s one of the numeric_state triggers. To find out which of those fired, you can use trigger.entity_id or trigger.to_state.name.

BTW, you can combine these:

  - platform: numeric_state
    entity_id: sensor.owm_wind_speed
    above: 6
  - platform: numeric_state
    entity_id: sensor.weather_yr_wind_speed
    above: 6    

into this:

  - platform: numeric_state
    entity_id:
    - sensor.owm_wind_speed
    - sensor.weather_yr_wind_speed
    above: 6    
1 Like