On this page

A cover entity controls something that opens and closes over an opening: blinds, shades, curtains, awnings, garage doors, gates, and motorized windows. It can report and set a position, and a tilt for blinds with slats. Inherit from CoverEntity in homeassistant.components.cover.

Only use a cover for something that covers an opening. A device that controls the flow of water or gas is a valve. A door you lock and unlock is a lock. For anything else, use another entity type, like a number, even where older integrations used a cover.

For how the frontend shows a cover, see the cover more-info view.

A cover that opens, closes, stops, and sets a position, in a tile card. The card is live: open, close, or move the blinds.

Properties

Cover entities have these properties on top of the generic entity properties. Every property can be set with its _attr_ attribute, like _attr_is_closed.

Name Type Default Description
is_closed bool | None Required Whether the cover is closed. Used for the state.
is_opening bool | None None Whether the cover is opening. Used for the state.
is_closing bool | None None Whether the cover is closing. Used for the state.
current_cover_position int | None None The position, from 0 (closed) to 100 (fully open).
current_cover_tilt_position int | None None The tilt, from 0 to 100. Closed at 0 and open at 100, unless you describe it differently. See Tilt position.
open_tilt_position int | None None The tilt where the slats are open, from 0 to 100. None means the default. See Tilt position.
closed_tilt_positions list[int] | None None The tilts where the slats are closed: 0, 100, or both. None means the default. See Tilt position.
tilt_start_angle int | None None The angle of the slats at tilt 0, from -90 to 90 degrees. Set it together with tilt_end_angle, to a different value.
tilt_end_angle int | None None The angle of the slats at tilt 100, from -90 to 90 degrees. Set it together with tilt_start_angle, to a different value.
device_class CoverDeviceClass | None None What kind of cover it is. See Device classes.
supported_speeds list[str] | None None The speeds the cover can move at when it opens, closes, or moves to a position. None or an empty list means no speed selection. Use the standard speeds CoverSpeed.FAST, CoverSpeed.MEDIUM, and CoverSpeed.SLOW from homeassistant.components.cover where they fit your device. An action without a speed moves the cover at the device's default speed.

When you set supported_speeds to a list, Home Assistant adds it as the supported_speeds attribute, and checks the speed in an action against it before it calls you. A speed that is not in the list is dropped, and the cover moves at its default speed. Without speeds, a speed in an action is dropped.

Tilt position

The tilt is a number from 0 to 100. By default, the slats are closed at 0 and open at 100. If your cover works differently, describe it with these properties:

  • open_tilt_position is the tilt where the slats are open. Your open_cover_tilt moves the slats there.
  • closed_tilt_positions holds the tilts where the slats are closed: [0], [100], or [0, 100]. Your close_cover_tilt moves the slats to the most closed position. With [0, 100], you decide what that means: if one end blocks more light, always close there. If both ends are equally closed, you can leave slats that are known to be closed where they are, or always close to the same end. If the tilt is only assumed, because the device doesn't report it, close anyway.
  • tilt_start_angle and tilt_end_angle are the angles of the slats at tilt 0 and at tilt 100, in degrees. Set both or neither.

A blind that is open in the middle of the scale, and closed at 0 and at 100:

Python
class MyBlind(CoverEntity):
    _attr_supported_features = (
        CoverEntityFeature.OPEN_TILT
        | CoverEntityFeature.CLOSE_TILT
        | CoverEntityFeature.SET_TILT_POSITION
    )
    _attr_open_tilt_position = 50
    _attr_closed_tilt_positions = [0, 100]

If you know how the slats turn, set the angles instead. Home Assistant then works out the positions, and code that needs the shape of the slats, like the HomeKit bridge or a drawing of the cover, can use them. A blind with slats that turn 180° is open at 50, and closed at 0 and at 100:

Python
class MyBlind(CoverEntity):
    _attr_supported_features = (
        CoverEntityFeature.OPEN_TILT
        | CoverEntityFeature.CLOSE_TILT
        | CoverEntityFeature.SET_TILT_POSITION
    )
    _attr_tilt_start_angle = -90
    _attr_tilt_end_angle = 90

Set the positions as well when the device is open or closed somewhere else than the angles say.

For the angles, 0° is a slat perpendicular to the cover, and -90° and 90° are a slat that lies flat. The angle changes evenly between tilt 0 and tilt 100. A negative angle means the inside edge of the slat is higher than the outside edge. For vertical slats, seen from inside, it means the inside edge is to the left of the outside edge. If you don't know how the cover is mounted, or it has no inside and outside, like a pergola roof, make the angle go up with the tilt, like -90 and 90. The angles are approximate: good enough to draw the slats, not to follow the sun.

When you only set the angles, the cover is open where the angle is closest to 0°, rounded to a whole number, and closed where the slats lie the flattest. When both ends are equally flat, both are closed positions. If the device is closed at only one end, set closed_tilt_positions yourself.

The positions are exact. When the slats are closed, report exactly a closed position, like 100 and not 98. If the angles give 50 but the device reports 51 when it is open, set open_tilt_position to 51.

When the cover supports SET_TILT_POSITION, Home Assistant adds the open and closed positions as state attributes, with the defaults filled in. It adds the angles when you set them. The recorder doesn't store these attributes. Change the values only when the device or its configuration changes, not with the position of the slats, and keep them while the device is unavailable. Set supported_features yourself, as the examples do. If Home Assistant guesses the features, SET_TILT_POSITION and these attributes disappear whenever the tilt is unknown.

toggle_tilt uses the values for every cover, also one without SET_TILT_POSITION.

