You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/components/api.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,10 @@ api:
115
115
Before using any of the actions below, you'll need to tell Home Assistant to allow your device to
116
116
perform actions.
117
117
118
+
> [!NOTE]
119
+
> Starting with ESPHome 2025.10.0, you can configure actions to receive and process responses from
120
+
> Home Assistant using `capture_response`, `on_success`, and `on_error`. See [Action Response Handling](#action-response-handling) for details.
121
+
118
122
Open the ESPHome integration page on your Home Assistant instance:
119
123
120
124
[](https://my.home-assistant.io/redirect/integration/?domain=esphome)
@@ -202,6 +206,20 @@ on_...:
202
206
- **variables** (*Optional*, mapping): Optional variables that can be used in the `data_template`.
203
207
Values are [lambdas](#config-lambda) and will be evaluated before sending the request.
204
208
209
+
- **capture_response** (*Optional*, boolean): Enable capturing the response from the Home Assistant action call.
210
+
When enabled, `on_success` must be configured. Defaults to `false`.
211
+
212
+
- **response_template** (*Optional*, [templatable](#config-templatable), string): Optional Jinja template to process
213
+
the action response data. This template is evaluated on the Home Assistant side with Home Assistant's templating engine.
214
+
Requires `capture_response: true`.
215
+
216
+
- **on_success** (*Optional*, [Automation](#automation)): Optional automation to execute when the Home Assistant action
217
+
call succeeds. When `capture_response: true`, the response data is available as a `response` variable of type `JsonObjectConst`.
218
+
See [Action Response Handling](#action-response-handling).
219
+
220
+
- **on_error** (*Optional*, [Automation](#automation)): Optional automation to execute when the Home Assistant action
221
+
call fails. See [Action Response Handling](#action-response-handling).
222
+
205
223
Data structures are not possible, but you can create a script in Home Assistant and call with all
206
224
the parameters in plain format.
207
225
@@ -235,6 +253,74 @@ on_...:
235
253
blue: '71'
236
254
```
237
255
256
+
#### Action Response Handling
257
+
258
+
> [!NOTE]
259
+
> Action response handling is available in ESPHome 2025.10.0 and later.
260
+
261
+
You can configure actions to receive and process responses from Home Assistant. This enables bidirectional
262
+
communication where ESPHome can not only call Home Assistant actions but also handle their responses.
263
+
264
+
##### Basic Success/Error Handling
265
+
266
+
Use `on_success` and `on_error` to respond to action completion:
267
+
268
+
```yaml
269
+
on_...:
270
+
- homeassistant.action:
271
+
action: light.toggle
272
+
data:
273
+
entity_id: light.demo_light
274
+
on_success:
275
+
- logger.log: "Toggled demo light"
276
+
on_error:
277
+
- logger.log: "Failed to toggle demo light"
278
+
```
279
+
280
+
##### Capturing Response Data
281
+
282
+
To capture and process response data from actions, set `capture_response: true`. When enabled, `on_success` must be configured
283
+
and the response data is available as a [`JsonObjectConst`](https://arduinojson.org/v7/api/jsonobjectconst/) variable named `response`.
284
+
285
+
```yaml
286
+
# Example: Get weather forecast and parse JSON response
0 commit comments