Seeing the events on the event bus?

Hi,
Is there a way to show the actual events on the event bus?
I have enabled (INFO-level) logging in configuration.yaml
When I trigger an automation that should fire an event, I only see the following 3 lines:

2019-08-12 15:26:36 INFO (MainThread) [homeassistant.helpers.script] Script <name of my automation>: Running script
2019-08-12 15:26:36 INFO (MainThread) [homeassistant.helpers.script] Script <name of my automation>: Executing step sun.sunrise 

But I would like to see the details of the actual event that I am firing, so that I can troubleshoot what I do wrong

Would that be possible?
Any tips are greatly appreciated,
thanks,
chris

Why donā€™t you use the ā€˜Eventā€™ icon from dev-tools? You may subscribe to your event and can see everything has fired.

Hi @A320Peter,(as in Airbus 320? you fly a lot?)
Thank you for your answer.
Interestingā€¦ On that page, I see ā€œAvailable Eventsā€
I was trying to trigger a ā€œsunriseā€ event, but there is no sunrise event under ā€œAvailable Eventsā€.
Even though, I can trigger an automation on ā€œsunriseā€
I guess I need to dive deeper in the documentation to understand what an event actually is.
Also, how do I ā€œSubscribe to an eventā€ on that page? From what I see, I can only 'trigger" an event.
thanks,
chris

Okey so I assume if you fire an event from an automation you are probably doing something like this:

  action:
    - event: my_test_event
      event_data:
        state: 'on'

This will fire an event and send it to the event bus either if called from an automation or from a script. The event will be called my_test_event and the event_data is a list of custom parameters which are stored as JSON objects on the event bus. In this case I used only one parameter which is state with a value on. Read the bottom lines on the Script Syntax page.

If you take a look at the Event page among the dev-tools you may trigger any event to test it. If you want to listen to the event bus you need to specify what kind of event you are listening to. So you need to subscribe. On the right side you may see the available events, this is correct. But it takes time for HA to update those and sometimes custom events are not appearing there (I have no clue). Scroll down the page and in the bottom middle you should find a textbox labeled ā€˜Event to subscribe toā€™ and a button next to it called ā€˜Start Listeningā€™. In my previous example if you start listening to my_test_event you will get results when this event is fired. As an example start listening to my_test_event and on the top of the page enter my_test_event into the ā€˜Event Typeā€™ text field. Below that is 'Event Data (JSON, optional). Copy paste the following:

{"state":"test"}

Whenever you press the FIRE EVENT button you will see the event is firing at the bottom of the page.

If you want to use this event as a trigger in an automation you should probably do something like this:

- alias: Test if my custom event has fired
  trigger:
      - platform: event
        event_type: my_test_event
  action:
  ...

I donā€™t know exactly what you want to do but I have the feeling there is an easier solution for that.

If you need to do something at sunrise, there is built-in entity called Sun. You may extract a lot of useful information like

sun.sun:

below_horizon 	

next_dawn: 2019-08-13T03:00:58+00:00
next_dusk: 2019-08-13T18:36:43+00:00
next_midnight: 2019-08-12T22:48:47+00:00
next_noon: 2019-08-13T10:48:50+00:00
next_rising: 2019-08-13T03:35:12+00:00
next_setting: 2019-08-13T18:02:29+00:00
elevation: -7.73
azimuth: 301.76
rising: false
friendly_name: Sun

You may easily detect sunrise and do something with an automation like this:

automation:
  - alias: 'Send notification when sun rises'
    trigger:
      platform: sun
      event: sunrise
      offset: '+00:00:00'
    action:
  ...

Donā€™t forget that in order to make this work correctly you have to specify your geographical location (coordinates) and elevation of your home in the configuration.yaml and then restart Home Assistant.

For more examples regarding Sun automations look at here.

3 Likes

Hi @A320Peter,
SOLVED:
Thank you so much for this very detailed answer.
This is almost like having a private tutor.
Much appreciated.

The field ā€œEvent to subscribe toā€ was off my screen.
I had not noticed the scroll bar, so I had no idea it was there.

Insights:

  1. I opened 2 hassio WebUIs (different browsers or Incognito window).
    In the first one I went to the Developer Tools -> Events and I subscribed to the sunrise event.
    In the second one I triggered a sunrise event from that same page.
    The first WebUI showed me the event with its full details in JSON format.
    Love it !

  2. Now I entered * in the ā€œEvent to subscribeā€ field.
    This gives me ALL events on the events bus.
    This is so powerful and insightful. Christmas !

This helps me to better understand and use Hassio
thanks again so much Airbus Peter :wink:
chris

1 Like

good catch. so whatā€™s your code to simulate a sunrise then? :slight_smile:

You donā€™t necessarily need WebUI for this. Another option is to use moqsuitto_sub command in terminal.

good question,ā€¦ let me answer that in the other thread, which was on that subject (ā€œHow to compensate for missed events (e.g. sunrise) after a restart of HA?ā€)

1 Like