Code clean-up
This commit is contained in:
@@ -71,17 +71,17 @@ script:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
// Update home.climate_entity variable
|
// Update home.climate_entity variable
|
||||||
id(entity_id) = (id(is_embedded_thermostat)) ? "embedded_climate" : "";
|
id(entity_id) = (id(is_embedded_thermostat)) ? "embedded_climate" : "";
|
||||||
id(disp1).set_component_value("climate.embedded", (id(is_embedded_thermostat)) ? 1 : 0);
|
disp1->set_component_value("climate.embedded", (id(is_embedded_thermostat)) ? 1 : 0);
|
||||||
// Update chips
|
// Update chips
|
||||||
if (id(is_embedded_thermostat))
|
if (id(is_embedded_thermostat))
|
||||||
id(update_climate_icon).execute("home.icon_top_03", int(id(thermostat_embedded).action), int(id(thermostat_embedded).mode));
|
id(update_climate_icon).execute("home.icon_top_03", int(thermostat_embedded->action), int(thermostat_embedded->mode));
|
||||||
|
|
||||||
- id: !extend addon_climate_service_call
|
- id: !extend addon_climate_service_call
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
id(is_addon_climate_visible) = true;
|
id(is_addon_climate_visible) = true;
|
||||||
id(disp1).set_component_value("climate.embedded", 1);
|
disp1->set_component_value("climate.embedded", 1);
|
||||||
auto call = id(thermostat_embedded).make_call();
|
auto call = thermostat_embedded->make_call();
|
||||||
if (key == "set_temperature")
|
if (key == "set_temperature")
|
||||||
call.set_target_temperature(stof(value) / 10);
|
call.set_target_temperature(stof(value) / 10);
|
||||||
else if (key == "hvac_mode")
|
else if (key == "hvac_mode")
|
||||||
@@ -96,44 +96,44 @@ script:
|
|||||||
- id: !extend addon_climate_update_page_climate
|
- id: !extend addon_climate_update_page_climate
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
if (id(current_page).state == "climate" and id(is_addon_climate_visible))
|
if (current_page->state == "climate" and id(is_addon_climate_visible))
|
||||||
{
|
{
|
||||||
id(disp1).set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
|
disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str());
|
||||||
float temp_step = ${temp_step};
|
float temp_step = ${temp_step};
|
||||||
float temp_offset = ${temp_min};
|
float temp_offset = ${temp_min};
|
||||||
float temp_max = ${temp_max};
|
float temp_max = ${temp_max};
|
||||||
float total_steps = (temp_max-temp_offset)/temp_step;
|
float total_steps = (temp_max-temp_offset)/temp_step;
|
||||||
id(set_climate)->execute
|
set_climate->execute
|
||||||
(
|
(
|
||||||
id(thermostat_embedded).current_temperature, // current_temp
|
thermostat_embedded->current_temperature, // current_temp
|
||||||
id(thermostat_embedded).target_temperature, // target_temp
|
thermostat_embedded->target_temperature, // target_temp
|
||||||
int(round(${temp_step}*10)), // temp_step
|
int(round(${temp_step}*10)), // temp_step
|
||||||
int(round(total_steps)), // total_steps //int(round((10*id(thermostat_embedded).target_temperature-temp_offset)/temp_step)), // slider_val
|
int(round(total_steps)), // total_steps //int(round((10*thermostat_embedded->target_temperature-temp_offset)/temp_step)), // slider_val
|
||||||
int(round(${temp_min}*10)), // temp_offset
|
int(round(${temp_min}*10)), // temp_offset
|
||||||
"", // climate_icon
|
"", // climate_icon
|
||||||
true // embedded_climate
|
true // embedded_climate
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update target temp icon
|
// Update target temp icon
|
||||||
id(update_climate_icon).execute("climate.target_icon", int(id(thermostat_embedded).action), int(id(thermostat_embedded).mode));
|
update_climate_icon->execute("climate.target_icon", int(thermostat_embedded->action), int(thermostat_embedded->mode));
|
||||||
|
|
||||||
// Update buttons bar
|
// Update buttons bar
|
||||||
// Hide not supported hotspots
|
// Hide not supported hotspots
|
||||||
id(disp1).hide_component("button01");
|
disp1->hide_component("button01");
|
||||||
id(disp1).hide_component("button02");
|
disp1->hide_component("button02");
|
||||||
if (${addon_climate_heat}) id(disp1).show_component("button03"); else id(disp1).hide_component("button03"); //Heat
|
if (${addon_climate_heat}) disp1->show_component("button03"); else disp1->hide_component("button03"); //Heat
|
||||||
if (${addon_climate_cool}) id(disp1).show_component("button04"); else id(disp1).hide_component("button04"); //Cool
|
if (${addon_climate_cool}) disp1->show_component("button04"); else disp1->hide_component("button04"); //Cool
|
||||||
id(disp1).hide_component("button05");
|
disp1->hide_component("button05");
|
||||||
id(disp1).hide_component("button06");
|
disp1->hide_component("button06");
|
||||||
id(disp1).show_component("button07"); //Off
|
disp1->show_component("button07"); //Off
|
||||||
// Set buttons colors
|
// Set buttons colors
|
||||||
id(disp1).set_component_font_color("climate.button01_icon", 6339);
|
disp1->set_component_font_color("climate.button01_icon", 6339);
|
||||||
id(disp1).set_component_font_color("climate.button02_icon", 6339);
|
disp1->set_component_font_color("climate.button02_icon", 6339);
|
||||||
id(disp1).set_component_font_color("climate.button03_icon", (id(thermostat_embedded).mode==climate::CLIMATE_MODE_HEAT) ? 64164 : ((${addon_climate_heat}) ? 48631 : 6339));
|
disp1->set_component_font_color("climate.button03_icon", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? 64164 : ((${addon_climate_heat}) ? 48631 : 6339));
|
||||||
id(disp1).set_component_font_color("climate.button04_icon", (id(thermostat_embedded).mode==climate::CLIMATE_MODE_COOL) ? 1055 : ((${addon_climate_cool}) ? 48631 : 6339));
|
disp1->set_component_font_color("climate.button04_icon", (thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? 1055 : ((${addon_climate_cool}) ? 48631 : 6339));
|
||||||
id(disp1).set_component_font_color("climate.button05_icon", 6339);
|
disp1->set_component_font_color("climate.button05_icon", 6339);
|
||||||
id(disp1).set_component_font_color("climate.button06_icon", 6339);
|
disp1->set_component_font_color("climate.button06_icon", 6339);
|
||||||
id(disp1).set_component_font_color("climate.button07_icon", (id(thermostat_embedded).mode==climate::CLIMATE_MODE_OFF) ? 10597 : 35921);
|
disp1->set_component_font_color("climate.button07_icon", (thermostat_embedded->mode==climate::CLIMATE_MODE_OFF) ? 10597 : 35921);
|
||||||
}
|
}
|
||||||
|
|
||||||
- id: !extend addon_climate_set_climate_friendly_name
|
- id: !extend addon_climate_set_climate_friendly_name
|
||||||
|
|||||||
@@ -18,27 +18,10 @@ substitutions:
|
|||||||
#############################
|
#############################
|
||||||
|
|
||||||
external_components:
|
external_components:
|
||||||
# - source: github://pr#3256 # adds esp-idf support to http_request
|
- source: github://pr#5667 # Remove this when that pr is merged
|
||||||
# components:
|
|
||||||
# - http_request
|
|
||||||
- source: github://pr#5667 #5484 #5660 # adds exit reparse to Nextion library
|
|
||||||
components:
|
components:
|
||||||
- nextion
|
- nextion
|
||||||
refresh: 300s
|
refresh: 300s
|
||||||
# - source:
|
|
||||||
# type: git
|
|
||||||
# url: https://github.com/edwardtfn/esphome
|
|
||||||
# ref: nextion-esp-idf
|
|
||||||
# components:
|
|
||||||
# - nextion
|
|
||||||
# refresh: 1s
|
|
||||||
|
|
||||||
##### HTTP REQUEST #####
|
|
||||||
# Enables http client #
|
|
||||||
# for upload_tft. #
|
|
||||||
########################
|
|
||||||
#http_request:
|
|
||||||
# id: httpclient
|
|
||||||
|
|
||||||
button:
|
button:
|
||||||
##### UPDATE TFT DISPLAY #####
|
##### UPDATE TFT DISPLAY #####
|
||||||
@@ -49,11 +32,8 @@ button:
|
|||||||
entity_category: config
|
entity_category: config
|
||||||
on_press:
|
on_press:
|
||||||
- logger.log: "Button pressed: Update TFT display"
|
- logger.log: "Button pressed: Update TFT display"
|
||||||
- binary_sensor.template.publish:
|
- lambda: |-
|
||||||
id: nextion_init
|
upload_tft->execute("${nextion_update_url}");
|
||||||
state: false
|
|
||||||
- delay: 16ms
|
|
||||||
- lambda: id(upload_tft).execute("${nextion_update_url}");
|
|
||||||
|
|
||||||
api:
|
api:
|
||||||
services:
|
services:
|
||||||
@@ -61,10 +41,8 @@ api:
|
|||||||
- service: upload_tft
|
- service: upload_tft
|
||||||
then:
|
then:
|
||||||
- logger.log: "Service: upload_tft"
|
- logger.log: "Service: upload_tft"
|
||||||
- binary_sensor.template.publish:
|
- lambda: |-
|
||||||
id: nextion_init
|
upload_tft->execute("${nextion_update_url}");
|
||||||
state: false
|
|
||||||
- lambda: 'id(upload_tft).execute("${nextion_update_url}");'
|
|
||||||
|
|
||||||
##### SERVICE TO UPDATE THE TFT FILE from URL #####
|
##### SERVICE TO UPDATE THE TFT FILE from URL #####
|
||||||
- service: upload_tft_url
|
- service: upload_tft_url
|
||||||
@@ -72,10 +50,8 @@ api:
|
|||||||
url: string
|
url: string
|
||||||
then:
|
then:
|
||||||
- logger.log: "Service: upload_tft_url"
|
- logger.log: "Service: upload_tft_url"
|
||||||
- binary_sensor.template.publish:
|
- lambda: |-
|
||||||
id: nextion_init
|
upload_tft->execute(url.c_str());
|
||||||
state: false
|
|
||||||
- lambda: 'id(upload_tft).execute(url.c_str());'
|
|
||||||
|
|
||||||
display:
|
display:
|
||||||
- id: !extend disp1
|
- id: !extend disp1
|
||||||
@@ -90,51 +66,51 @@ script:
|
|||||||
- lambda: |-
|
- lambda: |-
|
||||||
static const char *const TAG = "script.upload_tft";
|
static const char *const TAG = "script.upload_tft";
|
||||||
ESP_LOGVV(TAG, "Starting...");
|
ESP_LOGVV(TAG, "Starting...");
|
||||||
|
|
||||||
|
nextion_init->state = false;
|
||||||
|
|
||||||
|
auto delay_seconds_ = [](int seconds) {
|
||||||
|
ESP_LOGVV(TAG, "Wait %i seconds", seconds);
|
||||||
|
for (int i = 0; i < (seconds*4); i++) {
|
||||||
|
#ifdef ARDUINO
|
||||||
|
delay(250);
|
||||||
|
#elif defined(ESP_PLATFORM)
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(250));
|
||||||
|
#endif
|
||||||
|
App.feed_wdt();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Setting TFT url: %s", url.c_str());
|
ESP_LOGV(TAG, "Setting TFT url: %s", url.c_str());
|
||||||
id(disp1)->set_tft_url(url.c_str());
|
disp1->set_tft_url(url.c_str());
|
||||||
unsigned int upload_tries = 0;
|
unsigned int upload_tries = 0;
|
||||||
while (upload_tries < 5) {
|
while (upload_tries < 5) {
|
||||||
upload_tries++;
|
upload_tries++;
|
||||||
ESP_LOGD(TAG, "Try #%i", upload_tries);
|
ESP_LOGD(TAG, "Try #%i", upload_tries);
|
||||||
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
ESP_LOGD(TAG, "Setting Nextion protocol reparse mode to passive");
|
||||||
id(disp1).set_protocol_reparse_mode(false);
|
exit_reparse->execute();
|
||||||
|
delay_seconds_(2);
|
||||||
ESP_LOGV(TAG, "Calling upload from Nextion component");
|
ESP_LOGV(TAG, "Calling upload from Nextion component");
|
||||||
if (id(disp1)->upload_tft()) id(restart_nspanel).press();
|
if (disp1->upload_tft()) id(restart_nspanel).press();
|
||||||
ESP_LOGD(TAG, "Turn off Nextion");
|
ESP_LOGD(TAG, "Turn off Nextion");
|
||||||
id(screen_power).turn_off();
|
screen_power->turn_off();
|
||||||
#ifdef ARDUINO
|
delay_seconds_(3);
|
||||||
delay(1500);
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
|
||||||
#endif
|
|
||||||
ESP_LOGD(TAG, "Turn on Nextion");
|
ESP_LOGD(TAG, "Turn on Nextion");
|
||||||
id(screen_power).turn_on();
|
screen_power->turn_on();
|
||||||
#ifdef ARDUINO
|
delay_seconds_(2);
|
||||||
delay(1500);
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
ESP_LOGE(TAG, "TFT upload failed.");
|
ESP_LOGE(TAG, "TFT upload failed.");
|
||||||
ESP_LOGD(TAG, "Turn off Nextion");
|
ESP_LOGD(TAG, "Turn off Nextion");
|
||||||
id(screen_power).turn_off();
|
screen_power->turn_off();
|
||||||
#ifdef ARDUINO
|
delay_seconds_(2);
|
||||||
delay(1500);
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
|
||||||
#endif
|
|
||||||
ESP_LOGD(TAG, "Turn on Nextion");
|
ESP_LOGD(TAG, "Turn on Nextion");
|
||||||
id(screen_power).turn_on();
|
screen_power->turn_on();
|
||||||
ESP_LOGD(TAG, "Restarting esphome");
|
ESP_LOGD(TAG, "Restarting esphome");
|
||||||
#ifdef ARDUINO
|
delay_seconds_(1);
|
||||||
delay(1500);
|
restart_nspanel->press();
|
||||||
#elif defined(ESP_PLATFORM)
|
nextion_init->state = true;
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
|
||||||
#endif
|
|
||||||
id(restart_nspanel).press();
|
|
||||||
ESP_LOGV(TAG, "Finished!");
|
ESP_LOGV(TAG, "Finished!");
|
||||||
|
|
||||||
|
|
||||||
- id: upload_tft_legacy # Not in use - To be removed when Nextion component is updated
|
- id: upload_tft_legacy # Not in use - To be removed when Nextion component is updated
|
||||||
mode: single
|
mode: single
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
@@ -36,12 +36,7 @@ button:
|
|||||||
entity_category: config
|
entity_category: config
|
||||||
on_press:
|
on_press:
|
||||||
- logger.log: "Button pressed: Exit reparse"
|
- logger.log: "Button pressed: Exit reparse"
|
||||||
- uart.write:
|
- script.execute: exit_reparse
|
||||||
id: tf_uart
|
|
||||||
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
|
|
||||||
- uart.write:
|
|
||||||
id: tf_uart
|
|
||||||
data: [0xFF, 0xFF, 0xFF]
|
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
##### Uptime Sensors #####
|
##### Uptime Sensors #####
|
||||||
|
|||||||
@@ -34,13 +34,7 @@ esphome:
|
|||||||
condition:
|
condition:
|
||||||
- lambda: !lambda return id(disp1).is_setup();
|
- lambda: !lambda return id(disp1).is_setup();
|
||||||
timeout: 20s
|
timeout: 20s
|
||||||
- logger.log: "Exit reparse"
|
- script.execute: exit_reparse
|
||||||
- uart.write:
|
|
||||||
id: tf_uart
|
|
||||||
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
|
|
||||||
- uart.write:
|
|
||||||
id: tf_uart
|
|
||||||
data: [0xFF, 0xFF, 0xFF]
|
|
||||||
- wait_until:
|
- wait_until:
|
||||||
condition:
|
condition:
|
||||||
- lambda: !lambda return id(disp1).is_setup();
|
- lambda: !lambda return id(disp1).is_setup();
|
||||||
@@ -2418,6 +2412,17 @@ script:
|
|||||||
}
|
}
|
||||||
id(disp1).set_component_text_printf("page_index", "%s", indicator.c_str());
|
id(disp1).set_component_text_printf("page_index", "%s", indicator.c_str());
|
||||||
|
|
||||||
|
- id: exit_reparse
|
||||||
|
mode: restart
|
||||||
|
then:
|
||||||
|
- logger.log: "Exit reparse"
|
||||||
|
- uart.write:
|
||||||
|
id: tf_uart
|
||||||
|
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
|
||||||
|
- uart.write:
|
||||||
|
id: tf_uart
|
||||||
|
data: [0xFF, 0xFF, 0xFF]
|
||||||
|
|
||||||
##### ADD-ONS ############################################################
|
##### ADD-ONS ############################################################
|
||||||
##### Add-on - Climate #####
|
##### Add-on - Climate #####
|
||||||
- id: addon_climate_service_call
|
- id: addon_climate_service_call
|
||||||
|
|||||||
Reference in New Issue
Block a user