TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
http_request component lets your ESPHome device reach out to external HTTP and HTTPS servers — REST APIs, webhooks, local home automation endpoints, or any URL your device can route to. Trigger requests from any automation (button presses, sensor thresholds, time schedules), capture and parse JSON responses, and feed the results back into your device’s sensors or switches, all from YAML.
http_request performs network I/O and will block the ESPHome main loop for the duration of each request. Keep timeouts short and avoid making requests in time-critical automation paths. For ESP32, SSL certificate verification is on by default and uses the Mozilla NSS root certificate bundle embedded in the firmware.Minimal Configuration
Configuration Variables
Maximum time to wait for the server to respond before aborting the request. Defaults to
4.5s.Automatically follow HTTP 3xx redirects. Defaults to
true.Maximum number of consecutive redirects to follow when
follow_redirects is true. Defaults to 3.Value of the
User-Agent header sent with every request. Defaults to ESPHome/<version> (https://esphome.io) — for example, ESPHome/2024.6.0 (https://esphome.io).Validate the server’s SSL/TLS certificate against the embedded Mozilla NSS root certificate bundle. Defaults to
true. Only supported on ESP32. Must be explicitly set to false on other platforms when using HTTPS.Override the hardware watchdog timeout during HTTP transfers. Only change this if your device is rebooting due to watchdog resets on very slow connections. Available on ESP32 and RP2040 only.
Manually specify the component ID for use in code generation and lambdas.
Platform-specific Options
ESP32
HTTP receive buffer size in bytes. Defaults to
512.HTTP transmit buffer size in bytes. Defaults to
512.Path to a PEM-encoded CA certificate file to verify connections to servers using custom or self-signed CA certificates. The certificate is embedded at compile time. When set, the default Mozilla certificate bundle is not included, reducing firmware size.
ESP8266
TLS receive buffer size. Modern HTTPS servers use 16384-byte TLS records; set this to
16384 to handle them correctly. This significantly increases RAM usage. Defaults to 512.TLS transmit buffer size. Defaults to
512.Exclude SSL libraries from the build to reduce binary size. When
true, HTTPS is unavailable and verify_ssl: false is implied. Useful for 512 KB or 1 MB flash devices. Defaults to false.Actions
http_request.get Action
Sends an HTTP GET request to a URL. Use this to read data from APIs or trigger webhooks.
Action Variables
Names of response headers to collect for use in
on_response via response->get_response_header("Header-Name").When
true, the full response body is captured into a std::string named body, available in on_response lambdas. Defaults to false.Maximum size of the response buffer when
capture_response is true. Defaults to 1 kB.Automation triggered when the request completes (regardless of status code). Available variables:
response (pointer to HttpContainer with status_code, duration_ms, content_length), body (string, if capture_response: true).Automation triggered if the request could not be completed at all (network error, timeout, DNS failure). Not triggered for non-200 HTTP responses.
http_request.post Action
Sends an HTTP POST request. Supports raw body strings and structured JSON payloads.
Additional Variables (beyond http_request.get)
Body encoded as JSON. Two syntax options:
- Mapping (syntax 1): Key-value pairs where all values must be strings. Supports templates per value.
- Lambda block (syntax 2): A C++ lambda with access to a
rootArduinoJsonJsonObject. Useroot["key"] = value;to set fields. Allows booleans and numeric types.
http_request.send Action
General-purpose action supporting any HTTP method.
HTTP method to use. One of:
GET, POST, PUT, DELETE, PATCH.http_request.get and http_request.post apply.
Response Handling
Theon_response trigger receives these variables:
| Variable | Type | Description |
|---|---|---|
response | HttpContainer* | Pointer to response metadata |
response->status_code | int | HTTP status code (e.g. 200, 404) |
response->duration_ms | uint32_t | Round-trip time in milliseconds |
response->content_length | int | Content-Length header value (may be -1) |
body | std::string | Response body (only when capture_response: true) |
response->get_response_header("Header-Name") to read a specific response header (must be listed in collect_headers).
Always check
response->status_code before using body. Server errors (404, 500, etc.) return a non-200 code and may include an error message in the body.Examples
Call a Webhook on Button Press
Parse a JSON API Response
This example fetches a media player status and publishes the volume to a template sensor. Assume the server returns{"status":"play","vol":"42","mute":"0"}:
Templatable URL and Headers
POST with Numeric JSON (ArduinoJson syntax)
Collect and Log Response Headers
See Also
- JSON Component
- ArduinoJson Library
- Automations & Actions