diff --git a/components/logger.rst b/components/logger.rst index b8127023d..614ad5164 100644 --- a/components/logger.rst +++ b/components/logger.rst @@ -159,6 +159,35 @@ Configuration options: - **tag** (*Optional*, string): The tag (seen in front of the message in the logs) to print the message 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 ` 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 ` action + and the ``ESP_LOGx`` logging macros in this automation. + See Also -------- diff --git a/guides/automations.rst b/guides/automations.rst index ba8394ff4..f8e3ee145 100644 --- a/guides/automations.rst +++ b/guides/automations.rst @@ -321,6 +321,7 @@ All Triggers - :ref:`binary_sensor.on_click ` / :ref:`binary_sensor.on_double_click ` / :ref:`binary_sensor.on_multi_click ` - :ref:`esphome.on_boot ` / :ref:`esphome.on_shutdown ` / :ref:`esphome.on_loop ` +- :ref:`logger.on_message ` - :ref:`time.on_time ` - :ref:`mqtt.on_message ` / :ref:`mqtt.on_json_message ` - :ref:`pn532.on_tag ` / :ref:`rdm6300.on_tag `