Hello,
I read about the relatively new Event component, and I understand the concept that a momentary switch (like in my case the doorbell button) is considered as a stateless thing that kicks off events. I don’t understand how to do this.
The documentation doesn’t reveal which platforms event can have:
It looks like there’s only one event platform available, event.template.
From how I understand it, you use it to define events for later use. So to get it working with a GPIO pin, it seems like you need to do something like this:
Ok, thanks, I can confirm that this works - somehow
I see in the logs of the ESP that it triggers the event. But I didn’t succeed to catch that in Home Assistant. I tired an automation with an even trigger:
The event type in the HA automation is the same literal as in the ESP, but nothing happens. I also tried to find it somewhere in the developer tools, but couldn’t see it. I guess I have to try more when I feel more motivated.
It feels a bit odd and over-complicated to use a stateful binary senor, hide that (internal: true) and to define an event template and trigger that event from the binary sensor … that is a lot more to do and more potential for failures. And I do not see the benefit of this approach. With my current knowldge about the event thing it appears much better to just use a binary sensor. Anything I’m missing?
You can enable the event logger (Developer Tools > Events) to see if the events actually appear on the bus.
As for this feeling odd and over-complicated: I completely agree. But I don’t know if this is the actual intended use for events, it’s just one way I found to get it working. I might be missing something too
Sorry to bump an old topic. I have read the documentation on the event Component but to me it leaves room for clarification.
I think I understand the concept of a stateless event (I have some background in programming parallal discrete event simulation systems).
So I have made this ESPHome doorbell which has some functionality built in to prevent abuse. This leads to a few interesting events that are not directly related to GPIO's or binary sensors or switches. So I defined the Event component with two event_types which are triggered in the YAML at the right point.
It works allright and an event entity shows up in the esphome dashboard for the device, with the correct event_type. So far so good.
But now my problem is - how to make this event trigger an automation? The events are not in the list of events generated with the device, there is only an event entity, with one single attribute which is event_type. I could not find a way to capture the actual event. Only a change in event type can be detected. If the same event_type is triggered twice (with some time in between) the second is ignored by my automation trigger, apparently while there was no state change detected.
There must be a way to separately handle subsequent events of the same event_type. Could be a time stamp, but I have not found it.
The state of an event entity is a datetime string of when the underlying event occurred. So you use an "open" State trigger, i.e. one without a defined "to" value. Then filter based on the event type attribute value in the Conditions block.