1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Split response and error triggers

Simplify variables in response lambdas to JsonObject
Use `const char *` for message and parse to json right away
This commit is contained in:
Jesse Hills
2025-10-06 17:04:47 +13:00
parent a405592385
commit 0e0b67f126
14 changed files with 128 additions and 96 deletions

View File

@@ -17,14 +17,12 @@ esphome:
type: hourly
on_response:
- lambda: |-
if (response->is_success()) {
JsonObject json = response->get_json();
JsonObject next_hour = json["response"]["weather.forecast_home"]["forecast"][0];
float next_temperature = next_hour["temperature"].as<float>();
ESP_LOGD("main", "Next hour temperature: %f", next_temperature);
} else {
ESP_LOGE("main", "Action failed: %s", response->get_error_message().c_str());
}
JsonObject next_hour = response["response"]["weather.forecast_home"]["forecast"][0];
float next_temperature = next_hour["temperature"].as<float>();
ESP_LOGD("main", "Next hour temperature: %f", next_temperature);
on_error:
- lambda: |-
ESP_LOGE("main", "Action failed with error: %s", error.c_str());
- homeassistant.action:
action: weather.get_forecasts
data:
@@ -33,13 +31,8 @@ esphome:
response_template: "{{ response['weather.forecast_home']['forecast'][0]['temperature'] }}"
on_response:
- lambda: |-
if (response->is_success()) {
JsonObject json = response->get_json();
float temperature = json["response"].as<float>();
ESP_LOGD("main", "Next hour temperature: %f", temperature);
} else {
ESP_LOGE("main", "Action failed: %s", response->get_error_message().c_str());
}
float temperature = response["response"].as<float>();
ESP_LOGD("main", "Next hour temperature: %f", temperature);
api:
port: 8000