diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 7875bd9..ed67ab4 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3660,7 +3660,7 @@ variables: set_entity: 'esphome.{{ nspanel_name }}_set_entity' show: 'esphome.{{ nspanel_name }}_send_command_show' text_printf: 'esphome.{{ nspanel_name }}_send_command_text_printf' - tft_upload: 'esphome.{{ nspanel_name }}_upload_tft' + tft_upload_url: 'esphome.{{ nspanel_name }}_upload_tft_url' value: 'esphome.{{ nspanel_name }}_send_command_value' wake_up: 'esphome.{{ nspanel_name }}_wake_up' icon: @@ -9550,8 +9550,9 @@ action: sequence: - delay: seconds: 2 - - service: '{{ nextion.command.tft_upload }}' - data: {} + - service: '{{ nextion.command.tft_upload_url }}' + data: + url: "default" continue_on_error: true ############################################################# diff --git a/nspanel_esphome_addon_upload_tft.yaml b/nspanel_esphome_addon_upload_tft.yaml index a487db2..3a20c19 100644 --- a/nspanel_esphome_addon_upload_tft.yaml +++ b/nspanel_esphome_addon_upload_tft.yaml @@ -37,20 +37,31 @@ button: api: services: - ##### SERVICE TO UPDATE THE HMI FILE ############## - - service: upload_tft - then: - - logger.log: "Service: upload_tft" - - lambda: |- - upload_tft->execute("${nextion_update_url}"); - ##### SERVICE TO UPDATE THE TFT FILE from URL ##### - service: upload_tft_url variables: url: string then: - - logger.log: "Service: upload_tft_url" - lambda: |- + static const char *const TAG = "service.upload_tft_url"; + ESP_LOGVV(TAG, "Starting..."); + + auto toLowerAndTrim(const std::string& input) -> std::string { + std::string result = input; + // Convert to lowercase + std::transform(result.begin(), result.end(), result.begin(), + [](unsigned char c){ return std::tolower(c); }); + + // Trim trailing spaces + auto endPos = result.find_last_not_of(" \t"); + if (std::string::npos != endPos) { + result = result.substr(0, endPos + 1); + } + + return result; + }; + std::string clean_url = toLowerAndTrim(url.c_str()); + if ( clean_url.empty() or clean_url == "default") url = "${nextion_update_url}"; upload_tft->execute(url.c_str()); display: diff --git a/nspanel_esphome_core.yaml b/nspanel_esphome_core.yaml index 923de87..a06f748 100644 --- a/nspanel_esphome_core.yaml +++ b/nspanel_esphome_core.yaml @@ -49,6 +49,16 @@ esphome: ESP_LOGD(TAG, "Turn on Nextion"); screen_power->turn_on(); } + - wait_until: + condition: + - lambda: !lambda return disp1->is_setup(); + timeout: 20s + - lambda: |- + static const char *const TAG = "on_boot"; + if (not disp1->is_setup()) { + ESP_LOGE(TAG, "No response from Nextion display"); + } + ESP_LOGD(TAG, "Finished"); ##### TYPE OF ESP BOARD ##### esp32: