From 98c6cf9849d1eb721929caf0e44a371f68a2b211 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 21 Jan 2024 23:13:38 +0100 Subject: [PATCH] Expose sensors to HA --- .../esphome/nspanel_esphome_advanced.yaml | 18 ++++--------- advanced/esphome/nspanel_esphome_core.yaml | 26 ++++++++----------- nspanel_esphome.yaml | 1 + 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/advanced/esphome/nspanel_esphome_advanced.yaml b/advanced/esphome/nspanel_esphome_advanced.yaml index 1b8786f..015f225 100644 --- a/advanced/esphome/nspanel_esphome_advanced.yaml +++ b/advanced/esphome/nspanel_esphome_advanced.yaml @@ -21,22 +21,12 @@ button: 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 - ##### UPDATE TFT BLANK DISPLAY ##### - - name: ${name} Update TFT display (blank) - platform: template - icon: mdi:file-sync - id: tft_update_blank - entity_category: config - on_press: - - lambda: |- - static const char *const TAG = "button.tft_update_blank"; - ESP_LOGD(TAG, "Button pressed: Update TFT display (blank)"); - upload_tft->execute("${nextion_blank_url}"); - captive_portal: sensor: @@ -70,7 +60,9 @@ text_sensor: ##### ESPhome version used to compile the app ##### - name: ${name} ESPhome Version platform: version - disabled_by_default: true + disabled_by_default: false + internal: false + icon: mdi:tag-text-outline - platform: wifi_info ip_address: diff --git a/advanced/esphome/nspanel_esphome_core.yaml b/advanced/esphome/nspanel_esphome_core.yaml index b0b79e2..eac70db 100644 --- a/advanced/esphome/nspanel_esphome_core.yaml +++ b/advanced/esphome/nspanel_esphome_core.yaml @@ -109,8 +109,7 @@ time: - seconds: 0 then: - script.execute: refresh_datetime - - minutes: /5 - seconds: 30 + - seconds: 30 then: - script.execute: watchdog @@ -1682,9 +1681,9 @@ text_sensor: entity_category: diagnostic icon: mdi:tag-text-outline internal: false + update_interval: never lambda: |- return {"unknown"}; - update_interval: never on_value: - lambda: |- static const char *const TAG = "text_sensor.version_blueprint"; @@ -1703,6 +1702,7 @@ text_sensor: entity_category: diagnostic icon: mdi:tag-text-outline internal: false + update_interval: never lambda: |- return {"${version}"}; on_value: @@ -1724,6 +1724,7 @@ text_sensor: entity_category: diagnostic icon: mdi:tag-text-outline internal: false + update_interval: never on_value: - lambda: |- static const char *const TAG = "text_sensor.version_tft"; @@ -1788,24 +1789,13 @@ script: ESP_LOGD(TAG, "Blueprint version: %s", version_blueprint->state.c_str()); if (not compareVersions("${version}", version_blueprint->state.c_str())) ESP_LOGE(TAG, "Blueprint version mismatch!"); - std::string framework = "unknown"; - #ifdef ARDUINO - framework = "arduino"; - #elif defined(USE_ESP_IDF) - framework = "esp-idf"; - #endif - ESP_LOGD(TAG, "Framework: %s", framework.c_str()); - ESP_LOGD(TAG, "Baud rate: %" PRIu32, id(tf_uart).get_baud_rate()); - auto ha_event = new esphome::api::CustomAPIDevice(); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", { {"type", "version"}, {"tft", version_tft->state.c_str()}, {"esphome", "${version}"}, - {"blueprint", version_blueprint->state.c_str()}, - {"framework", framework.c_str()}, - {"baud_rate", to_string(id(tf_uart).get_baud_rate())} + {"blueprint", version_blueprint->state.c_str()} }); - id: display_embedded_temp @@ -3208,8 +3198,14 @@ script: ESP_LOGI(TAG, " Version: ${version}"); // Report framework #ifdef ARDUINO + size_t total_heap_size = ESP.getHeapSize(); + size_t free_heap_size = ESP.getFreeHeap(); + ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size, int(round(((float)free_heap_size / total_heap_size) * 100.0f))); ESP_LOGI(TAG, " Framework: arduino"); #elif defined(USE_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(); + ESP_LOGI(TAG, " Heap: %zu bytes (%d%%)", free_heap_size, int(round(((float)free_heap_size / total_heap_size) * 100.0f))); ESP_LOGI(TAG, " Framework: esp-idf"); #endif diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 04f0712..1a10fd6 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -1,5 +1,6 @@ --- packages: core_package: !include advanced/esphome/nspanel_esphome_core.yaml + #advanced_package: !include advanced/esphome/nspanel_esphome_advanced.yaml upload_tft_package: !include advanced/esphome/nspanel_esphome_addon_upload_tft.yaml ...