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 eventAn event is when something happens.
[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 serviceA service carries out one specific task, for example: turn on the light in the living room. A service has targets and data and can be called by actions, a dashboard, or via voice command.
[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

The button integration cannot be directly used. You cannot create your own button entities using this integration. This integration is a building block for other integrations to use, enabling them to create button entities for you.

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.

Every button entity does keep track of the timestamp of when the last time the button entity has been pressed in the Home Assistant UI or pressed via a service call.

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:

trigger:
  - platform: state
    entity_id: button.my_button
action:
  - service: notify.frenck
    data:
      message: "My button has been pressed!"

Services

The button entities exposes a single serviceA service carries out one specific task, for example: turn on the light in the living room. A service has targets and data and can be called by actions, a dashboard, or via voice command.
[Learn more]
: button.press

This service can be called to trigger a button press for that entity.

- service: button.press
  target:
    entity_id: button.my_button

Device class

The way these buttons are displayed in the frontend can be modified in the customize section. The following device classes are supported for buttons:

Example of device class icons.

  • 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.