mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-12-26 17:27:47 +01:00
Logger on_message trigger (#374)
* Docs * Review * Note added, example updated * Fix RST code syntax. Expand note. Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
5e930355d1
commit
8cac9af453
@ -159,6 +159,35 @@ Configuration options:
|
|||||||
- **tag** (*Optional*, string): The tag (seen in front of the message in the logs) to print the message
|
- **tag** (*Optional*, string): The tag (seen in front of the message in the logs) to print the message
|
||||||
with. Defaults to ``main``.
|
with. Defaults to ``main``.
|
||||||
|
|
||||||
|
Logger Automation
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
.. _logger-on_message:
|
||||||
|
|
||||||
|
``on_message``
|
||||||
|
**************
|
||||||
|
|
||||||
|
This automation will be triggered when a new message is added to the log.
|
||||||
|
In :ref:`lambdas <config-lambda>` you can get the message, log level and tag from the trigger
|
||||||
|
using ``message`` (``const char *``), ``level`` (``int``) and ``tag`` (``const char *``).
|
||||||
|
|
||||||
|
.. code-block:: yaml
|
||||||
|
|
||||||
|
logger:
|
||||||
|
# ...
|
||||||
|
on_message:
|
||||||
|
level: ERROR
|
||||||
|
then:
|
||||||
|
- mqtt.publish:
|
||||||
|
topic: some/topic
|
||||||
|
payload: !lambda |-
|
||||||
|
return "Triggered on_message with level " + std::to_string(level) + ", tag " + tag + " and message " + message;
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Logging will not work in the ``on_message`` trigger. You can't use the :doc:`logger.log <logger-log_action>` action
|
||||||
|
and the ``ESP_LOGx`` logging macros in this automation.
|
||||||
|
|
||||||
See Also
|
See Also
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -321,6 +321,7 @@ All Triggers
|
|||||||
- :ref:`binary_sensor.on_click <binary_sensor-on_click>` / :ref:`binary_sensor.on_double_click <binary_sensor-on_double_click>` /
|
- :ref:`binary_sensor.on_click <binary_sensor-on_click>` / :ref:`binary_sensor.on_double_click <binary_sensor-on_double_click>` /
|
||||||
:ref:`binary_sensor.on_multi_click <binary_sensor-on_multi_click>`
|
:ref:`binary_sensor.on_multi_click <binary_sensor-on_multi_click>`
|
||||||
- :ref:`esphome.on_boot <esphome-on_boot>` / :ref:`esphome.on_shutdown <esphome-on_shutdown>` / :ref:`esphome.on_loop <esphome-on_loop>`
|
- :ref:`esphome.on_boot <esphome-on_boot>` / :ref:`esphome.on_shutdown <esphome-on_shutdown>` / :ref:`esphome.on_loop <esphome-on_loop>`
|
||||||
|
- :ref:`logger.on_message <logger-on_message>`
|
||||||
- :ref:`time.on_time <time-on_time>`
|
- :ref:`time.on_time <time-on_time>`
|
||||||
- :ref:`mqtt.on_message <mqtt-on_message>` / :ref:`mqtt.on_json_message <mqtt-on_json_message>`
|
- :ref:`mqtt.on_message <mqtt-on_message>` / :ref:`mqtt.on_json_message <mqtt-on_json_message>`
|
||||||
- :ref:`pn532.on_tag <pn532-on_tag>` / :ref:`rdm6300.on_tag <rdm6300-on_tag>`
|
- :ref:`pn532.on_tag <pn532-on_tag>` / :ref:`rdm6300.on_tag <rdm6300-on_tag>`
|
||||||
|
Loading…
Reference in New Issue
Block a user