Fire event pressing a button in the Front End

I would like to fire a custom event pressing a button in the Front End.
I could link the button to the execution of a Python script and inside it fire the event with hass.bus.fire().

Is there a more straightforward method to do it, without passing through a Python script?

1 Like

You can fire an event using the following: https://www.home-assistant.io/docs/scripts/#fire-an-event

ok, but I guess I can’t link that action directly to a button to press in the Front End, can I?
Do I have to put it in a script and trigger the script from an Entity Button?

I use the syntax below… Add entity button, hit the {} icon at the bottom, copy and paste the code below.

You’ll need to change both "automation.?“ names and the “name:”

show_name: true
hold_action:
  action: none
tap_action:
  action: call-service
  service: automation.trigger
  service_data:
    entity_id: automation.north_shop_door
entity: automation.north_shop_door
name: Open Gate
type: entity-button
show_icon: true
1 Like

This links an automation to an entity button.
I was asking for a link between an entity button and a custom event firing (because I will use it in something more complicated of an automation). Is there something I’m missing?

5 Likes

Did you solve this? I am trying the same.

Like @niedejb said you can call an automation from your button like he did in his example and then simply fire the event as is shown on the page I linked to e.g.:

action:
  event: YOUR_EVENT

If you want to pass in some parameters, you can add them to event_data:

action:
  event: YOUR_EVENT
  event_data:
    your:
      data: 'foo'
      other_data: 'bar'

The action of an automation and the sequence of a script act the same (as far as I know), so you could create a script like @Vinz87 mentioned:

tap_action:
  action: call-service
  service: script.your_event_trigger_script

Your script:

your_event_trigger_script:
  sequence:
    event: YOUR_EVENT
    event_data:
      your:
        data: 'foo'
        other_data: 'bar'
1 Like

Is there not a simple way to fire an event from a button or something, the same way a service can be called or a device can be toggled?

An event can be fired from Developer Tools, so the possibility is there?

I built a work-around, posted here for anyone in the same need.