#How to automate a notification based on the outcome of 2 event triggers

1 messages · Page 1 of 1 (latest)

crisp forge
#

I have an automation that is triggered on a time pattern every hour which downloads the latest news from a website. I would like an action to run after the download has completed to trigger a notification to my companion app to say completed or failed. I have the trigger, action and notifications running correctly but i cannot get the notification to trigger using the event, correctly. Currently i have a wait for trigger which listens for the event complete which works perfectly but i need it to also listen to the event failed and then send the failed notification. Can anyone help?

coral solstice
#

I'd move the second part out to another automation, and use trigger ids

crisp forge
#

@coral solstice I had thought of that - i just wondered if there was any way of keeping it all within one automation. I assume that using trigger id's in the frist part of the same automation won't work?

coral solstice
crisp forge
#

@coral solstice I am not sure that is quite what i am looking for - unpless i am totally misreading the docs? But i have now set up a second automation to check for the event data and then send a notification. Using the event dev tools i can see the event trigger so i know it is running correctly. However when setting up the same triggers in the second automation with an option it doesn't send the automation.

#

To confirm, i have taken the individual trigger out and copied it into the actin fter the download in the first automation with a wait trigger and that does trigger a notification. Any idea why it isn't working in a seperate automation?

'''
alias: BBC News Download Notification
description: ""
triggers:

  • trigger: event
    event_type: downloader_download_completed
    event_data:
    trigger: event
    event_type: downloader_download_completed
    event_data:
    url: >-
    {{
    (state_attr('sensor.bbc_news_summary','entries')[0]['links']|selectattr('rel','eq','enclosure')|first)['href']
    }}
    filename: bbc_news_summary.mp3
    id: download_completed
  • trigger: event
    event_type: downloader_download_failed
    event_data:
    trigger: event
    event_type: downloader_download_completed
    event_data: null
    url: >-
    {{
    (state_attr('sensor.bbc_news_summary','entries')[0]['links']|selectattr('rel','eq','enclosure')|first)['href']
    }}
    filename: bbc_news_summary.mp3
    id: download_failed
    conditions: []
    actions:
  • choose:
    • conditions:
      • condition: trigger
        id:
        • download_completed
          sequence:
      • action: notify.mobile_app_caesar_augustus
        metadata: {}
        data:
        message: Success
        title: Home Assistant Downloader
    • conditions:
      • condition: trigger
        id:
        • download_failed
          sequence:
      • action: notify.mobile_app_caesar_augustus
        metadata: {}
        data:
        message: failed
        title: Home Assistant Downloader
        mode: single
        """
sly ridgeBOT
#

@crisp forge To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

#

@crisp forge Discord isn't like IRC, you don't have to tag people on every response. Keep in mind that every time you tag somebody, they get a notification ping. That can very quickly become annoying and people may block you.
When using Discord's Reply feature it defaults to pinging the person you reply to, click @ ON to @ OFF to stop this - on the right side of the compose bar.

coral solstice
#
    event_data:
      url: >-{{
        (state_attr('sensor.bbc_news_summary','entries')[0]['links']|selectattr('rel','eq','enclosure')|first)['href']
        }}
``` that's never going to work, you can't drop templates there
crisp forge
#

It does work, though.

alias: Download BBC News Summary
description: ""
triggers:

  • trigger: time_pattern
    minutes: "35"
    conditions: []
    actions:
  • action: downloader.download_file
    metadata: {}
    data:
    overwrite: true
    filename: bbc_news_summary.mp3
    url: >-
    {{
    (state_attr('sensor.bbc_news_summary','entries')[0]['links']|selectattr('rel','eq','enclosure')|first)['href']
    }}
  • wait_for_trigger:
    • trigger: event
      event_type: downloader_download_completed
      event_data:
      url: >-
      {{
      (state_attr('sensor.bbc_news_summary','entries')[0]['links']|selectattr('rel','eq','enclosure')|first)['href']
      }}
      filename: bbc_news_summary.mp3
      enabled: true
  • action: notify.mobile_app_caesar_augustus
    metadata: {}
    data:
    message: a message has sent
    enabled: true
    mode: single
#

It does trigger the notification here

coral solstice
#

Code markup please

#

Oh, I see, limited templates are now supported in some parts of the event trigger

#

They're only evaluated once though, at setup time

crisp forge
#

Right, so if i understand correctly; i will only be able to get the notification sent "in line" and having a seperate automation won't work?

coral solstice
#

Or check that in the conditions

#

That's the best place to check that, since it's checking the value of that attribute at that exact time, not when the automation starts running

crisp forge
#

Hmmm. So in theory i could IF the event data and send if it comes back true and then ELSE if not?

coral solstice
#

Or, just check that in a condition

#

Don't over-complicate it

sly ridgeBOT
#

There are three sections to an automation:

  • trigger: When any one of these becomes true the automation starts processing. Only one trigger is ever responsible for starting an automation, if you make a condition that checks for more than one having started the automation then the condition can never be true.
  • condition: These are checked after a trigger starts the processing, and must be true for the automation to continue.
  • action: This is the part that does something, and can also include further conditions.
crisp forge
#

The action to download the file needs to be triggered by the time pattern. That then causes the event to report back failed or completed so any conditions would need to be checked as a consequence