Home Assistant raises a ValueError when the values are invalid or contradict each other:

  • Only one angle is set, an angle is not a whole number from -90 to 90, or both angles are the same.
  • open_tilt_position is not a whole number from 0 to 100, or closed_tilt_positions doesn't hold 0, 100, or both.
  • The open position is also a closed position, including a default. A cover that is only closed at 100 also sets open_tilt_position, because the default open position is 100.

Home Assistant checks the values when it writes the state of a cover that supports SET_TILT_POSITION, and when toggle_tilt runs. If the check fails while the entity is added, the entity is not added. If it fails on a later state write, the state of the entity stops updating. If it fails in toggle_tilt, the action fails. Check the values you read from a device before you set them.

Device classes

Set a device class from CoverDeviceClass. It sets the icon, the wording of the states in the frontend, and how voice assistants talk about the cover.

Value Description
AWNING An awning, like an exterior retractable window, door, or patio cover.
BLIND Blinds: linked slats that expand, collapse, or tilt to cover an opening, like window blinds.
CURTAIN Curtains or drapes, often fabric hung above a window or door, drawn open and closed.
DAMPER A mechanical damper that reduces air flow, sound, or light.
DOOR A door that gives access to an area, typically part of a building.
GARAGE A garage door.
GATE A gate to a driveway or other area, outside a building and typically part of a fence.
SHADE Shades: one continuous piece of material or connected cells that expands or collapses over an opening, like window shades.
SHUTTER Shutters: linked slats that swing out or in, or tilt, to cover an opening, like window shutters.
WINDOW A window that opens, closes, or tilts.

Supported features

Combine the CoverEntityFeature flags with | and set them as supported_features. See supported features.

Value Description
OPEN The cover can open. Implement open_cover.
CLOSE The cover can close. Implement close_cover.
SET_POSITION The cover can move to a position. Implement set_cover_position.
STOP The cover can stop while it moves. Implement stop_cover.
OPEN_TILT The cover can tilt open. Implement open_cover_tilt.
CLOSE_TILT The cover can tilt closed. Implement close_cover_tilt.
STOP_TILT The cover can stop while it tilts. Implement stop_cover_tilt.
SET_TILT_POSITION The cover can tilt to a position. Implement set_cover_tilt_position.
SPEED The cover can move at different speeds. Set supported_speeds.

If you do not set supported_features at all, Home Assistant guesses: OPEN, CLOSE, and STOP, plus SET_POSITION when the cover reports a position, all tilt features when it reports a tilt, and SPEED when it has speeds. The guess follows the current state, so a cover loses SET_POSITION and its tilt features whenever its position or tilt is unknown, for example while the device is unavailable. Set the features yourself, so they describe what the cover can do and don't change with its state.

Methods

Implement the sync or the async variant of each method, not both.

Method Async variant Feature
open_cover(**kwargs: Any) async_open_cover OPEN
close_cover(**kwargs: Any) async_close_cover CLOSE
set_cover_position(**kwargs: Any) async_set_cover_position SET_POSITION
stop_cover(**kwargs: Any) async_stop_cover STOP
open_cover_tilt(**kwargs: Any) async_open_cover_tilt OPEN_TILT
close_cover_tilt(**kwargs: Any) async_close_cover_tilt CLOSE_TILT
set_cover_tilt_position(**kwargs: Any) async_set_cover_tilt_position SET_TILT_POSITION
stop_cover_tilt(**kwargs: Any) async_stop_cover_tilt STOP_TILT

set_cover_position receives ATTR_POSITION, and set_cover_tilt_position receives ATTR_TILT_POSITION, both from 0 to 100. open_cover, close_cover, and set_cover_position can receive ATTR_SPEED when the cover has supported_speeds.

Toggling is handled for you. toggle stops a moving cover when it supports STOP, opens a closed or closing cover, and closes an opening or fully open one. A cover that stopped partly open moves the other way from the last direction it reported, and closes when it never reported one. toggle_tilt opens the tilt when it is exactly at a closed position, and closes it otherwise, also when the tilt is unknown. See Tilt position.

States

The state comes from is_opening, is_closing, and is_closed, in that order, as a CoverState:

Value Description
CoverState.OPENING The cover is opening.
CoverState.CLOSING The cover is closing.
CoverState.CLOSED The cover is closed.
CoverState.OPEN The cover is open, fully or partly.

When the cover is not moving and is_closed is None, the state is unknown.

Example

Python
from typing import Any

from homeassistant.components.cover import (
    ATTR_POSITION,
    CoverDeviceClass,
    CoverEntity,
    CoverEntityFeature,
)


class MyBlind(CoverEntity):
    """A blind that moves to a position."""

    _attr_has_entity_name = True
    _attr_name = None
    _attr_device_class = CoverDeviceClass.BLIND
    _attr_supported_features = (
        CoverEntityFeature.OPEN
        | CoverEntityFeature.CLOSE
        | CoverEntityFeature.STOP
        | CoverEntityFeature.SET_POSITION
    )

    def __init__(self, device: MyDevice) -> None:
        """Set up the blind."""
        self._device = device
        self._attr_unique_id = device.serial

    @property
    def current_cover_position(self) -> int:
        """Return the position, 0 is closed."""
        return self._device.position

    @property
    def is_closed(self) -> bool:
        """Return if the blind is closed."""
        return self._device.position == 0

    async def async_open_cover(self, **kwargs: Any) -> None:
        """Open the blind."""
        await self._device.move_to(100)

    async def async_close_cover(self, **kwargs: Any) -> None:
        """Close the blind."""
        await self._device.move_to(0)

    async def async_set_cover_position(self, **kwargs: Any) -> None:
        """Move the blind to a position."""
        await self._device.move_to(kwargs[ATTR_POSITION])

    async def async_stop_cover(self, **kwargs: Any) -> None:
        """Stop the blind."""
        await self._device.stop()
Was this page helpful?

Last updated on .