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.