2020-06-14 00:35:55 +02:00
|
|
|
Template Output
|
|
|
|
===============
|
|
|
|
|
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up template outputs with ESPHome.
|
2021-11-16 03:19:33 +01:00
|
|
|
:image: description.svg
|
2020-06-14 00:35:55 +02:00
|
|
|
|
|
|
|
The ``template`` output component can be used to create templated binary and float outputs in ESPHome.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
output:
|
|
|
|
- platform: template
|
|
|
|
id: outputsplit
|
|
|
|
type: float
|
|
|
|
write_action:
|
|
|
|
- output.set_level:
|
|
|
|
id: output1
|
|
|
|
level: !lambda return state;
|
|
|
|
- output.set_level:
|
|
|
|
id: output2
|
|
|
|
level: !lambda return state;
|
|
|
|
|
|
|
|
- platform: esp8266_pwm
|
|
|
|
id: output1
|
|
|
|
pin: GPIO12
|
|
|
|
inverted: true
|
|
|
|
- platform: esp8266_pwm
|
|
|
|
id: output2
|
|
|
|
pin: GPIO14
|
|
|
|
inverted: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
- **id** (**Required**, :ref:`config-id`): The id to use for this output component.
|
|
|
|
- **type** (**Required**, string): The type of output. One of ``binary`` and ``float``.
|
2021-02-20 22:02:46 +01:00
|
|
|
- **write_action** (**Required**, :ref:`Automation <automation>`): An automation to perform
|
|
|
|
when the state of the output is updated.
|
2020-06-14 00:35:55 +02:00
|
|
|
- All other options from :ref:`Output <config-output>`.
|
|
|
|
|
|
|
|
See :apiclass:`output::BinaryOutput` and :apiclass:`output::FloatOutput`.
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
This is an **output component** and will not be visible from the frontend. Output components are intermediary
|
|
|
|
components that can be attached to for example lights.
|
|
|
|
|
|
|
|
.. _output-template-on_write_action:
|
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
``write_action`` Trigger
|
|
|
|
------------------------
|
2020-06-14 00:35:55 +02:00
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
When the state for this output is updated, the ``write_action`` is triggered.
|
2020-06-14 00:35:55 +02:00
|
|
|
It is possible to access the state value inside Lambdas:
|
|
|
|
|
2021-02-07 17:35:39 +01:00
|
|
|
.. code-block:: yaml
|
2020-06-14 00:35:55 +02:00
|
|
|
|
|
|
|
- platform: template
|
|
|
|
id: my_output
|
|
|
|
type: float
|
|
|
|
write_action:
|
|
|
|
- if:
|
|
|
|
condition:
|
|
|
|
lambda: return ((state > 0) && (state < .4));
|
|
|
|
then:
|
|
|
|
- output.turn_on: button_off
|
|
|
|
- delay: 500ms
|
|
|
|
- output.turn_off: button_off
|
|
|
|
|
|
|
|
|
|
|
|
Complete example from the cookbook: :doc:`Sonoff Dual Light Switch</cookbook/sonoff-dual-light-switch>`.
|
|
|
|
|
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
|
|
|
- :doc:`/components/output/index`
|
|
|
|
- :ref:`automation`
|
|
|
|
- :ghedit:`Edit`
|