Add lambda calls docs

This commit is contained in:
Otto Winter 2018-06-07 15:55:31 +02:00
parent d2ea5bede6
commit 2b4dcdf8d5
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
4 changed files with 146 additions and 0 deletions

View File

@ -150,6 +150,34 @@ Configuration variables:
- **max_length** (*Optional*, :ref:`config-time`): The maximum duration the click should last. Defaults to ``350ms``.
- See :ref:`Automation <automation>`.
lambda calls
""""""""""""
From :ref:`lambdas <config-lambda>`, you can call several methods on all binary sensors to do some
advanced stuff (see the full :doc:`API Reference </api/binary_sensor/index>` for more info).
- ``publish_state()``: Manually cause the binary sensor to publish and store a state from anywhere
in the program.
.. code:: yaml
// Within lambda, publish an OFF state.
id(my_binary_sensor).publish_state(false);
// Within lambda, publish an ON state.
id(my_binary_sensor).publish_state(true);
- ``value``: Retrieve the current value of the binary sensor.
.. code:: yaml
// Within lambda, get the binary sensor state and conditionally do something
if (id(my_binary_sensor).value) {
// Binary sensor is ON, do something here
} else {
// Binary sensor is OFF, do something else here
}
See Also
--------

View File

@ -47,6 +47,56 @@ This action stops the cover with the given ID when executed.
- cover.stop:
id: cover_1
lambda calls
""""""""""""
From :ref:`lambdas <config-lambda>`, you can call several methods on all covers to do some
advanced stuff (see the full :doc:`API Reference </api/cover/index>` for more info).
- ``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:: yaml
// 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:: yaml
if (id(my_cover).state == cover::COVER_OPEN) {
// Cover is open
} else if (id(my_cover).state == cover::COVER_CLOSED) {
// Cover is closed
} else {
// The cover hasn't reported any state yet.
}
- ``open()``: Manually cause the cover to open from code. Similar to the ``cover.open``
action, but can be used in complex lambda expressions.
.. code:: yaml
id(my_cover).open();
- ``close()``: Manually cause the cover to close from code. Similar to the ``cover.close``
action, but can be used in complex lambda expressions.
.. code:: yaml
id(my_cover).close();
- ``stop()``: Manually cause the cover to stop from code. Similar to the ``cover.stop``
action, but can be used in complex lambda expressions.
.. code:: yaml
id(my_cover).stop();
See Also
^^^^^^^^

View File

@ -261,6 +261,37 @@ with ``x``.
Configuration variables: See :ref:`Automation <automation>`.
lambda calls
""""""""""""
From :ref:`lambdas <config-lambda>`, you can call several methods on all sensors to do some
advanced stuff (see the full :doc:`API Reference </api/sensor/index>` for more info).
- ``push_new_value()``: Manually cause the sensor to push out a value. It will then
be processed by the sensor filters, and once done be published to MQTT.
.. code:: yaml
// Within lambda, push a value of 42.0
id(my_binary_sensor).push_new_value(42.0);
- ``value``: Retrieve the current value of the sensor that has passed through all sensor filters.
Is ``NAN`` if no value has gotten through all filters yet.
.. code:: yaml
// For example, create a custom log message when a value is received:
ESP_LOGI("main", "Value of my sensor: %f", id(my_sensor).value);
- ``raw_value``: Retrieve the current value of the sensor that has not passed through any filters
Is ``NAN`` if no value if no value has been pushed by the sensor itself yet.
.. code:: yaml
// For example, create a custom log message when a value is received:
ESP_LOGI("main", "Raw Value of my sensor: %f", id(my_sensor).value);
See Also
^^^^^^^^

View File

@ -68,6 +68,43 @@ This action turns a switch with the given ID off when executed.
- switch.turn_off:
id: relay_1
lambda calls
""""""""""""
From :ref:`lambdas <config-lambda>`, you can call several methods on all covers to do some
advanced stuff (see the full :doc:`API Reference </api/cover/index>` for more info).
- ``publish_state()``: Manually cause the switch 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:: yaml
// Within lambda, make the switch report a specific state
id(my_switch).publish_state(false);
id(my_switch).publish_state(true);
- ``state``: Retrieve the current state of the switch.
.. code:: yaml
// Within lambda, get the switch state and conditionally do something
if (id(my_switch).value) {
// Switch is ON, do something here
} else {
// Switch is OFF, do something else here
}
- ``write_state()``: Manually cause the cover to go into an OFF/ON state from code.
Similar to the ``switch.turn_on`` and ``switch.turn_off`` actions,
but can be used in complex lambda expressions.
.. code:: yaml
id(my_switch).write_state(false);
id(my_switch).write_state(true);
// Toggle the switch
id(my_switch).write_state(!id(my_switch).state);
See Also
^^^^^^^^