5 Commits

Author SHA1 Message Date
Edward Firmo
e02ee95198 Rebuilt Upload TFT
Rebuilt again, now based on the ESPHome's Nextion component instead of local code.
Still not there yet, specially when Lovelace UI tft is installed, but hopefully this solves #1383 and solves #1491.
2023-12-30 01:59:51 +01:00
Edward Firmo
05ab9a8664 Reduces invalid_cooldown to 100ms
Solves #1479
2023-12-28 12:27:46 +01:00
Edward Firmo
33a0a34938 Reorg substitutions
Makes easier custom passwords.
2023-12-28 12:27:00 +01:00
Edward Firmo
00640bd360 Add queue_size to nextion_status 2023-12-28 12:14:20 +01:00
Edward Firmo
e361284c4c Add Nextion queue info to Watchdog logs 2023-12-28 11:32:44 +01:00
4 changed files with 555 additions and 1031 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,13 @@
##### 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: ${device_name} Exit reparse
@@ -89,4 +96,4 @@ web_server:
port: 80
auth:
username: admin
password: ${wifi_password}
password: ${web_password}

View File

@@ -6,15 +6,20 @@
#####################################################################################################
---
substitutions:
##### DON'T CHANGE THIS #####
version: "4.2dev.3"
##############################
## Change only in your ##
## local yaml substitutions ##
temp_units: "°C"
invalid_cooldown: "500ms"
#############################
invalid_cooldown: "100ms"
ota_password: ${wifi_password}
ap_password: ${wifi_password}
##### DON'T CHANGE THIS ######
version: "4.2dev.3"
##############################
##### External components #####
external_components:
- source: github://pr#5979 # Remove this when that PR is released (Hopefully v2024.1.0)
- source: github://pr#6029 # Remove this when that PR is released (Hopefully v2024.1.0)
components:
- nextion
@@ -32,59 +37,59 @@ esphome:
static const char *const TAG = "on_boot";
ESP_LOGD(TAG, "After boot check-up starting");
set_baud_rate->execute(stoi(baud_rate->state), true);
- wait_until:
condition:
- api.connected:
timeout: 60s
- wait_until:
condition:
- lambda: !lambda return disp1->is_detected();
timeout: 10s
- lambda: |-
if (!disp1->is_setup()) {
exit_reparse->execute();
}
- wait_until:
condition:
- lambda: !lambda return disp1->is_setup();
timeout: 10s
- lambda: |-
static const char *const TAG = "on_boot";
#- wait_until:
# condition:
# - api.connected:
# timeout: 60s
#- wait_until:
# condition:
# - lambda: !lambda return disp1->is_detected();
# timeout: 10s
#- lambda: |-
# if (!disp1->is_setup()) {
# exit_reparse->execute();
# }
#- wait_until:
# condition:
# - lambda: !lambda return disp1->is_setup();
# timeout: 10s
#- lambda: |-
# static const char *const TAG = "on_boot";
auto delay_seconds_ = [](int seconds) {
ESP_LOGD(TAG, "Wait %i seconds", seconds);
for (int i = 0; i < (seconds*4); i++) {
#ifdef ARDUINO
delay(250);
#elif defined(USE_ESP_IDF)
vTaskDelay(pdMS_TO_TICKS(250));
#endif
App.feed_wdt();
}
};
# auto delay_seconds_ = [](int seconds) {
# ESP_LOGD(TAG, "Wait %i seconds", seconds);
# for (int i = 0; i < (seconds*4); i++) {
# #ifdef ARDUINO
# delay(250);
# #elif defined(USE_ESP_IDF)
# vTaskDelay(pdMS_TO_TICKS(250));
# #endif
# App.feed_wdt();
# }
# };
nextion_status->execute();
if (not disp1->is_setup()) {
ESP_LOGE(TAG, "No response from Nextion display");
ESP_LOGD(TAG, "Turn off Nextion");
screen_power->turn_off();
delay_seconds_(2);
ESP_LOGD(TAG, "Turn on Nextion");
screen_power->turn_on();
delay_seconds_(5);
nextion_status->execute();
}
- wait_until:
condition:
- lambda: !lambda return disp1->is_setup();
timeout: 20s
- lambda: |-
static const char *const TAG = "on_boot";
nextion_status->execute();
if (not disp1->is_setup()) {
ESP_LOGE(TAG, "No response from Nextion display");
}
ESP_LOGD(TAG, "Finished");
# nextion_status->execute();
# if (not disp1->is_setup()) {
# ESP_LOGE(TAG, "No response from Nextion display");
# ESP_LOGD(TAG, "Turn off Nextion");
# screen_power->turn_off();
# delay_seconds_(2);
# ESP_LOGD(TAG, "Turn on Nextion");
# screen_power->turn_on();
# delay_seconds_(5);
# nextion_status->execute();
# }
#- wait_until:
# condition:
# - lambda: !lambda return disp1->is_setup();
# timeout: 20s
#- lambda: |-
# static const char *const TAG = "on_boot";
# nextion_status->execute();
# if (not disp1->is_setup()) {
# ESP_LOGE(TAG, "No response from Nextion display");
# }
# ESP_LOGD(TAG, "Finished");
on_shutdown:
then:
- switch.turn_off: screen_power
@@ -103,7 +108,7 @@ wifi:
password: ${wifi_password}
ap:
ssid: "${device_name}"
password: ${wifi_password}
password: ${ap_password}
on_connect:
then:
- script.execute: watchdog
@@ -114,7 +119,7 @@ wifi:
##### OTA PASSWORD #####
ota:
id: ota_std
password: ${wifi_password}
password: ${ota_password}
safe_mode: true
reboot_timeout: 3min
num_attempts: 3
@@ -155,6 +160,8 @@ time:
- seconds: 0
then:
- script.execute: refresh_datetime
- seconds: 30
then:
- script.execute: watchdog
on_time_sync:
@@ -726,18 +733,23 @@ display:
- id: disp1
platform: nextion
uart_id: tf_uart
start_up_page: 8
on_setup:
- script.execute: setup_sequence
on_page:
lambda: |-
static const char *const TAG = "display.disp1.on_page";
ESP_LOGD(TAG, "Nextion page changed");
ESP_LOGD(TAG, "New page: %s (%i)" , id(page_names)[x].c_str(), x);
page_id->update();
if (current_page->state != id(page_names)[x].c_str()) {
current_page->publish_state(id(page_names)[x].c_str());
page_changed->execute(id(page_names)[x].c_str());
if (id(is_uploading_tft)) {
ESP_LOGD(TAG, "Page changed ignored as a TFT upload is in progress");
} else if (x > id(page_names).size()) {
ESP_LOGW(TAG, "Invalid page index: %i", int(x));
} else {
ESP_LOGD(TAG, "Nextion page changed");
ESP_LOGD(TAG, "New page: %s (%i)" , id(page_names)[x].c_str(), x);
page_id->update();
if (current_page->state != id(page_names)[x].c_str()) {
current_page->publish_state(id(page_names)[x].c_str());
page_changed->execute(id(page_names)[x].c_str());
}
}
on_touch:
lambda: |-
@@ -1252,8 +1264,8 @@ select:
set_action:
- lambda: set_baud_rate->execute(stoi(x), true);
- name: ${device_name} Wake-up page
id: wakeup_page_name
- id: wakeup_page_name
name: ${device_name} Wake-up page
platform: template
options:
- buttonpage01
@@ -1295,9 +1307,9 @@ sensor:
resistor: 11.2kOhm
##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) #####
- name: ${device_name} Temperature
- id: temp_nspanel
name: ${device_name} Temperature
platform: ntc
id: temp_nspanel
sensor: resistance_sensor
unit_of_measurement: ${temp_units}
calibration:
@@ -1317,9 +1329,9 @@ sensor:
- lambda: display_embedded_temp->execute();
###### Display Brightness GET VALUE FROM NSPanel SLIDER #####
- name: ${device_name} brightness Slider
- id: brightslider
name: ${device_name} brightness Slider
platform: nextion
id: brightslider
variable_name: brightslider
internal: true
on_value:
@@ -1331,9 +1343,9 @@ sensor:
timer_reset_all->execute("settings");
###### Display DIM Brightness GET VALUE FROM NSPanel SLIDER #####
- name: ${device_name} dim brightness slider
- id: dimslider
name: ${device_name} dim brightness slider
platform: nextion
id: dimslider
variable_name: dimslider
internal: true
on_value:
@@ -1344,8 +1356,8 @@ sensor:
- lambda: |-
timer_reset_all->execute("settings");
- name: ${device_name} Page Id
id: page_id
- id: page_id
name: ${device_name} Page Id
platform: nextion
variable_name: dp
precision: 0
@@ -1354,14 +1366,20 @@ sensor:
on_value:
then:
- lambda: |-
if (current_page->state != id(page_names)[x].c_str()) {
static const char *const TAG = "sensor.page_id";
ESP_LOGD(TAG, "New page Id: %i", int(x));
if (id(is_uploading_tft)) {
ESP_LOGD(TAG, "Skipping actions as a TFT upload is in progress");
} else if (x > id(page_names).size()) {
ESP_LOGW(TAG, "Invalid page index: %i", int(x));
} else if (current_page->state != id(page_names)[x].c_str()) {
current_page->publish_state(id(page_names)[x].c_str());
page_changed->execute(id(page_names)[x].c_str());
}
##### Display mode (1 = EU, 2 = US, 3 = US Landscape)
- name: ${device_name} Display mode
id: display_mode
- id: display_mode
name: ${device_name} Display mode
platform: nextion
variable_name: display_mode
precision: 0
@@ -1793,14 +1811,16 @@ script:
- logger.log: "Exit reparse"
- uart.write: "DRAKJHSUYDGBNCJHGJKSHBDN"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "connect"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: [0xFF, 0xFF]
- uart.write: "connect"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: "bkcmd=3"
- uart.write: [0xFF, 0xFF, 0xFF]
- id: global_settings
@@ -1842,6 +1862,7 @@ script:
id(screensaver_display_time_color) = screensaver_time_color;
id(is_blueprint_updated) = true;
disp1->send_command_printf("api=1");
// Update home page
ESP_LOGV(TAG, "Update home page");
@@ -1943,6 +1964,7 @@ script:
ESP_LOGD(TAG, "Nextion status:");
ESP_LOGD(TAG, " Is detected: %s", disp1->is_detected() ? "True" : "False");
ESP_LOGD(TAG, " Is setup: %s", disp1->is_setup() ? "True" : "False");
ESP_LOGD(TAG, " Queue size: %d", disp1->queue_size());
- id: notification_clear
mode: restart
@@ -2994,22 +3016,51 @@ script:
else if (rssi > -80) ESP_LOGW(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status.c_str(), rssi);
else ESP_LOGE(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status.c_str(), rssi);
}
else
else {
ESP_LOGW(TAG, "Wi-Fi: DISCONNECTED");
if (id(wifi_timeout) > 0) {
id(wifi_timeout)--;
ESP_LOGD(TAG, "Retrying Wi-Fi connection");
wifi_component->retry_connect();
} else {
ESP_LOGE(TAG, "Restarting ESP due to a Wi-Fi timeout...");
App.safe_reboot();
}
}
// report API status
bool previous_blueprint_status = id(is_blueprint_updated);
bool api_connected = api_server->is_connected();
if (api_connected)
if (api_connected) {
ESP_LOGD(TAG, "API: Connected");
else
} else {
ESP_LOGW(TAG, "API: DISCONNECTED");
id(is_blueprint_updated) = false;
if (current_page->state != "blank" and
current_page->state != "boot" and
current_page->state != "home" and
current_page->state != "screensaver" and
current_page->state != "settings" and
current_page->state != "qrcode") {
ESP_LOGD(TAG, "Fallback to page Home");
disp1->goto_page("home");
}
}
// Report blueprint version
id(is_blueprint_updated) = id(is_blueprint_updated) and wifi_connected and api_connected and (not id(version_blueprint).empty());
if (id(is_blueprint_updated))
ESP_LOGD(TAG, "Blueprint: %s", id(version_blueprint).c_str());
else
else {
ESP_LOGW(TAG, "Blueprint: %s", (wifi_connected and api_connected) ? "Pending" : "DISCONNECTED");
ESP_LOGD(TAG, "Requesting blueprint settings");
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"type", "boot"},
{"step", "timeout"}
});
}
refresh_wifi_icon->execute();
@@ -3031,54 +3082,24 @@ script:
// Report Nextion status
nextion_init->publish_state(nextion_init->state and disp1->is_setup());
ESP_LOGD(TAG, "Nextion:");
ESP_LOGD(TAG, " Queue size: %d", disp1->queue_size());
if (disp1->is_setup())
ESP_LOGD(TAG, " Is setup: True");
else {
ESP_LOGW(TAG, " Is setup: False");
ESP_LOGW(TAG, " Is detected: %s", disp1->is_detected() ? "True" : "False");
//exit_reparse->execute();
}
if (nextion_init->state)
ESP_LOGD(TAG, " Init: True");
// Update api value on Nextion
if (id(is_blueprint_updated) != previous_blueprint_status) disp1->send_command_printf("api=%i", id(is_blueprint_updated) ? 1 : 0);
else
ESP_LOGW(TAG, " Init: False");
if (version_tft->state.empty())
ESP_LOGW(TAG, " TFT: UNKNOWN");
else
ESP_LOGD(TAG, " TFT: %s", version_tft->state.c_str());
// Update api value on Nextion
disp1->send_command_printf("api=%i", id(is_blueprint_updated) ? 1 : 0);
if (!wifi_connected) {
if (id(wifi_timeout) > 0) {
id(wifi_timeout)--;
ESP_LOGD(TAG, "Retrying Wi-Fi connection");
wifi_component->retry_connect();
} else {
ESP_LOGE(TAG, "Restarting ESP due to a Wi-Fi timeout...");
App.safe_reboot();
}
}
if (api_connected) {
if (not id(is_blueprint_updated)) {
ESP_LOGD(TAG, "Requesting blueprint settings");
auto ha_event = new esphome::api::CustomAPIDevice();
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
{
{"type", "boot"},
{"step", "timeout"}
});
}
} else {
id(is_blueprint_updated) = false;
if (current_page->state != "blank" and
current_page->state != "boot" and
current_page->state != "home" and
current_page->state != "screensaver" and
current_page->state != "settings" and
current_page->state != "qrcode") {
ESP_LOGD(TAG, "Fallback to page Home");
disp1->goto_page("home");
}
}
}
ESP_LOGV(TAG, "Finished");

