mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-08-16 21:53:10 +02:00
48 lines
1.5 KiB
ReStructuredText
48 lines
1.5 KiB
ReStructuredText
Template Sensor
|
|
===============
|
|
|
|
The ``template`` sensor platform allows you to create a sensor with templated values
|
|
using :ref:`lambdas <config-lambda>`.
|
|
|
|
.. code:: yaml
|
|
|
|
# Example configuration entry
|
|
sensor:
|
|
- platform: template
|
|
name: "Template Sensor"
|
|
lambda: >-
|
|
if (id(some_binary_sensor).state) {
|
|
return 42.0;
|
|
} else {
|
|
return 0.0;
|
|
}
|
|
update_interval: 15s
|
|
|
|
|
|
Possible return values for the lambda:
|
|
|
|
- ``return <FLOATING_POINT_NUMBER>;`` the new value for the sensor.
|
|
- ``return NAN;`` if the state should be considered invalid to indicate an error (advanced).
|
|
- ``return {};`` if you don't want to publish a new state (advanced).
|
|
|
|
Configuration variables:
|
|
------------------------
|
|
|
|
- **name** (**Required**, string): The name of the sensor.
|
|
- **lambda** (*Optional*, :ref:`lambda <config-lambda>`):
|
|
Lambda to be evaluated every update interval to get the new value of the sensor
|
|
- **update_interval** (*Optional*, :ref:`config-time`): The interval to check the
|
|
sensor. Defaults to ``15s``. See :ref:`sensor-default_filter`.
|
|
- **id** (*Optional*,:ref:`config-id`): Manually specify the ID used for code generation.
|
|
- All other options from :ref:`Sensor <config-sensor>` and :ref:`MQTT Component <config-mqtt-component>`.
|
|
|
|
See Also
|
|
--------
|
|
|
|
- :ref:`sensor-filters`
|
|
- :ref:`automation`
|
|
- :doc:`API Reference </api/sensor/template>`
|
|
- `Edit this page on GitHub <https://github.com/OttoWinter/esphomedocs/blob/current/esphomeyaml/components/sensor/template.rst>`__
|
|
|
|
.. disqus::
|