Event trigger automation, how to simplify event_data for multiple tag triggers

I have multiple cameras and each camera notifies me on a separate tag so they don’t overwrite each other’s messages. However, I’m finding that this is making it difficult to write “message clearing” automations because there doesn’t seem to be a concise way to write multiple tag triggers into a single automation. I was able to collapse two event_types into a single event trigger (array) but when I try to list out the tag values (in an array) it no longer triggers on the event.

Right now, I have a trigger entry for each camera tag and this works:

  - id: cameras_event_message_clear
    alias: Cameras Event Message Clear
    initial_state: true
    mode: queued
    trigger:
      - platform: event
        event_type:
          - html5_notification.closed
          - mobile_app_notification_cleared
        event_data:
          tag: cameras_event_greg_1
      - platform: event
        event_type:
          - html5_notification.closed
          - mobile_app_notification_cleared
        event_data:
          tag: cameras_event_greg_2
      - platform: event
        event_type:
          - html5_notification.closed
          - mobile_app_notification_cleared
        event_data:
          tag: cameras_event_greg_3

Is that the best I can do? I’d really like to be able to do a single event trigger with a list of all tags or better yet use a wildcard/asterisk to match all cameras_event_greg_* tags. Is there a way to do that?

Ideally:

      - platform: event
        event_type:
          - html5_notification.closed
          - mobile_app_notification_cleared
        event_data:
          tag: cameras_event_greg_*

Thanks,
-Greg

Leave out the event data part and then in the condition filter out only the events, which have either of this tag, something like this:

trigger:
- platform: event
  event_type:
    - html5_notification.closed
    - mobile_app_notification_cleared
condition: "{{ trigger.event.data['tag'] in ['cameras...', 'cameras...'] }}"
action:
.....
1 Like

OMG!!! Awesome @Burningstone!! Thank you so much, that makes this automation SOOO much tighter.

Did it work? XD I typed it on the phone, didn’t rest it.

yeah, perfectly! Mobile solution FTW! :smiley:

1 Like

I have this same problem however when switching back to the UI view of the automation interface changes.

  trigger:
  - platform: event
    event_type: 
      - insteon.button_on
      - insteon.button_on_fast
      - insteon.button_off
      - insteon.button_off_fast

to

trigger:
  - platform: event
    event_type: >-
      insteon.button_on,insteon.button_on_fast,insteon.button_off,insteon.button_off_fast

the automation works perfectly prior to reopening in the UI view but once it shifts to the second formatting approach, it no longer works.

That’s weird, it should work either way. I’m pretty sure that the dash notation is just a list (similar to using commas). I can’t explain that.

1 Like

If you change your automation to use a comma separated list, does it work for you?

That’s why I avoid the UI editor like the plague. Strips all the comments, messes up the whole format and ordering.
Generally when using UI and YAML, I suggest creating the initial automation in the UI, then copy the code to another file and edit it in YAML.

1 Like

I second this notion. I have all my automations broken out into separate packages based on their related function so the UI editor doesn’t work with them anyway. @scott.l.gamble, try hacking it into the file directly and don’t use the UI editor.

1 Like

@SpikeyGG Yeah that’s the direction i’m leaning, but have found the UI a good place to get examples since i’m just starting out.

If you want to have the best of both worlds, you can add this to configuration.yaml:

# Core configuration
homeassistant:
  packages: !include_dir_named packages/
automation: !include automations.yaml

Then create a folder called packages in the same directory as configuration.yaml and in there create your yaml files by room, by component or whatever you like, e.g. bedroom.yaml and climate.yaml.

Now you can create automations in the UI and they will be stored in automations.yaml, then you copy the code from there once you are finished and then put it in the package you like and put automation: in the beginning, like this:

automation:
  - id: cameras_event_message_clear
    alias: Cameras Event Message Clear
    initial_state: true
    mode: queued
    trigger:
    .....
1 Like