diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 9a8acb4..ba48037 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -1047,12 +1047,6 @@ globals: restore_value: true initial_value: '65535' - ##### Versioning ##### - - id: version_blueprint - type: char[10] - restore_value: false - initial_value: '' - ##### Is uploading TFT ##### - id: is_uploading_tft type: bool @@ -1850,6 +1844,17 @@ text_sensor: } ##### Versioning ##### + - id: version_blueprint + name: Version Blueprint + platform: template + entity_category: diagnostic + icon: mdi:tag-text-outline + internal: false + update_interval: never + on_value: + - lambda: |- + check_versions->execute(); + - id: version_tft name: Version TFT platform: nextion @@ -1905,7 +1910,7 @@ script: - wait_until: condition: - lambda: |- - return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", id(version_blueprint))); + return (compare_versions("${version}", version_tft->state.c_str()) and compare_versions("${version}", version_blueprint->state.c_str())); timeout: 60s - lambda: |- if (!id(is_uploading_tft)) { @@ -1914,8 +1919,8 @@ script: ESP_LOGD("script.check_versions", " TFT: %s", version_tft->state.c_str()); if (not compare_versions("${version}", version_tft->state.c_str())) ESP_LOGE("script.check_versions", "TFT version mismatch!"); - ESP_LOGD("script.check_versions", " Blueprint: %s", id(version_blueprint)); - if (not compare_versions("${version}", id(version_blueprint))) + ESP_LOGD("script.check_versions", " Blueprint: %s", version_blueprint->state.c_str()); + if (not compare_versions("${version}", version_blueprint->state.c_str())) ESP_LOGE("script.check_versions", "Blueprint version mismatch!"); esphome::api::CustomAPIDevice ha_event; @@ -1925,7 +1930,7 @@ script: {"type", "version"}, {"tft", version_tft->state.c_str()}, {"esphome", "${version}"}, - {"blueprint", id(version_blueprint)} + {"blueprint", version_blueprint->state.c_str()} }); } @@ -1997,7 +2002,7 @@ script: if (id(is_uploading_tft)) global_settings->stop(); if (blueprint_status->state <= 99) goto_page->execute("boot"); // Blueprint version - copyStringToCharArray(id(version_blueprint), blueprint_version); + version_blueprint->publish_state(blueprint_version.c_str()); disp1->set_component_text("boot.bluep_version", blueprint_version.c_str()); check_versions->execute(); @@ -2826,6 +2831,7 @@ script: update_alarm_icon->stop(); update_climate_icon->stop(); update_tft_info->stop(); + watchdog->stop(); ###### Timers ###### - id: timer_reset_all # Global timer reset - Triggered with a touch on the screen @@ -3040,4 +3046,116 @@ script: condition: - lambda: return (!isnan(display_charset->state) and !isnan(display_mode->state) and !(version_tft->state.empty())); timeout: 10s + + - id: watchdog + mode: restart + then: + - lambda: |- + static const char *const TAG = "script.watchdog"; + ESP_LOGV(TAG, "Starting"); + if (id(is_uploading_tft)) { + ESP_LOGW(TAG, "TFT upload in progress"); + } else { + // report Wi-Fi status + bool wifi_connected = wifi_component->is_connected(); + if (wifi_connected) { + float rssi = wifi_rssi->state; + const char *rssi_status = "Unknown"; // Use const char* to avoid dynamic memory allocation + if (rssi > -50) rssi_status = "Excellent"; + else if (rssi > -60) rssi_status = "Good"; + else if (rssi > -70) rssi_status = "Fair"; + else if (rssi > -80) rssi_status = "Weak"; + else rssi_status = "Poor"; + if (rssi > -70) ESP_LOGI(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi); + else if (rssi > -80) ESP_LOGW(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi); + else ESP_LOGE(TAG, "Wi-Fi: %s (%.0f dBm)", rssi_status, rssi); + } + else { + ESP_LOGW(TAG, "Wi-Fi: DISCONNECTED"); + ESP_LOGI(TAG, "Retrying Wi-Fi connection"); + wifi_component->retry_connect(); + } + + // report API status + bool api_connected = api_server->is_connected(); + if (api_connected) { + ESP_LOGI(TAG, "API: Connected"); + } else { + ESP_LOGW(TAG, "API: DISCONNECTED"); + blueprint_status->publish_state(0); + 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_LOGI(TAG, "Fallback to page Home"); + disp1->goto_page("home"); + } + } + + if (!wifi_connected or !api_connected) blueprint_status->publish_state(0); + + // Report blueprint version + ESP_LOGI(TAG, "Blueprint:"); + if (blueprint_status->state > 99) { + ESP_LOGI(TAG, " Version: %s", version_blueprint->state.c_str()); + ESP_LOGI(TAG, " Init steps: %i (%0.1f%%)", int(blueprint_status->raw_state), blueprint_status->state); + } else { + ESP_LOGW(TAG, " Init steps: %i (%0.1f%%)", int(blueprint_status->raw_state), blueprint_status->state); + ESP_LOGW(TAG, " State: %s", (wifi_connected and api_connected) ? "Pending" : "DISCONNECTED"); + ESP_LOGI(TAG, "Requesting blueprint settings"); + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", + { + {"device_name", device_name->state.c_str()}, + {"type", "boot"}, + {"step", "timeout"} + }); + } + + // Report ESPHome + ESP_LOGI(TAG, "ESPHome:"); + ESP_LOGI(TAG, " Version: ${version}"); + // Report framework + #ifdef ARDUINO + ESP_LOGI(TAG, " Framework: Arduino"); + size_t total_heap_size = ESP.getHeapSize(); + size_t free_heap_size = ESP.getFreeHeap(); + #elif defined(USE_ESP_IDF) + ESP_LOGI(TAG, " Framework: ESP-IDF"); + size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT); + size_t free_heap_size = esp_get_free_heap_size(); + #endif + if (total_heap_size != 0) + ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size, + int(round(((float)free_heap_size / total_heap_size) * 100.0f))); + + // Report UART + ESP_LOGI(TAG, "UART:"); + ESP_LOGI(TAG, " Baud rate: %" PRIu32 " bps", tf_uart->get_baud_rate()); + ESP_LOGI(TAG, " Queue size: %d", tf_uart->available()); + + // Report Nextion status + nextion_init->publish_state(nextion_init->state and disp1->is_setup()); + ESP_LOGI(TAG, "Nextion:"); + ESP_LOGI(TAG, " Queue size: %d", disp1->queue_size()); + if (disp1->is_setup()) + ESP_LOGI(TAG, " Is setup: True"); + else { + ESP_LOGW(TAG, " Is setup: False"); + ESP_LOGW(TAG, " Is detected: %s", YESNO(disp1->is_detected())); + //exit_reparse->execute(); + } + if (nextion_init->state) { + ESP_LOGI(TAG, " Init: True"); + } else + ESP_LOGW(TAG, " Init: False"); + if (version_tft->state.empty()) + ESP_LOGW(TAG, " TFT: UNKNOWN"); + else + ESP_LOGI(TAG, " TFT: %s", version_tft->state.c_str()); + } + refresh_wifi_icon->execute(); + ESP_LOGV(TAG, "Finished"); ... diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index c39bb81..16575bf 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3366,7 +3366,15 @@ trigger_variables: else ("climate." ~ device_name ~ "_thermostat") }} - home_page_background_update: !input home_page_background_update + utilities_line_reference: + page01: + main: !input utilities_page01_main_line_reference + group01: !input utilities_page01_group01_line_reference + group02: !input utilities_page01_group02_line_reference + group03: !input utilities_page01_group03_line_reference + group04: !input utilities_page01_group04_line_reference + group05: !input utilities_page01_group05_line_reference + group06: !input utilities_page01_group06_line_reference variables: pages: @@ -3403,6 +3411,17 @@ variables: confirm: "confirm" utilities: "utilities" + home_page_background_update: !input home_page_background_update + + indoor_temperature_sensor_input: !input indoortemp + indoor_temperature_sensor: > + {{ + indoor_temperature_sensor_input + if indoor_temperature_sensor_input is string and indoor_temperature_sensor_input.split(".") | count == 2 + else nspaneltemp + }} + embedded_indoor_temperature: '{{ indoor_temperature_sensor == nspaneltemp }}' + # yamllint disable rule:indentation rule:comments-indentation trigger: ##### Trigger - General ################################################################################################################# @@ -3984,9 +4003,14 @@ trigger: ##### Trigger - Page utilities - State change ################################################################################################################# ##### Page utilities - Main line ##### - - platform: state - entity_id: !input utilities_page01_main_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.main %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page + for: + seconds: 1 ##### Page utilities - Home ##### - platform: state entity_id: !input utilities_page01_home_value1 @@ -4020,8 +4044,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group01_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group01 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -4036,8 +4063,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group02_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group02 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -4052,8 +4082,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group03_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group03 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -4068,8 +4101,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group04_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group04 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -4084,8 +4120,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group05_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group05 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -4100,8 +4139,11 @@ trigger: id: utilities_page for: seconds: 1 - - platform: state - entity_id: !input utilities_page01_group06_line_reference + - platform: template + value_template: > + {% set line_ref_id = utilities_line_reference.page01.group06 %} + {% set line_ref_state = (states(line_ref_id) | float(0)) if line_ref_id is string and line_ref_id.split(".") == 2 else 0 %} + {{ ((line_ref_state > 0) - (line_ref_state < 0)) }} id: utilities_page for: seconds: 1 @@ -7365,14 +7407,6 @@ action: ##### GENERAL ENTITYS ##### climate: !input climate embedded_climate: '{{ climate == thermostat_embedded }}' - indoor_temperature_sensor_input: !input indoortemp - indoor_temperature_sensor: > - {{ - indoor_temperature_sensor_input - if indoor_temperature_sensor_input is string and indoor_temperature_sensor_input.split(".") | count == 2 - else nspaneltemp - }} - embedded_indoor_temperature: '{{ indoor_temperature_sensor == nspaneltemp }}' domain_automation_button_action: !input domain_automation_button_action # yamllint disable rule:truthy rule:line-length rule:comments-indentation