esphome-docs/components/cover/index.rst

112 lines
2.2 KiB
ReStructuredText
Raw Normal View History

2018-06-01 18:10:00 +02:00
Cover Component
===============
2018-11-14 22:12:27 +01:00
.. seo::
2019-02-16 23:25:23 +01:00
:description: Instructions for setting up base covers in ESPHome.
:image: folder-opn.png
2018-11-14 22:12:27 +01:00
2019-02-16 23:25:23 +01:00
The ``cover`` component is a generic representation of covers in ESPHome.
2018-06-01 18:10:00 +02:00
A cover can (currently) either be *closed* or *open* and supports three types of
commands: *open*, *close* and *stop*.
.. _cover-open_action:
``cover.open`` Action
2018-08-24 22:44:01 +02:00
---------------------
2018-06-01 18:10:00 +02:00
This action opens the cover with the given ID when executed.
.. code-block:: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
- cover.open: cover_1
.. note::
This action can also be expressed in :ref:`lambdas <config-lambda>`:
.. code-block:: cpp
id(cover_1).open();
2018-06-01 18:10:00 +02:00
.. _cover-close_action:
``cover.close`` Action
2018-08-24 22:44:01 +02:00
----------------------
2018-06-01 18:10:00 +02:00
This action closes the cover with the given ID when executed.
.. code-block:: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
- cover.close: cover_1
.. note::
This action can also be expressed in :ref:`lambdas <config-lambda>`:
.. code-block:: cpp
id(cover_1).close();
2018-06-01 18:10:00 +02:00
.. _cover-stop_action:
``cover.stop`` Action
2018-08-24 22:44:01 +02:00
---------------------
2018-06-01 18:10:00 +02:00
This action stops the cover with the given ID when executed.
.. code-block:: yaml
2018-06-01 18:10:00 +02:00
on_...:
then:
- cover.stop: cover_1
.. note::
This action can also be expressed in :ref:`lambdas <config-lambda>`:
.. code-block:: cpp
id(cover_1).stop();
2018-06-01 18:10:00 +02:00
2018-06-07 15:55:31 +02:00
lambda calls
2018-08-24 22:44:01 +02:00
------------
2018-06-07 15:55:31 +02:00
From :ref:`lambdas <config-lambda>`, you can call several methods on all covers to do some
advanced stuff.
2018-06-07 15:55:31 +02:00
- ``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.
.. code-block:: yaml
2018-06-07 15:55:31 +02:00
// Within lambda, make the cover report a specific state
id(my_cover).publish_state(cover::COVER_OPEN);
id(my_cover).publish_state(cover::COVER_CLOSED);
- ``state``: Retrieve the current state of the cover.
.. code-block:: yaml
2018-06-07 15:55:31 +02:00
if (id(my_cover).state == cover::COVER_OPEN) {
// Cover is open
} else {
// Cover is closed
2018-06-07 15:55:31 +02:00
}
2018-06-03 12:50:44 +02:00
See Also
2018-08-24 22:44:01 +02:00
--------
2018-06-01 18:10:00 +02:00
- :apiref:`cover/cover.h`
- :ghedit:`Edit`
2018-06-01 18:10:00 +02:00
.. toctree::
:maxdepth: 1
:glob:
2018-06-01 18:10:00 +02:00
*