Event
Events are signals that are emitted when something happens, for example, when a user presses a physical button like a doorbell or when a button on a remote control is pressed.
The Event integration集成将 Home Assistant 与您的设备、服务等连接和集成。 [Learn more] provides entities实体表示 Home Assistant 中的传感器、执行器或功能。实体用于监控物理属性或控制其他实体。实体通常是设备或服务的一部分。 [Learn more] that trigger state change events, as do all other entity integrations.
These events do not capture a state in the traditional sense. For example, a doorbell does not have a state such as “on” or “off” but instead is momentarily pressed. Some events can have variations in the type of event that is emitted. For example, maybe your remote control is capable of emitting a single press, a double press, or a long press.
The event entity can capture these events in the physical world and makes them available in Home Assistant as an entity.
构建模块集成
这个 event 是一个构建模块集成,无法直接添加到你的 Home Assistant 中,但可以被其他集成使用和提供。
构建模块集成不同于典型的与设备或服务连接的集成。相反,其他将设备或服务集成到 Home Assistant 中的集成使用这个 event 构建模块来提供实体、服务和其他你可以在自动化或仪表板中使用的功能。
如果你的某个集成具有这个构建模块,这个页面记录了 event 构建模块所提供的功能。
The state of an event entity
The event entity does not capture a state such as On or Off. Instead, an event entity keeps track of the timestamp when the emitted event has last been detected.
Event entity with a timestamp value in state and event type "pressed".
In addition, the entity can have the following states:
- Unavailable: The entity is currently unavailable.
- Unknown: The state is not yet known.
Because the state of an event entity in Home Assistant is a timestamp, it means we can use it in our automations. For example:
triggers:
- trigger: state
entity_id: event.doorbell
actions:
- action: notify.frenck
data:
message: "Ding Dong! Someone is at the door!"
Event types
Besides the timestamp of the last event, the event entity also keeps track of the event type that has last been emitted. This can be used in automations to trigger different actions based on the type of event.
This allows you, for example, to trigger a different action when the button on a remote control is pressed once or twice, if your remote control is capable of emitting these different types of events.
When combining that with the choose action script, you can assign multiple different actions to a single event entity. In the following example, short- or long-pressing the button on the remote will trigger a different scene:
triggers:
- trigger: state
entity_id: event.hue_remote_control
actions:
- alias: "Choose an action based on the type of event"
choose:
- conditions:
- alias: "Normal evening scene if the button was pressed"
condition: state
entity_id: event.hue_remote_control_on_button
attribute: "event_type"
state: "short_release"
sequence:
- scene: scene.living_room_evening
- conditions:
- alias: "Scene for watching a movie if the button was long-pressed"
condition: state
entity_id: event.hue_remote_control_on_button
attribute: "event_type"
state: "long_release"
sequence:
- scene: scene.living_room_movie
When creating automations in the automation editor in the UI, the event types are available as a dropdown list, depending on the event entity you are using. This means you don’t have to remember the different event types and can easily select them.
Automating on a button press
This section shows a similar example to the example automation shown above in YAML. It’s an automation that is triggered by an event state change, but shows how to implement it in the UI. To start an automation triggered by a button press (or a button press pattern), follow these steps.
Prerequisites
- You have a device that takes button presses as inputs, such as a Tuo Smart Button, VTM31SN dimmer by Inovelli, or the Matter Pushbutton Module by Innovation Matters
- The device has been added to Home Assistant
To automate on a button press
-
If you like, give your button event entity a friendly name.
- Under Settings > Devices & services, select the Matter integration card and select the device.
- On the Events card, select the button entity.
- Under Name, enter the new friendly name.
-
Go to Settings > Automations & scenes and select Create Automation.
-
Then, select Create new automation. This brings up an empty automation page.
-
-
Define what should trigger触发器是定义的一组平台值或条件,用于触发自动化运行。 [Learn more] the automation to run.
- Select Add trigger, then, select Entity > State.
- Type
event
and select your button entity. -
Important: Leave the other fields empty.
-
Define the condition when something should happen.
- Under Then do, select Add action.
- Type
choose
and select Add condition. - Select Entity > State and select your button event entity from the list.
- Under Attribute, select Event type.
- Under State, select the state change you want to act as trigger, for example Pressed once.
-
Pressed once is the event type. But the state of this event is the timestamp of when the button was pressed. This is why we automate on the state change so that it is triggered every time the button is pressed.
-
Pressed once is the event type. But the state of this event is the timestamp of when the button was pressed. This is why we automate on the state change so that it is triggered every time the button is pressed.
-
Define what should happen when your automation is triggered (when the button is pressed, for example).
- Select Add action and define your action.
-
Repeat these steps for each event type you want to monitor.
- In this example, we want to do something else when the button was pressed twice.
- In this example, we want to do something else when the button was pressed twice.
-
Save the automation.
Device class
设备类别是 Home Assistant 中的一种测量分类。它影响实体在 仪表板 中的表示方式。这可以在 自定义部分 中进行修改。例如,不同的状态可能会用不同的图标、颜色或文本来表示。
The screenshot shows different icons representing device classes of the event entity:
Example of different icons representing device classes of the event entity.
The following device classes are supported by event entities:
- None: Generic event. This is the default and doesn’t need to be set.
- button: For remote control buttons.
- doorbell: Specifically for buttons that are used as a doorbell.
- motion: For motion events detected by a motion sensor.
Video tutorial
This comprehensive video tutorial explains how events work in Home Assistant and how you can set up Emulated Roku to control a media player using a physical remote control.