2018-06-01 18:10:00 +02:00
Template Cover
==============
2018-11-14 22:12:27 +01:00
.. seo ::
2019-02-16 23:25:23 +01:00
:description: Instructions for setting up template covers in ESPHome.
2018-11-19 18:32:16 +01:00
:image: description.png
2018-11-14 22:12:27 +01:00
2018-06-01 18:10:00 +02:00
The `` template `` cover platform allows you to create simple covers out of just a few
actions and a value lambda. Once defined, it will automatically appear in Home Assistant
as a cover and can be controlled through the frontend.
.. figure :: images/cover-ui.png
:align: center
:width: 75.0%
2018-11-19 18:32:16 +01:00
.. code-block :: yaml
2018-06-01 18:10:00 +02:00
# Example configuration entry
cover:
- platform: template
name: "Template Cover"
2019-01-06 18:56:14 +01:00
lambda: |-
2018-10-20 14:53:27 +02:00
if (id(top_end_stop).state) {
2019-05-12 22:44:59 +02:00
return COVER_OPEN;
2018-06-01 18:10:00 +02:00
} else {
2019-05-12 22:44:59 +02:00
return COVER_CLOSED;
2018-06-01 18:10:00 +02:00
}
open_action:
2018-11-10 14:31:27 +01:00
- switch.turn_on: open_cover_switch
2018-06-01 18:10:00 +02:00
close_action:
2018-11-10 14:31:27 +01:00
- switch.turn_on: close_cover_switch
2018-06-01 18:10:00 +02:00
stop_action:
2018-11-10 14:31:27 +01:00
- switch.turn_on: stop_cover_switch
2018-06-01 18:10:00 +02:00
optimistic: true
Possible return values for the optional lambda:
2019-05-12 22:44:59 +02:00
- `` return COVER_OPEN; `` if the cover should be reported as OPEN.
- `` return COVER_CLOSED; `` if the cover should be reported as CLOSED.
2018-06-01 18:10:00 +02:00
- `` return {}; `` if the last state should be repeated.
Configuration variables:
2018-08-24 22:44:01 +02:00
------------------------
2018-06-01 18:10:00 +02:00
2019-02-16 23:25:23 +01:00
- **name** (**Required** , string): The name of the cover.
- **lambda** (*Optional* , :ref: `lambda <config-lambda>` ):
Lambda to be evaluated repeatedly to get the current state of the cover.
- **open_action** (*Optional* , :ref: `Action <config-action>` ): The action that should
be performed when the remote (like Home Assistant's frontend) requests the cover to be opened.
- **close_action** (*Optional* , :ref: `Action <config-action>` ): The action that should
be performed when the remote requests the cover to be closed.
2019-05-12 22:44:59 +02:00
- **stop_action** (*Optional* , :ref: `Action <config-action>` ): The action that should
be performed when the remote requests the cover to be stopped.
2019-02-16 23:25:23 +01:00
- **optimistic** (*Optional* , boolean): Whether to operate in optimistic mode - when in this mode,
any command sent to the template cover will immediately update the reported state and no lambda
needs to be used. Defaults to `` false `` .
- **assumed_state** (*Optional* , boolean): Whether the true state of the cover is not known.
This will make the Home Assistant frontend show buttons for both OPEN and CLOSE actions, instead
of hiding one of them. Defaults to `` false `` .
2019-07-03 16:45:58 +02:00
- **tilt_action** (*Optional* , :ref: `Action <config-action>` ): The action that should
be performed when the remote (like Home Assistant's frontend) requests the cover be set to a specific
tilt position.
- **tilt_lambda** (*Optional* , :ref: `lambda <config-lambda>` ):
Lambda to be evaluated repeatedly to get the current tilt position of the cover.
2019-02-16 23:25:23 +01:00
- **id** (*Optional* , :ref: `config-id` ): Manually specify the ID used for code generation.
2019-05-12 22:44:59 +02:00
- All other options from :ref: `Cover <config-cover>` .
2019-02-16 23:25:23 +01:00
.. _cover-template-publish_action:
`` cover.template.publish `` Action
---------------------------------
You can also publish a state to a template cover from elsewhere in your YAML file
with the `` cover.template.publish `` action.
.. code-block :: yaml
# Example configuration entry
cover:
- platform: template
name: "Template Cover"
id: template_cov
# in some trigger
on_...:
- cover.template.publish:
id: template_cov
state: OPEN
# Templated
- cover.template.publish:
id: template_cov
2019-05-12 22:44:59 +02:00
state: !lambda 'return COVER_OPEN;'
2019-02-16 23:25:23 +01:00
Configuration options:
- **id** (**Required** , :ref: `config-id` ): The ID of the template cover.
2019-05-12 22:44:59 +02:00
- **state** (*Optional* , :ref: `templatable <config-templatable>` ):
2019-06-14 12:50:51 +02:00
The state to publish. One of `` OPEN `` , `` CLOSED `` . If using a lambda, use `` COVER_OPEN `` or `` COVER_CLOSED `` .
2019-05-12 22:44:59 +02:00
- **position** (*Optional* , :ref: `templatable <config-templatable>` , float):
2019-07-03 16:45:58 +02:00
The position to publish, from 0 (CLOSED) to 1.0 (OPEN)
- **tilt** (*Optional* , :ref: `templatable <config-templatable>` , float):
The tilt position to publish, from 0 (CLOSED) to 1.0 (OPEN)
2019-05-12 22:44:59 +02:00
- **current_operation** (*Optional* , :ref: `templatable <config-templatable>` , string):
2019-06-14 12:50:51 +02:00
The current operation mode to publish. One of `` IDLE `` , `` OPENING `` and `` CLOSING `` . If using a lambda, use `` COVER_OPERATION_IDLE `` , `` COVER_OPERATION_OPENING `` , and `` COVER_OPERATION_CLOSING `` .
2019-02-16 23:25:23 +01:00
.. note ::
This action can also be written in lambdas:
2019-07-03 15:32:06 +02:00
2019-02-16 23:25:23 +01:00
.. code-block :: cpp
2019-05-12 22:44:59 +02:00
id(template_cov).position = COVER_OPEN;
2019-07-03 16:45:58 +02:00
id(template_cov).tilt = 0.5;
2019-05-12 22:44:59 +02:00
id(template_cov).publish_state();
2018-06-01 18:10:00 +02:00
See Also
2018-08-24 22:44:01 +02:00
--------
2018-06-01 18:10:00 +02:00
2019-02-07 13:54:45 +01:00
- :doc: `/components/cover/index`
2018-06-01 18:10:00 +02:00
- :ref: `automation`
2019-02-07 13:54:45 +01:00
- :doc: `/cookbook/garage-door`
2019-05-12 22:44:59 +02:00
- :apiref: `template/cover/template_cover.h`
2019-02-07 13:54:45 +01:00
- :ghedit: `Edit`