diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 6ba36c4..0b503f8 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -188,7 +188,7 @@ These files are considerably bigger, as the fonts requires more memory, but it s ### 6. Improved TFT transfer -#### TFT file selectors +#### TFT file selectors (`ESP-IDF` framework required) We still working on the Upload TFT engine to make it easier for new and for experienced users. Now, together with the **Update TFT Display** button, you will find also **Update TFT Display - Model** and **Update TFT Display - Branch** (disabled by default) where you can select the different model you are using and the upload URL will be automatically adjusted to donwload the file directly from the repository on GitHub, diff --git a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml index 91371ca..cc5a5b1 100644 --- a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml +++ b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml @@ -65,6 +65,20 @@ display: tft_url: ${nextion_update_url} exit_reparse_on_start: true +esphome: + on_boot: + - priority: 601.0 + then: + - lambda: |- + // Hide TFT file selectors when using arduino + #ifdef ARDUINO + tft_file_branch->set_internal(true); + tft_file_model->set_internal(true); + #elif defined(ESP_PLATFORM) + tft_file_branch->set_internal(false); + tft_file_model->set_internal(false); + #endif + globals: - id: baud_rate_original type: uint @@ -217,7 +231,11 @@ script: then: - delay: 2s - lambda: |- - static const char *const TAG = "addon_upload_tft.script.set_tft_file"; + #ifdef ARDUINO + static const char *const TAG = "addon_upload_tft.script.set_tft_file.arduino"; + #elif defined(ESP_PLATFORM) + static const char *const TAG = "addon_upload_tft.script.set_tft_file.esp_idf"; + #endif std::string branch = tft_file_branch->state; std::string model = tft_file_model->state; ESP_LOGD(TAG, "TFT URL set:"); @@ -229,8 +247,11 @@ script: id(tft_model) = tft_file_model->active_index().value(); if (id(is_uploading_tft)) - ESP_LOGW(TAG, "TFT Upload in progress."); + ESP_LOGW(TAG, " TFT Upload in progress."); else { + #ifdef ARDUINO + std::string url = "${nextion_update_url}"; + #elif defined(ESP_PLATFORM) std::string url; std::string file_name; if (model == "NSPanel Blank") file_name = "nspanel_blank.tft"; @@ -251,6 +272,7 @@ script: url = url.substr(0, endPos + 1); } } + #endif ESP_LOGD(TAG, " Full URL: %s", url.c_str()); id(tft_url) = url; @@ -308,6 +330,27 @@ script: // Upload URL ESP_LOGD(TAG, " Upload URL: %s", url.c_str()); + #ifdef ARDUINO + auto startsWith = [](const std::string& str, const std::string& prefix) -> bool { + if (str.length() < prefix.length()) return false; + + std::string lowerStr = str.substr(0, prefix.length()); + std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), + [](unsigned char c){ return std::tolower(c); }); + + std::string lowerPrefix = prefix; + std::transform(lowerPrefix.begin(), lowerPrefix.end(), lowerPrefix.begin(), + [](unsigned char c){ return std::tolower(c); }); + + return lowerStr == lowerPrefix; + }; + + if (startsWith(url, "https")) { + ESP_LOGE(TAG, "HTTPS is not supported by Arduino framework."); + ESP_LOGE(TAG, "This transfer will most likely fail."); + ESP_LOGE(TAG, "Please use HTTP instead."); + } + #endif disp1->set_tft_url(url.c_str()); nextion_uart_command->execute("bkcmd=3"); @@ -1237,7 +1280,7 @@ select: initial_option: "main" optimistic: true restore_value: true - internal: false + internal: true entity_category: config disabled_by_default: true icon: mdi:file-sync @@ -1259,7 +1302,7 @@ select: initial_option: "Use nextion_update_url" optimistic: true restore_value: true - internal: false + internal: true entity_category: config disabled_by_default: false icon: mdi:file-sync diff --git a/advanced/esphome/nspanel_esphome_prebuilt.yaml b/advanced/esphome/nspanel_esphome_prebuilt.yaml index 4bc8ef2..1bee074 100644 --- a/advanced/esphome/nspanel_esphome_prebuilt.yaml +++ b/advanced/esphome/nspanel_esphome_prebuilt.yaml @@ -63,9 +63,11 @@ esphome: name: esphome.NSPanel_HA_Blueprint version: "${version}" on_boot: - - text_sensor.template.publish: - id: firmware_url - state: https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/main/nspanel_esphome_prebuilt.bin + - priority: 602.0 + then: + - text_sensor.template.publish: + id: firmware_url + state: https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/main/nspanel_esphome_prebuilt.bin # Sets up the improv via serial client for Wi-Fi provisioning improv_serial: diff --git a/docs/addon_climate.md b/docs/addon_climate.md index 2ab3876..da089ed 100644 --- a/docs/addon_climate.md +++ b/docs/addon_climate.md @@ -27,8 +27,6 @@ substitutions: wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft" - # Add-on configuration (if needed) ## Add-on climate heater_relay: "1" # Possible values: "1" or "2" @@ -96,8 +94,6 @@ substitutions: wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft" - # Add-on configuration (if needed) ## Add-on climate cooler_relay: "1" # Possible values: "1" or "2" @@ -140,8 +136,6 @@ substitutions: wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft" - # Add-on configuration (if needed) ## Add-on climate heater_relay: "1" # Possible values: "1" or "2" @@ -184,8 +178,6 @@ substitutions: wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft" - # Add-on configuration (if needed) ## Add-on climate heater_relay: "1" # Possible values: "1" or "2" diff --git a/docs/customization.md b/docs/customization.md index a1229db..a78ca50 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -59,8 +59,6 @@ substitutions: wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_us.tft" - # Add-on configuration (if needed) ## Add-on climate # heater_relay: "1" # Possible values: "1" or "2" diff --git a/docs/install.md b/docs/install.md index e51d128..1e56bc3 100644 --- a/docs/install.md +++ b/docs/install.md @@ -93,7 +93,7 @@ Follow these steps to add a new device in the ESPHome Dashboard: device_name: "YOUR_NSPANEL_NAME" wifi_ssid: !secret wifi_ssid wifi_password: !secret wifi_password - nextion_update_url: "http://homeassistant.local:8123/local/nspanel_eu.tft" + nextion_update_url: "http://homeassistant.local:8123/local/nspanel_eu.tft" # Optional for `esp-idf` framework # Add-on configuration (if needed) # heater_relay: "1" # Possible values: "1" or "2" @@ -125,7 +125,8 @@ Follow these steps to add a new device in the ESPHome Dashboard: ![Edit Settings](pics/ha_esphome_dashboard_new_device_06b.png) 10. For Wi-Fi credentials, use `!secret` for added security or input them directly. Learn about secrets in ESPHome: [Home Assistant Secrets in ESPHome](https://www.youtube.com/watch?v=eW4vKDeHh7Y). -11. Optionally, adjust `nextion_update_url` to the URL of a TFT file hosted on an HTTP or HTTPS server, ensuring that the file is accessible to the NSPanel. +11. (Optionally when using `esp-idf`) Adjust `nextion_update_url` to the URL of a TFT file hosted on an HTTP or HTTPS server, + ensuring that the file is accessible to the NSPanel. This URL will be used by ESPHome to download the TFT file to your panel. For more information on hosting the TFT file and setting up the URL, see the [Upload TFT](#upload-tft) section. diff --git a/docs/nspanel_blank.md b/docs/nspanel_blank.md index 9998bdb..3379f37 100644 --- a/docs/nspanel_blank.md +++ b/docs/nspanel_blank.md @@ -4,15 +4,24 @@ The NSPanel consist in a ESP32 board (the panel itself, controlling the relays, This Nextion display have an independent controller which also requires a firmware and its settings (the basic layout), and this is done by an `.tft` file. -When you get your panel from Sonoff, their `tft` file is installed in the Nextion display and using a called "Reparse mode", which makes a bit challenging to replace the `tft` file when using ESPHome and then, we highly recoment you using `nspanel_blank.tft`, which is just a fraction of the size of a regular `tft` and will make the first `tft` replacement much easier. You can find this file under the folder [`custom_configuration`](/custom_configuration). +When you get your panel from Sonoff, their `tft` file is installed in the Nextion display and using a called "Reparse mode", +which makes a bit challenging to replace the `tft` file when using ESPHome and then, we highly recoment you using `nspanel_blank.tft`, +which is just a fraction of the size of a regular `tft` and will make the first `tft` replacement much easier. +You can find this file under the folder [`custom_configuration`](/custom_configuration). -Once NSPanel's original `tft` is replaced, is much easier to install a new `tft` with ESPHome, so you can go directly to the final file (either `nspanel_eu.tft`, `nspanel_us.tft` or `nspanel_us_land.tft`). +Once NSPanel's original `tft` is replaced, is much easier to install a new `tft` with ESPHome, +so you can go directly to the final file (either `nspanel_eu.tft`, `nspanel_us.tft` or `nspanel_us_land.tft`). -For more datails on how to install the first `tft` file, specially if your panel still displaying the original Sonoff screen, please refeer to the Wiki where you will find the doc ["Common Issues TFT Upload"](/wiki/(EN)-Common-Issues-TFT-Upload). +For more datails on how to install the first `tft` file, specially if your panel still displaying the original Sonoff screen, +please refeer to the Wiki where you will find the doc ["Common Issues TFT Upload"](/wiki/(EN)-Common-Issues-TFT-Upload). ## How to install a different `tft` file? +### v4.2 or later and `esp-idf` framework +Just go to your devices's page (under **Settings** > **Devices and Services** > **ESPHome**), select your **Upload TFT display - Model** and then press **Upload TFT display**. + +### Older versions or `arduino` framework On your ESPHome settings, you have entered a url for `nextion_update_url`, in the substitutions, like this: ```yaml @@ -49,32 +58,42 @@ esp32: This url will indicate where your panel will look for the `tft` file when you click the "Upload TFT" button (under device's page) or call the service `esphome.xxxxx_upload_tft`. -The most popular way to switch between the `nspanel_blank.tft` and `nspanel_xx.tft` is replacing the URL on the ESPHome settings and flashing the device again, however, you can also do this calling the service `esphome.xxxxx_upload_tft_url` adding the URL of the alternative file as a parameter. It's up to you, as both ways will give the same result. +The most popular way to switch between the `nspanel_blank.tft` and `nspanel_xx.tft` is replacing the URL on the ESPHome settings and flashing the device again, +however, you can also do this calling the service `esphome.xxxxx_upload_tft_url` adding the URL of the alternative file as a parameter. +It's up to you, as both ways will give the same result. ## What to do after installing `nspanel_blank.tft`? ![image](https://github.com/Blackymas/NSPanel_HA_Blueprint/assets/94725493/3b0bb950-4857-4c22-a53a-062d09f315dc) -Once you have sucessfully installed any of the `tft` files from this project, the `nspanel_blank.tft` file shouldn't be necessary anymore and you should be able to always install the final `tft` file. +Once you have sucessfully installed any of the `tft` files from this project, +the `nspanel_blank.tft` file shouldn't be necessary anymore and you should be able to always install the final `tft` file. +### v4.2 or later and `esp-idf` framework +Just go to your devices's page (under **Settings** > **Devices and Services** > **ESPHome**), select your **Upload TFT display - Model** and then press **Upload TFT display**. + +### Older versions or `arduino` framework Make sure you have one of the following final TFT files in your local http server (typically Home Assistant on ***www*** folder): - [`nspanel_eu.tft`](../nspanel_eu.tft) - [`nspanel_us.tft`](../nspanel_us.tft) - [`nspanel_us_land.tft`](../nspanel_us_land.tft) -Now Flash your panel with `nextion_update_url` pointing to one of the final TFT files and press **Upload TFT** in the device's page (**Settings** > **Devices & Services** > **ESPHome**). +Now Flash your panel with `nextion_update_url` pointing to one of the final TFT files and +press **Upload TFT** in the device's page (**Settings** > **Devices & Services** > **ESPHome**). ## Additional Tips and Resources -We have an useful guide for [troubleshooting TFT transfer issues](tft_upload.md). Please take a look there first. +We have an useful guide for [troubleshooting TFT transfer issues](tft_upload.md). +Please take a look there first. After troubleshooting, if issues persist, consult the [Issues](/Blackymas/NSPanel_HA_Blueprint/issues) and feel free to create a new one asking for more personalized assistance. Please share as much info as possible, like: 1. Describing (or a picture of) what is in your screen -2. Are updating from a previous version of this same project, or coming from another NSPanel customization (which one?) or customizing for the first time a panel with original Sonoff settings? +2. Are updating from a previous version of this same project, +or coming from another NSPanel customization (which one?) +or customizing for the first time a panel with original Sonoff settings? 3. Please share the ESPHome logs from when your panel starts to the moment the upload fails. 4. Describe what you have already tried. ## Important note Remember, these steps are a guideline and might vary slightly based on your specific setup and previously installed system. - diff --git a/nspanel_esphome_prebuilt.bin b/nspanel_esphome_prebuilt.bin index ea67775..d0ece08 100644 Binary files a/nspanel_esphome_prebuilt.bin and b/nspanel_esphome_prebuilt.bin differ