Cover Component

The cover component is a generic representation of covers in ESPHome. A cover can (currently) either be closed or open and supports three types of commands: open, close and stop.

../../_images/cover-ui.png

Base Cover Configuration

All cover config schemas inherit from this schema - you can set these keys for covers.

cover:
  - platform: ...
    device_class: garage

Configuration variables:

Advanced options:

  • internal (Optional, boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.
  • If MQTT enabled, all other options from MQTT Component.

cover.open Action

This action opens the cover with the given ID when executed.

on_...:
  then:
    - cover.open: cover_1

Note

This action can also be expressed in lambdas:

auto call = id(cover_1).make_call();
call.set_command_open();
call.perform();

cover.close Action

This action closes the cover with the given ID when executed.

on_...:
  then:
    - cover.close: cover_1

Note

This action can also be expressed in lambdas:

auto call = id(cover_1).make_call();
call.set_command_close();
call.perform();

cover.stop Action

This action stops the cover with the given ID when executed.

on_...:
  then:
    - cover.stop: cover_1

Note

This action can also be expressed in lambdas:

auto call = id(cover_1).make_call();
call.set_command_stop();
call.perform();

cover.control Action

This action is a more generic version of the other cover actions and allows all cover attributes to be set.

on_...:
  then:
    - cover.control:
        id: cover_1
        position: 50%
        tilt: 50%

Configuration variables:

  • id (Required, ID): The cover to control.
  • stop (Optional, boolean): Whether to stop the cover.
  • state (Optional, string): The state to set the cover to - one of OPEN or CLOSE.
  • position (Optional, float): The cover position to set.
    • 0.0 = 0% = CLOSED
    • 1.0 = 100% = OPEN
  • tilt (Optional, float): The tilt position to set. In range 0% - 100%.

Note

This action can also be expressed in lambdas:

auto call = id(cover_1).make_call();
// set attributes
call.set_position(0.5);
call.perform();

lambda calls

From lambdas, you can call several methods on all covers to do some advanced stuff.

  • publish_state(): Manually cause the cover to publish a new state and store it internally. If it’s different from the last internal state, it’s additionally published to the frontend.

    // Within lambda, make the cover report a specific state
    id(my_cover).publish_state(COVER_OPEN);
    id(my_cover).publish_state(COVER_CLOSED);
    
  • state: Retrieve the current state of the cover.

    if (id(my_cover).state == COVER_OPEN) {
      // Cover is open
    } else {
      // Cover is closed
    }