Reorg repo

Simplifies things
This commit is contained in:
Edward Firmo
2024-02-16 16:55:12 +01:00
parent 67e358b526
commit dc4a5f43e1
209 changed files with 66 additions and 195 deletions

View File

@@ -0,0 +1,265 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ESPHome Add-on for Climate control - Shared - This will be called by heat/cool #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
### Local thermostat defaults ###
# https://esphome.io/components/climate/thermostat.html
heater_relay: "0" # Select 1 for "Relay 1", 2 for "Relay 2" or "0" to a dummy switch/disabled
cooler_relay: "0" # Select 1 for "Relay 1", 2 for "Relay 2" or "0" to a dummy switch/disabled
min_off_time: "300"
min_run_time: "300"
min_idle_time: "30"
# https://esphome.io/components/climate/index.html#base-climate-configuration
temp_min: "7"
temp_max: "35"
temp_step: "0.5"
target_low: "18"
target_high: "24"
cool_deadband: "0.5" # Temperature delta before engaging cooling
cool_overrun: "0.5" # Temperature delta before disengaging cooling
heat_deadband: "0.5" # Temperature delta before engaging heat
heat_overrun: "0.5" # Temperature delta before disengaging heat
##### DO NOT CHANGE THIS #####
addon_climate_cool: "false"
addon_climate_heat: "false"
addon_climate_dual: "false"
##############################
climate:
- platform: thermostat
name: Thermostat
id: thermostat_embedded
sensor: temp_nspanel
min_idle_time: ${min_idle_time}s
visual:
min_temperature: ${temp_min} ${temp_units}
max_temperature: ${temp_max} ${temp_units}
temperature_step:
target_temperature: 0.5 # This is hard coded for now as ESPHome isn't supporting a substitution here. In contact with support.
current_temperature: 0.1
idle_action:
- switch.turn_off: relay_${heater_relay}
default_preset: "Off"
on_boot_restore_from: memory
internal: false
on_state:
- lambda: |-
static const char *const TAG = "addon_climate_base.climate.thermostat_embedded.on_state";
ESP_LOGD(TAG, "Starting");
page_climate->execute();
page_home->execute();
ESP_LOGD(TAG, "Finished");
globals:
##### Is embedded thermostat visible on climate page? #####
- id: is_addon_climate_visible
type: bool
restore_value: false
initial_value: 'false'
##### Embeded climate friendly name #####
- id: addon_climate_friendly_name
type: std::string
restore_value: false
initial_value: '"${name} Thermostat"'
switch:
##### PHYSICAL SWITCH 0 (Dummy) - Used when relay is not set #####
- name: Relay 0 (dummy)
platform: template
id: relay_0
lambda: !lambda return false;
internal: true
optimistic: true
script:
- id: !extend change_climate_state
then:
- lambda: |-
if (embedded and !id(is_uploading_tft)) {
static const char *const TAG = "addon_climate_base.script.change_climate_state";
auto FahrenheitToCelsius = [](float fahrenheit) -> float {
return (fahrenheit - 32.0) * 5.0 / 9.0;
};
std::string temp_units = "${temp_units}";
bool temp_unit_fahrenheit = (temp_units == "°F" || temp_units == "F" || temp_units == "°f" || temp_units == "f");
auto call = thermostat_embedded->make_call();
float temperature;
id(is_addon_climate_visible) = true;
disp1->set_component_value("climate.embedded", 1);
if (key == "temperature") {
temperature = stof(value) / 10;
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
ESP_LOGD(TAG, "set_target_temperature(%f)", temperature);
call.set_target_temperature(temperature);
} else if (key == "target_temp_high") {
temperature = stof(value) / 10;
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
ESP_LOGD(TAG, "set_target_temperature_high(%f)", temperature);
call.set_target_temperature_high(temperature);
} else if (key == "target_temp_low") {
temperature = stof(value) / 10;
if (temp_unit_fahrenheit) temperature = FahrenheitToCelsius(temperature);
ESP_LOGD(TAG, "set_target_temperature_low(%f)", temperature);
call.set_target_temperature_low(temperature);
} else if (key == "hvac_mode") {
ESP_LOGD(TAG, "hvac_mode(%s)", value.c_str());
call.set_mode(value);
} else {
ESP_LOGE(TAG, "Invalid call:");
ESP_LOGE(TAG, " Embedded: %s", YESNO(embedded));
ESP_LOGE(TAG, " Key: %s", key.c_str());
ESP_LOGE(TAG, " Value: %s", value.c_str());
}
call.perform();
}
- id: !extend global_settings
then:
- lambda: |-
id(addon_climate_friendly_name) = embedded_climate_friendly_name;
- id: !extend open_entity_settings_page
then:
- lambda: |-
if (page == "climate" and entity == "embedded_climate")
id(addon_climate_friendly_name) = page_label;
- id: !extend page_climate
then:
- lambda: |-
id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate");
if (id(is_addon_climate_visible) and !id(is_uploading_tft)) {
static const char *const TAG = "addon_climate_base.script.page_climate";
auto CelsiusToFahrenheit = [](float celsius) -> float {
return (celsius * 9 / 5) + 32;
};
std::string temp_units = "${temp_units}";
bool temp_unit_fahrenheit = (temp_units == "°F" || temp_units == "F" || temp_units == "°f" || temp_units == "f");
ClimateTraits traits = thermostat_embedded->get_traits();
ESP_LOGV(TAG, "Climate page constructor:");
ESP_LOGV(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown")));
ESP_LOGV(TAG, " Temp. units: %s", temp_unit_fahrenheit ? "Fahrenheit" : "Celsius");
disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
float temp_step = traits.get_visual_target_temperature_step();
float temp_offset = traits.get_visual_min_temperature();
float temp_max = traits.get_visual_max_temperature();
float temp_target = thermostat_embedded->target_temperature;
float temp_target_high = thermostat_embedded->target_temperature_high;
float temp_target_low = thermostat_embedded->target_temperature_low;
float temp_current = thermostat_embedded->current_temperature;
if (temp_unit_fahrenheit) {
//temp_step = CelsiusToFahrenheit(temp_step);
temp_step = temp_step * 1.8;
temp_offset = CelsiusToFahrenheit(temp_offset);
temp_max = CelsiusToFahrenheit(temp_max);
temp_target = CelsiusToFahrenheit(temp_target);
temp_target_high = CelsiusToFahrenheit(temp_target_high);
temp_target_low = CelsiusToFahrenheit(temp_target_low);
temp_current = CelsiusToFahrenheit(temp_current);
}
float total_steps = (temp_max-temp_offset)/temp_step;
set_climate->execute
(
temp_current, // current_temp
0, // supported_features
((${addon_climate_dual}) ? -999 : temp_target), // target_temp
((${addon_climate_dual}) ? temp_target_high : -999), // target_temp_high
((${addon_climate_dual}) ? temp_target_low : -999), // target_temp_low
int(round(temp_step*10)), // temp_step
int(round(total_steps)), // total_steps
int(round(temp_offset*10)), // temp_offset
"", // climate_icon
true // embedded_climate
);
// Update target temp icon
update_climate_icon->execute("target_icon", int(thermostat_embedded->action), int(thermostat_embedded->mode));
// Update buttons bar
// Hide not supported hotspots
disp1->hide_component("button01");
if (${addon_climate_dual}) disp1->show_component("button02"); else disp1->hide_component("button02");
if (${addon_climate_heat} or ${addon_climate_dual}) disp1->show_component("button03"); else disp1->hide_component("button03"); //Heat
if (${addon_climate_cool} or ${addon_climate_dual}) disp1->show_component("button04"); else disp1->hide_component("button04"); //Cool
disp1->hide_component("button05");
disp1->hide_component("button06");
disp1->show_component("button07"); //Off
// Set buttons colors
disp1->set_component_font_color("button01", 6339);
disp1->set_component_font_color("button02", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? 65535 : ((${addon_climate_dual}) ? 48631 : 6339));
disp1->set_component_font_color("button03", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? 64164 : ((${addon_climate_heat} or ${addon_climate_dual}) ? 48631 : 6339));
disp1->set_component_font_color("button04", (thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? 1055 : ((${addon_climate_cool} or ${addon_climate_dual}) ? 48631 : 6339));
disp1->set_component_font_color("button05", 6339);
disp1->set_component_font_color("button06", 6339);
disp1->set_component_font_color("button07", (thermostat_embedded->mode==climate::CLIMATE_MODE_OFF) ? 10597 : 35921);
}
- id: !extend page_home
then:
- lambda: |-
// Update chips
if (id(is_embedded_thermostat) and !id(is_uploading_tft))
update_climate_icon->execute("home.icon_top_03", int(thermostat_embedded->action), int(thermostat_embedded->mode));
- id: !extend set_climate
then:
- lambda: |-
if (current_page->state == "climate" and !id(is_uploading_tft))
id(is_addon_climate_visible) = embedded_climate;
- id: !extend watchdog
then:
- lambda: |-
if (!id(is_uploading_tft)) {
static const char *const TAG = "addon_climate_base.script.watchdog";
bool addon_climate_cool = ${addon_climate_cool};
bool addon_climate_heat = ${addon_climate_heat};
bool addon_climate_dual = ${addon_climate_dual};
uint cooler_relay = ${cooler_relay};
uint heater_relay = ${heater_relay};
ESP_LOGI(TAG, "Add-on climate:");
if (addon_climate_cool) {
ESP_LOGI(TAG, " Cool: %s", addon_climate_cool ? "Enabled" : "Disabled");
if (cooler_relay == 1 or cooler_relay == 2)
ESP_LOGI(TAG, " Relay: %u", cooler_relay);
else
ESP_LOGE(TAG, " Relay: %u", cooler_relay);
}
if (addon_climate_heat) {
ESP_LOGI(TAG, " Heat: %s", addon_climate_heat ? "Enabled" : "Disabled");
if (heater_relay == 1 or heater_relay == 2)
ESP_LOGI(TAG, " Relay: %u", heater_relay);
else
ESP_LOGE(TAG, " Relay: %u", heater_relay);
}
if (addon_climate_dual) {
ESP_LOGI(TAG, " Dual: %s", addon_climate_dual ? "Enabled" : "Disabled");
if (cooler_relay == 1 or cooler_relay == 2)
ESP_LOGI(TAG, " Relay (cooler): %u", cooler_relay);
else
ESP_LOGE(TAG, " Relay (cooler): %u", cooler_relay);
if (heater_relay == 1 or heater_relay == 2)
ESP_LOGI(TAG, " Relay (heater): %u", heater_relay);
else
ESP_LOGE(TAG, " Relay (heater): %u", heater_relay);
if (cooler_relay == heater_relay)
ESP_LOGE(TAG, " Double relay assignment");
}
if ((addon_climate_cool && addon_climate_heat) ||
(addon_climate_cool && addon_climate_dual) ||
(addon_climate_heat && addon_climate_dual) ||
(!addon_climate_cool && !addon_climate_heat && !addon_climate_dual)) {
ESP_LOGE(TAG, "Invalid settings for add-on Climate");
}
}
...

View File

@@ -0,0 +1,36 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ESPHome Add-on for Climate control - Cool #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
### Local thermostat defaults ###
temp_min: "15"
##### DO NOT CHANGE THIS #####
addon_climate_cool: "true"
##############################
climate:
- id: !extend thermostat_embedded
min_cooling_off_time: ${min_off_time}s
min_cooling_run_time: ${min_run_time}s
cool_deadband: ${cool_deadband} ${temp_units}
cool_overrun: ${cool_overrun} ${temp_units}
cool_action:
- switch.turn_on: relay_${cooler_relay}
preset:
- name: "Off"
default_target_temperature_high: ${target_high} ${temp_units}
mode: "off"
- name: Home
default_target_temperature_high: ${target_high} ${temp_units}
mode: "cool"
packages:
climate_base_package: !include nspanel_esphome_addon_climate_base.yaml
...

View File

@@ -0,0 +1,41 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ESPHome Add-on for Climate control - Dual #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
##### DO NOT CHANGE THIS #####
addon_climate_dual: "true"
##############################
climate:
- id: !extend thermostat_embedded
min_cooling_off_time: ${min_off_time}s
min_heating_off_time: ${min_off_time}s
min_cooling_run_time: ${min_run_time}s
min_heating_run_time: ${min_run_time}s
cool_deadband: ${cool_deadband} ${temp_units}
cool_overrun: ${cool_overrun} ${temp_units}
heat_deadband: ${heat_deadband} ${temp_units}
heat_overrun: ${heat_overrun} ${temp_units}
cool_action:
- switch.turn_on: relay_${cooler_relay}
heat_action:
- switch.turn_on: relay_${heater_relay}
preset:
- name: "Off"
default_target_temperature_high: ${target_high} ${temp_units}
default_target_temperature_low: ${target_low} ${temp_units}
mode: "off"
- name: Home
default_target_temperature_high: ${target_high} ${temp_units}
default_target_temperature_low: ${target_low} ${temp_units}
mode: "heat_cool"
packages:
climate_base_package: !include nspanel_esphome_addon_climate_base.yaml
...

View File

@@ -0,0 +1,36 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ESPHome Add-on for Climate control - Heat #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add climate elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
### Local thermostat defaults ###
temp_max: "25"
##### DO NOT CHANGE THIS #####
addon_climate_heat: "true"
##############################
climate:
- id: !extend thermostat_embedded
min_heating_off_time: ${min_off_time}s
min_heating_run_time: ${min_run_time}s
heat_deadband: ${heat_deadband} ${temp_units}
heat_overrun: ${heat_overrun} ${temp_units}
heat_action:
- switch.turn_on: relay_${heater_relay}
preset:
- name: "Off"
default_target_temperature_low: ${target_low} ${temp_units}
mode: "off"
- name: Home
default_target_temperature_low: ${target_low} ${temp_units}
mode: "heat"
packages:
climate_base_package: !include nspanel_esphome_addon_climate_base.yaml
...

View File

@@ -0,0 +1,475 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### TFT Upload engine #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add advanced elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
################## Defaults ##################
# Just in case user forgets to set something #
nextion_update_url: "https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/main/nspanel_eu.tft"
nextion_update_base_url: "https://raw.githubusercontent.com/Blackymas/NSPanel_HA_Blueprint/"
##############################################
api:
on_client_connected:
- script.execute: report_settings
services:
##### SERVICE TO UPDATE THE TFT FILE from URL #####
##### It will use the default url if url is empty or "default"
- service: upload_tft_url
variables:
url: string
then:
- lambda: |-
static const char *const TAG = "addon_upload_tft.service.upload_tft_url";
ESP_LOGVV(TAG, "Starting...");
std::string clean_url = url;
// Convert to lowercase
std::transform(clean_url.begin(), clean_url.end(), clean_url.begin(),
[](unsigned char c){ return std::tolower(c); });
// Trim trailing spaces
auto endPos = clean_url.find_last_not_of(" \t");
if (std::string::npos != endPos) {
clean_url = clean_url.substr(0, endPos + 1);
}
if (clean_url.empty() or clean_url == "default") url = id(tft_url);
upload_tft->execute(url.c_str());
button:
##### UPDATE TFT DISPLAY #####
- id: tft_update
name: Update TFT display
platform: template
icon: mdi:file-sync
entity_category: config
on_press:
- lambda: |-
static const char *const TAG = "addon_upload_tft.button.tft_update.on_press";
ESP_LOGD(TAG, "Update TFT display button pressed");
upload_tft->execute(id(tft_url).c_str());
display:
- id: !extend disp1
tft_url: ${nextion_update_url}
exit_reparse_on_start: true
globals:
- id: baud_rate_original
type: uint
restore_value: false
initial_value: '115200'
- id: tft_is_valid
type: bool
restore_value: false
initial_value: 'false'
- id: tft_upload_attempt
type: uint
restore_value: false
initial_value: '0'
- id: tft_url
type: std::string
restore_value: false
initial_value: '"${nextion_update_url}"'
- id: tft_upload_result
type: esphome::nextion::Nextion::TFTUploadResult
restore_value: false
initial_value: 'esphome::nextion::Nextion::TFTUploadResult::UNKNOWN'
script:
- id: nextion_upload
mode: single
parameters:
baud_rate: uint32_t
then:
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.nextion_upload";
ESP_LOGD(TAG, "Waiting for empty UART and Nextion queues");
- wait_until:
condition:
- lambda: return (disp1->queue_size() < 1);
- lambda: return (tf_uart->available() < 1);
timeout: 10s
- delay: 2s
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.nextion_upload";
ESP_LOGD(TAG, "Starting TFT upload...");
id(tft_upload_result) = disp1->upload_tft(baud_rate, !disp1->is_setup());
ESP_LOGD(TAG, "TFT upload: %s", esphome::nextion::Nextion::tft_upload_result_to_string(id(tft_upload_result)));
- id: open_upload_dialog
mode: restart
then:
- lambda: |-
ESP_LOGD("addon_upload_tft.script.open_upload_dialog", "Showing upload dialog page");
disp1->goto_page("confirm");
page_id->update();
- wait_until:
condition:
- lambda: return (page_id->state == 26);
timeout: 2s
- lambda: |-
if (page_id->state == 26) {
disp1->hide_component("bclose");
disp1->hide_component("bt_accept");
disp1->hide_component("bt_clear");
}
disp1->set_component_text_printf("confirm.title", "Upload TFT\\r%s",
id(framework) == 1 ? "Arduino" : (id(framework) == 2 ? "ESP-IDF" : "Unknown"));
page_id->update();
- id: report_settings
mode: restart
then:
- delay: 15s
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.report_settings";
ESP_LOGI(TAG, "TFT URL: %s", id(tft_url).c_str());
ESP_LOGI(TAG, "Substitutions:");
ESP_LOGI(TAG, " nextion_update_url: ${nextion_update_url}");
ESP_LOGI(TAG, " nextion_update_base_url: ${nextion_update_base_url}");
ESP_LOGI(TAG, " TFT upload baud rate: %s bps", tft_upload_baud_rate->state.c_str());
- id: report_upload_progress
mode: restart
parameters:
message: string
then:
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.report_upload_progress";
ESP_LOGD(TAG, "%s", message.c_str());
if (id(tft_is_valid)) {
if (page_id->state != 26) {
open_upload_dialog->execute();
}
display_wrapped_text->execute("confirm.body", message.c_str(), 18);
disp1->set_backlight_brightness(1);
App.feed_wdt();
}
- id: set_tft_file
mode: restart
then:
- delay: 2s
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.set_tft_file";
std::string branch = "v${version}";
if (branch.find("beta") != std::string::npos) branch = "beta";
else if (branch.find("dev") != std::string::npos) branch = "dev";
std::string model = tft_file_model->state;
ESP_LOGD(TAG, "TFT URL set:");
ESP_LOGD(TAG, " Branch: %s", branch.c_str());
ESP_LOGD(TAG, " Model: %s", model.c_str());
if (id(is_uploading_tft))
ESP_LOGW(TAG, " TFT Upload in progress.");
else {
std::string url;
std::string file_name;
if (model == "NSPanel Blank") file_name = "nspanel_blank.tft";
else if (model == "NSPanel EU") file_name = "nspanel_eu.tft";
else if (model == "NSPanel US") file_name = "nspanel_us.tft";
else if (model == "NSPanel US Landscape") file_name = "nspanel_us_land.tft";
else if (model == "NSPanel EU (CJK languages)") file_name = "advanced/hmi/nspanel_CJK_eu.tft";
else if (model == "NSPanel US (CJK languages)") file_name = "advanced/hmi/nspanel_CJK_us.tft";
else if (model == "NSPanel US Landscape (CJK languages)") file_name = "advanced/hmi/nspanel_CJK_us_land.tft";
if (file_name.empty()) url = "${nextion_update_url}";
else {
std::string base_url("${nextion_update_base_url}");
url = base_url + branch + "/" + file_name;
// Remove trailing slashes or spaces
auto endPos = url.find_last_not_of(" /");
if (std::string::npos != endPos) {
url = url.substr(0, endPos + 1);
}
}
ESP_LOGD(TAG, " Full URL: %s", url.c_str());
id(tft_url) = url;
disp1->set_tft_url(url.c_str());
}
- id: upload_tft # I've changed this to use ESPHome commands to avoid the parallelism from lambdas
mode: single
parameters:
url: string
then:
# Make sure the screen is ON
- if:
condition:
- switch.is_off: screen_power
then:
- switch.turn_on: screen_power
- delay: 5s
# Wait for recent changes to TFT url
- script.wait: set_tft_file
# Then start the upload
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.upload_tft";
ESP_LOGD(TAG, "Starting...");
id(is_uploading_tft) = true;
nextion_status->execute();
// The upload process starts here
ESP_LOGD(TAG, "Starting the upload script");
ESP_LOGD(TAG, " Valid TFT: %s", YESNO(id(tft_is_valid)));
ESP_LOGD(TAG, " Current baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate());
ESP_LOGD(TAG, " Target upload baud rate: %s bps", tft_upload_baud_rate->state.c_str());
ESP_LOGD(TAG, " Upload URL: %s", url.c_str());
disp1->set_tft_url(url.c_str());
- lambda: if (id(tft_is_valid)) disp1->goto_page("home");
- delay: 2s
- script.execute: open_upload_dialog
- script.wait: open_upload_dialog
- lambda: page_id->update();
- wait_until:
condition:
- lambda: return (page_id->state == 26);
timeout: 2s
- script.execute:
id: report_upload_progress
message: "Set Nextion unavailable for blueprint calls"
- script.wait: report_upload_progress
- binary_sensor.template.publish:
id: nextion_init
state: false
- script.execute:
id: report_upload_progress
message: "Stopping other scripts"
- script.wait: report_upload_progress
- script.execute: stop_all
- script.wait: stop_all
- wait_until:
condition:
- lambda: return (!id(tft_is_valid));
timeout: 1s
### Attempt twice at the target baud rate
- script.execute:
id: upload_tft_sequence_attempt
baud_rate: !lambda return stoi(tft_upload_baud_rate->state);
- script.wait: upload_tft_sequence_attempt
### Attempt twice at the original baud rate
- if:
condition:
- lambda: return (stoi(tft_upload_baud_rate->state) != tf_uart->get_baud_rate());
then:
- script.execute:
id: upload_tft_sequence_attempt
baud_rate: 0
- script.wait: upload_tft_sequence_attempt
### Attempt twice at the Nextion's default baud rate (115200bps)
- if:
condition:
- lambda: return (stoi(tft_upload_baud_rate->state) != 115200 and tf_uart->get_baud_rate() != 115200);
then:
- script.execute:
id: upload_tft_sequence_attempt
baud_rate: 115200
- script.wait: upload_tft_sequence_attempt
### Restart Nextion and attempt twice again at default baud rate (115200bps)
- script.execute:
id: report_upload_progress
message: "Restarting Nextion display"
- script.wait: report_upload_progress
- wait_until:
condition:
- lambda: return (!id(tft_is_valid));
timeout: 3s
- switch.turn_off: screen_power
- delay: 2s
- switch.turn_on: screen_power
- delay: 5s
- script.execute:
id: upload_tft_sequence_attempt
baud_rate: 115200
- script.wait: upload_tft_sequence_attempt
### All tries failed ###
- script.execute:
id: report_upload_progress
message: "TFT upload failed"
- script.wait: report_upload_progress
- wait_until:
condition:
- lambda: return (!id(tft_is_valid));
timeout: 5s
- script.execute:
id: report_upload_progress
message: "Turn off Nextion and restart ESPHome"
- script.wait: report_upload_progress
- wait_until:
condition:
- lambda: return (!id(tft_is_valid));
timeout: 5s
- switch.turn_off: screen_power
- delay: 2s
# Restart ESPHome
- lambda: App.safe_reboot();
### This code should never run
- delay: 2s
- lambda: |-
static const char *const TAG = "addon_upload_tft.script.upload_tft";
ESP_LOGD(TAG, "Finishing...");
id(is_uploading_tft) = false;
screen_power->publish_state(true);
ESP_LOGE(TAG, "TFT upload finished unsuccessfully!");
- id: upload_tft_sequence_attempt
mode: single
parameters:
baud_rate: uint32_t
then:
- script.execute: nextion_status
- script.wait: nextion_status
- script.execute:
id: report_upload_progress
message: "Setting baud rate"
- script.wait: report_upload_progress
- script.execute:
id: set_baud_rate
baud_rate: !lambda return baud_rate;
definitive: false
- script.wait: set_baud_rate
- delay: 2s
- repeat:
count: 2
then:
# First attempt
- script.execute:
id: upload_tft_attempt
baud_rate: !lambda return baud_rate;
- script.wait: upload_tft_attempt
- delay: 5s
- id: upload_tft_attempt
mode: single
parameters:
baud_rate: uint32_t
then:
- logger.log: "Attempting to upload TFT"
- lambda: id(tft_upload_attempt)++;
- lambda: |-
char update_msg[128];
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps", id(tft_upload_attempt), tf_uart->get_baud_rate());
id(tft_upload_result) = esphome::nextion::Nextion::TFTUploadResult::UNKNOWN;
report_upload_progress->execute(update_msg);
- script.wait: report_upload_progress
- wait_until:
condition:
- lambda: return (!id(tft_is_valid));
timeout: 1s
- script.execute:
id: nextion_upload
baud_rate: !lambda return baud_rate;
- script.wait: nextion_upload
- lambda: |-
char update_msg[128];
sprintf(update_msg, "Attempt #%d at %" PRIu32 " bps returned: %s", id(tft_upload_attempt),
tf_uart->get_baud_rate(), esphome::nextion::Nextion::tft_upload_result_to_string(id(tft_upload_result)));
report_upload_progress->execute(update_msg);
- script.wait: report_upload_progress
- if:
condition:
- lambda: |-
return
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::UNKNOWN and
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::UPLOAD_IN_PROGRESS and
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_PREPARATION_FAILED and
id(tft_upload_result) != esphome::nextion::Nextion::TFTUploadResult::NEXTION_ERROR_INVALID_RESPONSE;
then:
- delay: 5s
- lambda: |-
ESP_LOGI("addon_upload_tft.script.upload_tft_attempt", "Restarting ESPHome");
App.safe_reboot();
- id: !extend watchdog
then:
- lambda: |-
if (!id(is_uploading_tft)) {
static const char *const TAG = "addon_upload_tft.script.watchdog";
ESP_LOGI(TAG, "Add-on Upload TFT:");
ESP_LOGI(TAG, " File model: %s", tft_file_model->state.c_str());
ESP_LOGI(TAG, " Valid TFT: %s", YESNO(id(tft_is_valid)));
}
select:
- id: tft_file_model
name: Update TFT display - Model
platform: template
options:
- "Use nextion_update_url"
- "NSPanel Blank"
- "NSPanel EU"
- "NSPanel US"
- "NSPanel US Landscape"
- "NSPanel EU (CJK languages)"
- "NSPanel US (CJK languages)"
- "NSPanel US Landscape (CJK languages)"
initial_option: "Use nextion_update_url"
optimistic: true
restore_value: true
internal: false
entity_category: config
disabled_by_default: false
icon: mdi:file-sync
on_value:
- script.execute: set_tft_file
- id: tft_upload_baud_rate
name: Update TFT display - Baud rate
platform: template
options:
- "2400"
- "4800"
- "9600"
- "19200"
- "31250"
- "38400"
- "57600"
- "115200"
- "230400"
- "250000"
- "256000"
- "512000"
- "921600"
initial_option: "921600"
optimistic: true
restore_value: true
internal: false
entity_category: config
disabled_by_default: true
icon: mdi:swap-horizontal
sensor:
- id: !extend display_mode
on_value:
then:
lambda: |-
static const char *const TAG = "addon_upload_tft.sensor.display_mode";
id(tft_is_valid) = (display_mode->state > 0 and display_mode->state < 4);
if (id(tft_is_valid))
ESP_LOGD(TAG, "Valid TFT: True");
else {
ESP_LOGW(TAG, "Display mode: %i", int(display_mode->state));
ESP_LOGW(TAG, "Valid TFT: False");
}
...

View File

@@ -0,0 +1,105 @@
#####################################################################################################
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
##### ESPHOME ADVANCED #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
##### ATTENTION: This will add advanced elements to the core system and requires the core part. #####
#####################################################################################################
---
substitutions:
##### Do not change this here. #####
##### Set your substitutions on #####
##### your base yaml file. #####
web_password: ${wifi_password}
#####################################
button:
##### EXIT REPARSE TFT DISPLAY #####
- name: Exit reparse
platform: template
icon: mdi:file-sync
id: tft_reparse_off
entity_category: config
internal: false
disabled_by_default: true
on_press:
- logger.log: "Button pressed: Exit reparse"
- script.execute: exit_reparse
captive_portal:
script:
- id: exit_reparse
mode: restart
then:
- logger.log: "Exit reparse"
- uart.write: "DRAKJHSUYDGBNCJHGJKSHBDN"
- uart.write: [0xFF, 0xFF, 0xFF]
- id: !extend stop_all
then:
- lambda: |-
exit_reparse->stop();
sensor:
##### Uptime Sensors #####
- name: Uptime seconds
id: uptime_sec
platform: uptime
internal: true
- name: API uptime
id: api_timestamp
platform: template
lambda: 'return id(time_provider).now().timestamp;'
internal: false
device_class: timestamp
entity_category: diagnostic
accuracy_decimals: 0
update_interval: never
- name: Device uptime
id: device_timestamp
platform: template
lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
internal: false
device_class: timestamp
entity_category: diagnostic
accuracy_decimals: 0
update_interval: never
text_sensor:
##### ESPhome version used to compile the app #####
- name: ESPhome Version
platform: version
disabled_by_default: false
internal: false
icon: mdi:tag-text-outline
- platform: wifi_info
ip_address:
name: IP
disabled_by_default: true
id: ip_address
ssid:
name: SSID
disabled_by_default: true
bssid:
name: BSSID
disabled_by_default: true
time:
- id: !extend time_provider
on_time_sync:
then:
- component.update: api_timestamp
- component.update: device_timestamp
web_server:
id: web_server_std
port: 80
auth:
username: admin
password: ${web_password}
...

File diff suppressed because it is too large Load Diff