Button
A button entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] is an entity that can fire an eventEvery time something happens in Home Assistant, an event is fired. There are different types of events, such as state change events, when an action was triggered, or the time changed. All entities produce state change events. Every time a state changes, a state change event is produced. Events can be used to trigger automations or scripts. For example, you can trigger an automation when a light is turned on, then a speaker turns on in that room. Events can also be used to trigger actions in the frontend. For example, you can trigger an action when a button is pressed. [Learn more] / trigger an actionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called sequence. [Learn more] towards a deviceA device is a model representing a physical or logical unit that contains entities. or serviceThe term “service” in Home Assistant is used in the sense of an information service. For example, the municipal waste management service that provides entities for organic, paper, and packaging waste. In terms of functionality, the information service is like a device. It is called service to avoid confusion, as it does not come with a piece of hardware. [Learn more] but remains stateless from the Home Assistant perspective.
It can be compared to a real live momentary switch, push-button, or some other form of a stateless switch.
Building block integration
This button is a building block integration that cannot be added to your Home Assistant directly but is used and provided by other integrations.
A building block integration differs from the typical integration that connects to a device or service. Instead, other integrations that do integrate a device or service into Home Assistant use this button building block to provide entities, services, and other functionality that you can use in your automations or dashboards.
If one of your integrations features this building block, this page documents the functionality the button building block offers.
The state of a button
The button entityAn entity represents a sensor, actor, or function in Home Assistant. Entities are used to monitor physical properties or to control other entities. An entity is usually part of a device or a service. [Learn more] is stateless, as in, it cannot have a state like the on
or
off
state that, for example, a normal switch entity has.
The state of a button is a timestamp showing the date and time of the last time the button had been pressed in the Home Assistant UI or via an action.
Screenshot showing the state of a button entity in the developer tools.
In addition, the entity can have the following states:
- Unavailable: The entity is currently unavailable.
- Unknown: The state is not yet known.
Because the stateThe state holds the information of interest of an entity, for example, if a light is on or off. Each entity has exactly one state and the state only holds one value at a time. However, entities can store attributes related to that state such as brightness, color, or a unit of measurement. [Learn more] of a button entity in Home Assistant is a timestamp, it means we can use it in our automations. For example:
triggers:
- trigger: state
entity_id: button.my_button
actions:
- action: notify.frenck
data:
message: "My button has been pressed!"
Actions
The button entities exposes a single actionActions are used in several places in Home Assistant. As part of a script or automation, actions define what is going to happen once a trigger is activated. In scripts, an action is called sequence. [Learn more]: button.press
This action can be called to trigger a button press for that entity.
- action: button.press
target:
entity_id: button.my_button
Device class
A device class is a measurement categorization in Home Assistant. It influences how the entity is represented in the dashboard. This can be modified in the customize section. For example, different states may be represented by different icons, colors, or text.
The screenshot shows different icons representing different device classes for buttons:
Example of device class icons.
The following device classes are supported for buttons:
- None: Generic button. This is the default and doesn’t need to be set.
- identify: The button is used to identify a device.
- restart: The button restarts the device.
- update: The button updates the software of the device.