From 9265b6cc8b3d71a99029c581abdb2a8d84530f4f Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 22 Mar 2021 16:26:19 +1300 Subject: [PATCH] Add docs for http_request on_response trigger (#1049) --- components/http_request.rst | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/components/http_request.rst b/components/http_request.rst index a11d384d8..b9da808c1 100644 --- a/components/http_request.rst +++ b/components/http_request.rst @@ -49,6 +49,12 @@ This :ref:`action ` sends a GET request. headers: Content-Type: application/json verify_ssl: false + on_response: + then: + - logger.log: + format: 'Response status: %d' + args: + - status_code # Short form - http_request.get: https://esphome.io @@ -57,6 +63,7 @@ Configuration variables: - **url** (**Required**, string, :ref:`templatable `): URL to send request. - **headers** (*Optional*, mapping): Map of HTTP headers. Values are :ref:`templatable `. - **verify_ssl** (*Optional*, boolean): Verify the SSL certificate of the endpoint. Defaults to ``true``. +- **on_response** (*Optional*, :ref:`Automation `): An automation to perform when the request is finished. .. note:: @@ -112,6 +119,29 @@ Configuration variables: - **method** (**Required**, string): HTTP method to use (``GET``, ``POST``, ``PUT``, ``DELETE``, ``PATCH``). - All other options from :ref:`http_request-post_action`. +.. _http_request-on_response: + +``on_response`` Trigger +----------------------- + +This automation will be triggered when the HTTP request is finished and will supply the +http response code in parameter ``status_code`` as an ``int``. + +.. code-block:: yaml + + on_... + then: + - http_request.get: + url: https://esphome.io + verify_ssl: false + on_response: + then: + - logger.log: + format: "Response status: %d" + args: + - status_code + + .. _http_request-examples: Examples