View File

@@ -1,5 +1,24 @@
# ESPHome
### Logging
Avoid excessive log, or at least avoid excessive log at DEBUG level, but if you look around this project, many of the functionalities will log like this:
```yaml
sensor:
- id: my_sensor
...
on_change:
- lambda: |-
static const char *const TAG = "sensor.my_sensor";
ESP_LOGD(TAG, "New value: %f", x); // No need to log this, use only when needed
if (id(is_uploading_tft)) {
ESP_LOGD(TAG, "Skipping any action as a TFT upload is in progress"); // No need to log this, use only when needed
} else {
// Your code here
}
```
### Page opened
When a new page is opened, a script name `page_changed` (whith a parameter `page` containing a string with the page name) is called and that one will call a page specific script named `page_<page_name>`. In addition, pages with multiple pages (entitypageXX, buttonpageXX and weatherXX) will also call a generic page named `page_entitypage`, `page_buttonpage` or `page_weather` with a parameter `page_number` containing the number of the page called.
If you want to execute expecific code when a page is opened, you can extend the functionality of that specific page:
@@ -21,4 +40,49 @@ script:
- id: !extend page_buttonpage02
then:
# Code to run when buttonpage02 is opened
```
#### Managing conflicts with Upload TFT
The TFT upload is the most resource conmsuming task in this project and should have all the resources available, so when creating something, please take in account:
#### Stop your scripts before the upload starts
If you create a new script that should be stopped previous a Upload TFT starts, please add your script to the `stop_all` script like this:
```yaml
script:
- id: !extend stop_all
then:
- script.stop: my_new_script_id
```
#### Check for upload status before starting any action
There is a global `is_uploading_tft` which will be true when the upload TFT process starts, so you can use this in your code like this:
```yaml
sensor:
- id: my_sensor
...
on_change:
- if:
condition:
- lambda: !lambda return (!id(is_uploading_tft))
then:
# your code here
```
or:
```yaml
sensor:
- id: my_sensor
...
on_change:
- lambda: |-
static const char *const TAG = "sensor.my_sensor";
ESP_LOGD(TAG, "New value: %f", x); // No need to log this, use only when needed
if (id(is_uploading_tft)) {
ESP_LOGD(TAG, "Skipping any action as a TFT upload is in progress"); // No need to log this, use only when needed
} else {
// Your code here
}
```