How do I specify a trigger that fired an automation in an event?

I currently have this automation:

alias: Ikea-2Buttons-Printer-Action
description: Actions resulting from Ikea 2Buttons Printer
triggers:
  - domain: mqtt
    device_id: 5d544db47f645aaadcb4d6bb37e26629
    type: action
    subtype: "on"
    metadata: {}
    trigger: device
  - domain: mqtt
    device_id: 5d544db47f645aaadcb4d6bb37e26629
    type: action
    subtype: "off"
    trigger: device
  - domain: mqtt
    device_id: 5d544db47f645aaadcb4d6bb37e26629
    type: action
    subtype: "brightness_move_up"
    trigger: device
  - domain: mqtt
    device_id: 5d544db47f645aaadcb4d6bb37e26629
    type: action
    subtype: "brightness_move_down"
    trigger: device
conditions: []
actions:
  - event: RemoteButtonEvent
    event_data:
      device_id: D-Ikea-2Buttons-Printer
      action: "on"
      integration: zb2mqtt_event
mode: single

The intent is to raise an event, based on a button press of a remote control. Instead of having to create one automation for each button, I would like to create one automation that can trigger from all of the buttons, then indicate in the event, which button was pressed. However, I have no clue how to specify what event triggered the automation. Ultimately, the ā€œactionā€ in the example above would probably look something like:

action: {{ triggered.event.action }}

or something like that.
Does anyone know how I can get around this? Thanks.
BTW, the way I currently get around this is to create a MQTT sensor, then when the event is raised, I read the sensor to see which button was pressed. Not very pretty, therefore, I’d like to optimize it.

Absolutely: trigger ID. Automation Trigger - Home Assistant

You specify an ID for each trigger, and it’s then available in the trigger.id variable.

1 Like

@d921 dominic - Thank you very much!!! That did the trick.
action: ā€œ{{ trigger.id }}ā€

You should stop using the device triggers too. See: Why and how to avoid device_ids in automations and scripts

An example of a zigbee remote automation without using device triggers: Do I really need 1 automation per button of my 6 gang loratap controller? (therefore 18 automations for 1 device) - #4 by tom_l

@tom_l - Thanks for the tip Tom. Have a follow up question for you. In your example, you use an entity:

entity_id: event.dining_button_action

I’m also in the process of transitioning from using the Z2M legacy action to the new ā€œmethodā€, but unaware of such ā€œeventā€ entity. Although I still have the legacy option set in my config file. Is that something that will become available once I get rid of the legacy option in the config file?

What version of HA are you using? Settings → About.

You can see the entities that Z2M has created in Settings → Integrations → MQTT → Entities. Does that help? If things are up-to-date, you should be seeing event.xxx entities.

This is why:

Yep.


I don’t have any entity named event.xxx. I have never seen any such items before. I wonder if it’s a setting in my setup.

Ah ok. Have to enable it. Thanks

If you are not ready to move from the legacy system just yet due to other automations then you should be able to accomplish a similar thing with the action.… entity and a state trigger.

I’m going to make the switch. Don’t want to be surprised when the developers decide to deprecate the legacy function. Just need to make a good backup before I do it. Thanks for your help.

1 Like

For anyone who may stumble into this thread: In order to see the event.xxx entities from Zigbee2MQTT, the option ā€œHome Assistant experimental event entitiesā€ must be enabled as seen in the screenshot below - at least as of this version:
screenshot.5

Yeah their naming scheme isn’t great, legacy or experimental. Where’s ā€˜normal’?