From 55ea00b50a88fe81beb1abfcf51fd6d866b51cc8 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:04:47 +0100 Subject: [PATCH] Add nextion_components.h --- .../nspanel_ha_blueprint/nextion_components.h | 51 ++++ components/nspanel_ha_blueprint/pages.h | 68 ++++++ .../nspanel_esphome_addon_climate_base.yaml | 2 +- esphome/nspanel_esphome_core.yaml | 230 +++++++++--------- nspanel_blueprint.yaml | 29 ++- 5 files changed, 254 insertions(+), 126 deletions(-) create mode 100644 components/nspanel_ha_blueprint/nextion_components.h create mode 100644 components/nspanel_ha_blueprint/pages.h diff --git a/components/nspanel_ha_blueprint/nextion_components.h b/components/nspanel_ha_blueprint/nextion_components.h new file mode 100644 index 0000000..17733d9 --- /dev/null +++ b/components/nspanel_ha_blueprint/nextion_components.h @@ -0,0 +1,51 @@ +// nextion_components.h +#pragma once + +#include + +namespace nspanel_ha_blueprint { + + struct PageComponent { + std::string page; + std::string component_id; + bool is_current_page; + }; + + /** + * Extracts the page name and component ID from a given input string. + * Handles a special case where "alarm_control_panel" should be shortened to "alarm". + * + * @param input The input string containing either the combined page and component ID or just the component ID. + * @param defaultPage The default page name to use if the input string does not specify a page. + * @return A PageComponent struct containing the extracted or default page name, the component ID, and a flag indicating if it's the current page. + */ + PageComponent extractPageAndComponent(const std::string& input, const std::string& defaultPage) { + size_t dotPos = input.find("."); + PageComponent result; + + if (dotPos != std::string::npos) { + // Extract page and component_id from the input string + result.page = input.substr(0, dotPos); + result.component_id = input.substr(dotPos + 1); + result.is_current_page = false; // Since there's a dot, it's assumed not to be the current page + + // Check for the special case of "alarm_control_panel" + if (result.page == "alarm_control_panel") { + result.page = "alarm"; + } + } else { + // No dot found, the entire input is considered as component_id + result.page = defaultPage; + result.component_id = input; + result.is_current_page = true; // No specific page mentioned, so it's the current page + } + + // Check if the resolved page matches the defaultPage indicating it's the current page + if (result.page == defaultPage) { + result.is_current_page = true; + } + + return result; + } + +} // namespace nspanel_ha_blueprint diff --git a/components/nspanel_ha_blueprint/pages.h b/components/nspanel_ha_blueprint/pages.h new file mode 100644 index 0000000..8d58e50 --- /dev/null +++ b/components/nspanel_ha_blueprint/pages.h @@ -0,0 +1,68 @@ +// pages.h +#pragma once + +#include +#include +#include +#include // For std::pair + +namespace nspanel_ha_blueprint { + + /** + * @file pages.h + * Defines constants and functions related to page names for "NSPanel HA Blueprint" project.. + */ + + // Constants + /** + * A compile-time constant array containing the names of pages. + * These names correspond to various pages of the Nextion TFT file in use, + * such as settings, home, weather information, and more. + */ + constexpr std::array page_names = { + "home", + "weather01", + "weather02", + "weather03", + "weather04", + "weather05", + "climate", + "settings", + "boot", + "screensaver", + "light", + "cover", + "buttonpage01", + "buttonpage02", + "buttonpage03", + "buttonpage04", + "notification", + "qrcode", + "entitypage01", + "entitypage02", + "entitypage03", + "entitypage04", + "fan", + "alarm", + "keyb_num", + "media_player", + "confirm" + }; + + /** + * Retrieves the index of a given page name within the page_names array. + * + * @param page_name The name of the page to find. + * @return The index of the page_name in the page_names array. If the page_name + * is not found, returns UINT8_MAX as an indicator that no matching page was found. + */ + inline uint8_t get_page_id(const std::string& page_name) { + for (uint8_t i = 0; i < page_names.size(); ++i) { + if (strcmp(page_names[i], page_name.c_str()) == 0) { + return i; // Return the index if found + } + } + return UINT8_MAX; // Return UINT8_MAX if not found + } + +} // namespace nspanel_ha_blueprint \ No newline at end of file diff --git a/esphome/nspanel_esphome_addon_climate_base.yaml b/esphome/nspanel_esphome_addon_climate_base.yaml index 42d87b9..1613c9e 100644 --- a/esphome/nspanel_esphome_addon_climate_base.yaml +++ b/esphome/nspanel_esphome_addon_climate_base.yaml @@ -202,7 +202,7 @@ script: - 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)); + update_climate_icon->execute("home.chip_climate", int(thermostat_embedded->action), int(thermostat_embedded->mode)); - id: !extend set_climate then: diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 459866d..ae9fcf6 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -243,11 +243,11 @@ api: disp1->set_component_text_printf(btnbri.c_str(), "%s", bri.c_str()); else disp1->set_component_text_printf(btnbri.c_str(), " "); - disp1->show_component(btnpic.c_str()); - disp1->show_component(btnicon.c_str()); - disp1->show_component(btntext.c_str()); - disp1->show_component(btnbri.c_str()); - disp1->show_component(id.c_str()); + set_component_visibility->execute(btnpic.c_str(), true); + set_component_visibility->execute(btnicon.c_str(), true); + set_component_visibility->execute(btntext.c_str(), true); + set_component_visibility->execute(btnbri.c_str(), true); + set_component_visibility->execute(id.c_str(), true); } else { ESP_LOGW("service.set_button", "Skipping button `%s.%s` update.", page.c_str(), id.c_str()); } @@ -329,7 +329,7 @@ api: then: - lambda: |- if (!id(is_uploading_tft)) - disp1->hide_component(id.c_str()); + set_component_visibility->execute(id.c_str(), false); # Component Show Service # Enables dynamic interface changes by making specified components visible on the display again. @@ -352,7 +352,7 @@ api: then: - lambda: |- if (!id(is_uploading_tft)) - disp1->show_component(id.c_str()); + set_component_visibility->execute(id.c_str(), true); # Component Text Service # Updates text content for a specified component on the display, ideal for dynamic updates. @@ -465,24 +465,18 @@ api: visible: bool then: - lambda: |- + static const char *const TAG = "service.icon"; + ESP_LOGI(TAG, "id: %s", id.c_str()); + ESP_LOGI(TAG, "id_empty: %s", YESNO(id.empty())); + ESP_LOGI(TAG, "icon: %s", icon.c_str()); + ESP_LOGI(TAG, "icon_color: %i", icon_color.size()); + ESP_LOGI(TAG, "visible: %s", YESNO(visible)); + ESP_LOGI(TAG, "page: %s", current_page->state.c_str()); if (!id(is_uploading_tft) and !(id.empty())) { - if (!(icon.empty())) disp1->set_component_text_printf("%s_icon", id.c_str(), icon.c_str()); + if (!(icon.empty())) disp1->set_component_text_printf(id.c_str(), "%s", icon.c_str()); if (icon_color.size() == 3) - disp1->set_component_font_color((id + "_icon").c_str(), esphome::display::ColorUtil::color_to_565(esphome::Color(icon_color[0], icon_color[1], icon_color[2]))); - bool IsCurrentPage = true; - size_t dotPos = id.find("."); - if (dotPos != std::string::npos) { - std::string left_side = id.substr(0, dotPos); - if (left_side == "alarm_control_panel") left_side = "alarm"; - if (left_side != current_page->state) IsCurrentPage = false; - } - if (IsCurrentPage) { - if (visible) { - disp1->show_component(id.c_str()); - } else { - disp1->hide_component(id.c_str()); - } - } + disp1->set_component_font_color(id.c_str(), esphome::display::ColorUtil::color_to_565(esphome::Color(icon_color[0], icon_color[1], icon_color[2]))); + set_component_visibility->execute(id.c_str(), visible); } # Init Global Service @@ -644,21 +638,24 @@ api: // Chips icon size ESP_LOGV(TAG, "Chips size"); - for (int i = 1; i <= 10; ++i) { - disp1->send_command_printf("home.icon_top_%02d.font=%" PRIu32, i, chip_font); + disp1->send_command_printf("home.chip_relay1.font=%" PRIu8, chip_font); + disp1->send_command_printf("home.chip_relay2.font=%" PRIu8, chip_font); + disp1->send_command_printf("home.chip_climate.font=%" PRIu8, chip_font); + for (int i = 1; i <= 7; ++i) { + disp1->send_command_printf("home.chip%02d.font=%" PRIu8, i, chip_font); } - disp1->send_command_printf("home.wifi_icon.font=%" PRIu32, chip_font); + disp1->send_command_printf("home.wifi_icon.font=%" PRIu8, chip_font); id(home_chip_font_id) = chip_font; // Custom buttons icon size ESP_LOGV(TAG, "Custom buttons sizes"); id(home_custom_buttons_font_id) = custom_buttons_font; for (int i = 1; i <= 7; ++i) { - disp1->send_command_printf("home.button%02d.font=%i", i, id(home_custom_buttons_font_id)); + disp1->send_command_printf("home.button%02d.font=%" PRIu8, i, id(home_custom_buttons_font_id)); } - disp1->send_command_printf("home.bt_notific.font=%i", id(home_custom_buttons_font_id)); - disp1->send_command_printf("home.bt_qrcode.font=%i", id(home_custom_buttons_font_id)); - disp1->send_command_printf("home.bt_entities.font=%i", id(home_custom_buttons_font_id)); + disp1->send_command_printf("home.bt_notific.font=%" PRIu8, id(home_custom_buttons_font_id)); + disp1->send_command_printf("home.bt_qrcode.font=%" PRIu8, id(home_custom_buttons_font_id)); + disp1->send_command_printf("home.bt_entities.font=%" PRIu8, id(home_custom_buttons_font_id)); // Outdoor temperature font size ESP_LOGV(TAG, "Outdoor temperature font size"); @@ -794,13 +791,13 @@ api: id(home_relay1_icon_color) = ColorUtil::color_to_565(esphome::Color(relay1_icon_color[0], relay1_icon_color[1], relay1_icon_color[2])); - disp1->set_component_font_color("home.icon_top_01", id(home_relay1_icon_color)); + disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color)); } if (relay2_icon_color.size() == 3) { id(home_relay2_icon_color) = ColorUtil::color_to_565(esphome::Color(relay2_icon_color[0], relay2_icon_color[1], relay2_icon_color[2])); - disp1->set_component_font_color("home.icon_top_02", id(home_relay2_icon_color)); + disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color)); } // Refresh display @@ -942,7 +939,8 @@ api: disp1->set_component_background_color("bt_home_icon", (state == "armed_home") ? 19818 : 52857); disp1->set_component_font_color("bt_home_text", (state == "armed_home") ? 65535 : 0); disp1->set_component_font_color("bt_home_icon", (state == "armed_home") ? 65535 : 0); - if (state == "armed_home") disp1->hide_component("bt_home"); else disp1->show_component("bt_home"); + set_component_visibility->execute("bt_home", (state != "armed_home")); + } if (supported_features & 2 or state == "armed_away") // Alarm - Button - Away { @@ -951,7 +949,7 @@ api: disp1->set_component_background_color("bt_away_icon", (state == "armed_away") ? 19818 : 52857); disp1->set_component_font_color("bt_away_text", (state == "armed_away") ? 65535 : 0); disp1->set_component_font_color("bt_away_icon", (state == "armed_away") ? 65535 : 0); - if (state == "armed_away") disp1->hide_component("bt_away"); else disp1->show_component("bt_away"); + set_component_visibility->execute("bt_away", (state != "armed_away")); } if (supported_features & 4 or state == "armed_night") // Alarm - Button - Night { @@ -960,7 +958,7 @@ api: disp1->set_component_background_color("bt_night_icon", (state == "armed_night") ? 19818 : 52857); disp1->set_component_font_color("bt_night_text", (state == "armed_night") ? 65535 : 0); disp1->set_component_font_color("bt_night_icon", (state == "armed_night") ? 65535 : 0); - if (state == "armed_night") disp1->hide_component("bt_night"); else disp1->show_component("bt_night"); + set_component_visibility->execute("bt_night", (state != "armed_night")); } if (supported_features & 32 or state == "armed_vacation") // Alarm - Button - Vacation { @@ -969,7 +967,7 @@ api: disp1->set_component_background_color("bt_vacat_icon", (state == "armed_vacation") ? 19818 : 52857); disp1->set_component_font_color("bt_vacat_text", (state == "armed_vacation") ? 65535 : 0); disp1->set_component_font_color("bt_vacat_icon", (state == "armed_vacation") ? 65535 : 0); - if (state == "armed_vacation") disp1->hide_component("bt_vacat"); else disp1->show_component("bt_vacat"); + set_component_visibility->execute("bt_vacat", (state != "armed_vacation")); } if (supported_features & 16 or state == "armed_bypass") // Alarm - Button - Custom bypass { @@ -978,7 +976,7 @@ api: disp1->set_component_background_color("bt_bypass_icon", (state == "armed_bypass") ? 19818 : 52857); disp1->set_component_font_color("bt_bypass_text", (state == "armed_bypass") ? 65535 : 0); disp1->set_component_font_color("bt_bypass_icon", (state == "armed_bypass") ? 65535 : 0); - if (state == "armed_bypass") disp1->hide_component("bt_bypass"); else disp1->show_component("bt_bypass"); + set_component_visibility->execute("bt_bypass", (state != "armed_bypass")); } if ( true ) // Alarm - Button - Disarm { @@ -987,7 +985,7 @@ api: disp1->set_component_background_color("bt_disarm_icon", (state == "disarmed") ? 19818 : 52857); disp1->set_component_font_color("bt_disarm_text", (state == "disarmed") ? 65535 : 0); disp1->set_component_font_color("bt_disarm_icon", (state == "disarmed") ? 65535 : 0); - if (state == "disarmed") disp1->hide_component("bt_disarm"); else disp1->show_component("bt_disarm"); + set_component_visibility->execute("bt_disarm", (state != "disarmed")); } } @@ -1127,38 +1125,41 @@ api: // on/off button if (supported_features & 128 and state == "off") { //TURN_ON disp1->set_component_foreground_color("bt_on_off", 65535); - disp1->show_component("bt_on_off"); + set_component_visibility->execute("bt_on_off", true); } else if (supported_features & 256 and state != "off") { //TURN_OFF disp1->set_component_foreground_color("bt_on_off", 10597); - disp1->show_component("bt_on_off"); - } else disp1->hide_component("bt_on_off"); + set_component_visibility->execute("bt_on_off", true); + } else + set_component_visibility->execute("bt_on_off", false); // play/pause button if ((supported_features & 512 or supported_features & 16384) and state != "playing" and state != "off") { //PLAY_MEDIA+PLAY disp1->set_component_text_printf("bt_play_pause", "%s", "\uE409"); // mdi:play - disp1->show_component("bt_play_pause"); + set_component_visibility->execute("bt_play_pause", true); } else if (supported_features & 1 and state == "playing" ) { //PAUSE disp1->set_component_text_printf("bt_play_pause", "%s", "\uE3E3"); // mdi:pause - disp1->show_component("bt_play_pause"); - } else disp1->hide_component("bt_play_pause"); + set_component_visibility->execute("bt_play_pause", true); + } else + set_component_visibility->execute("bt_play_pause", false); // bt_prev button - PREVIOUS_TRACK - if (supported_features & 16 and state != "off") disp1->show_component("bt_prev"); else disp1->hide_component("bt_prev"); + set_component_visibility->execute("bt_prev", (supported_features & 16 and state != "off")); // bt_next button - NEXT_TRACK - if (supported_features & 32 and state != "off") disp1->show_component("bt_next"); else disp1->hide_component("bt_next"); + set_component_visibility->execute("bt_next", (supported_features & 32 and state != "off")); // Stop button - STOP - //if (supported_features & 4096 and (state == "playing" or state == "paused")) disp1->show_component("bt_stop"); else disp1->hide_component("bt_stop"); + //set_component_visibility->execute("bt_stop", (supported_features & 4096 and (state == "playing" or state == "paused"))); // mute/unmute button - VOLUME_MUTE disp1->set_component_value("is_muted", is_volume_muted ? 1 : 0); if (supported_features & 8 and is_volume_muted) { // unmute disp1->set_component_text_printf("bt_mute", "%s", "\uEE07"); // mdi:volume-variant-off - disp1->show_component("bt_mute"); + set_component_visibility->execute("bt_mute", true); } else if (supported_features & 8) { // mute disp1->set_component_text_printf("bt_mute", "%s", "\uE57E"); // mdi:volume-low - disp1->show_component("bt_mute"); - } else disp1->hide_component("bt_mute"); + set_component_visibility->execute("bt_mute", true); + } else + set_component_visibility->execute("bt_mute", false); // VOLUME_SET if (supported_features & 4) { @@ -1167,15 +1168,15 @@ api: disp1->set_component_text_printf("vol_text", "%" PRIu32 "%%", volume_level); disp1->set_component_value("vol_slider", volume_level); } - disp1->show_component("vol_slider"); - disp1->show_component("bt_vol_down"); - disp1->show_component("bt_vol_up"); - disp1->show_component("vol_text"); + set_component_visibility->execute("vol_slider", true); + set_component_visibility->execute("bt_vol_down", true); + set_component_visibility->execute("bt_vol_up", true); + set_component_visibility->execute("vol_text", true); } else { - disp1->hide_component("vol_slider"); - disp1->hide_component("bt_vol_down"); - disp1->hide_component("bt_vol_up"); - disp1->hide_component("vol_text"); + set_component_visibility->execute("vol_slider", false); + set_component_visibility->execute("bt_vol_down", false); + set_component_visibility->execute("bt_vol_up", false); + set_component_visibility->execute("vol_text", false); } if (media_duration > 0) { @@ -1186,14 +1187,14 @@ api: } disp1->set_component_value("prg_total", int(round(media_duration))); disp1->send_command_printf("prg_timer.en=%i", (state == "playing") ? 1 : 0); - disp1->show_component("time_current"); - disp1->show_component("time_total"); - disp1->show_component("time_progress"); + set_component_visibility->execute("time_current", true); + set_component_visibility->execute("time_total", true); + set_component_visibility->execute("time_progress", true); } else { disp1->send_command_printf("prg_timer.en=0"); - disp1->hide_component("time_current"); - disp1->hide_component("time_total"); - disp1->hide_component("time_progress"); + set_component_visibility->execute("time_current", false); + set_component_visibility->execute("time_total", false); + set_component_visibility->execute("time_progress", false); } } @@ -2317,7 +2318,6 @@ text_sensor: static const char *const TAG = "text_sensor.version_tft"; ESP_LOGD(TAG, "TFT version: %s", x.c_str()); if (current_page->state == "boot") { - disp1->send_command_printf("tm_esphome.en=0"); page_boot->execute(); timer_reset_all->execute("boot"); } @@ -2632,14 +2632,15 @@ script: static const char *const TAG = "script.page_boot"; ESP_LOGV(TAG, "Construct boot page"); set_brightness->execute(100); - disp1->set_component_text_printf("boot.esph_version", "${version}"); // ESPHome version - #ifdef ARDUINO - disp1->set_component_text_printf("framework", "Arduino"); - #elif defined(USE_ESP_IDF) - disp1->set_component_text_printf("framework", "ESP-IDF"); - #endif - disp1->send_command_printf("tm_esphome.en=0"); + if (current_page->state == "boot") { + #ifdef ARDUINO + disp1->set_component_text_printf("framework", "Arduino"); + #elif defined(USE_ESP_IDF) + disp1->set_component_text_printf("framework", "ESP-IDF"); + #endif + disp1->send_command_printf("tm_esphome.en=0"); + } - id: page_buttonpage mode: restart @@ -2847,7 +2848,7 @@ script: if (id(screensaver_display_time)) { disp1->send_command_printf("screensaver.text.font=%i", id(screensaver_display_time_font)); disp1->set_component_font_color("screensaver.text", id(screensaver_display_time_color)); - disp1->show_component("text"); + set_component_visibility->execute("screensaver.text", true); refresh_datetime->execute(); } else { disp1->set_backlight_brightness(0.0f); @@ -2862,8 +2863,8 @@ script: static const char *const TAG = "script.page_settings"; ESP_LOGV(TAG, "Construct settings page"); //disp1->set_component_text_printf("bt_sleep", "%s", (id(sleep_mode).state) ? "\uEA19" : "\uEA18"); //mdi:toggle-switch-outline or mdi:toggle-switch-off-outline - disp1->hide_component("lbl_sleep"); - disp1->hide_component("bt_sleep"); + set_component_visibility->execute("page_settings.lbl_sleep", false); + set_component_visibility->execute("page_settings.bt_sleep", false); - id: page_weather mode: restart @@ -2947,13 +2948,7 @@ script: bool is_notification = ((not notification_text->state.empty()) or (not notification_label->state.empty())); ESP_LOGV(TAG, "Notification: %s", YESNO(is_notification)); disp1->send_command_printf("is_notification=%i", is_notification ? 1 : 0); - if (current_page->state == "home") { - if (is_notification) { - disp1->show_component("bt_notific"); - } else { - disp1->hide_component("bt_notific"); - } - } + set_component_visibility->execute("home.bt_notific", is_notification); - wait_until: condition: - lambda: return (blueprint_status->state > 99); @@ -2965,8 +2960,8 @@ script: then: - lambda: |- // Chips - Relays - disp1->set_component_text_printf("home.icon_top_01", "%s", (relay_1->state) ? id(home_relay1_icon) : "\uFFFF"); - disp1->set_component_text_printf("home.icon_top_02", "%s", (relay_2->state) ? id(home_relay2_icon) : "\uFFFF"); + disp1->set_component_text_printf("home.chip_relay1", "%s", (relay_1->state) ? id(home_relay1_icon) : "\uFFFF"); + disp1->set_component_text_printf("home.chip_relay2", "%s", (relay_2->state) ? id(home_relay2_icon) : "\uFFFF"); // Hardware buttons bars - Fallback mode if (id(relay_settings) & nspanel_ha_blueprint::RelaySettings::Relay1_Local) disp1->send_command_printf("home.left_bt_pic.val=%i", (relay_1->state) ? 1 : 0); if (id(relay_settings) & nspanel_ha_blueprint::RelaySettings::Relay2_Local) disp1->send_command_printf("home.right_bt_pic.val=%i", (relay_2->state) ? 1 : 0); @@ -3072,7 +3067,7 @@ script: - lambda: |- static const char *const TAG = "script.set_brightness"; ESP_LOGD(TAG, "brightness: %.0f%%", brightness); - if (brightness == display_brightness->state and current_page->state != "screensaver") + if (brightness == display_brightness->state and current_page->state != "boot" and current_page->state != "screensaver") disp1->send_command_printf("wakeup_timer.en=1"); else disp1->set_backlight_brightness(brightness / 100.0f); @@ -3115,7 +3110,7 @@ script: disp1->send_command_printf("slider_low.maxval=%i", total_steps); disp1->set_component_value("temp_offset", temp_offset); disp1->set_component_value("temp_step", temp_step); - disp1->show_component("current_temp"); + set_component_visibility->execute("current_temp", true); if (current_temp > -999) disp1->set_component_text_printf("current_temp", "%.1f°", current_temp); else @@ -3123,50 +3118,65 @@ script: if (target_temp > -999) { // Target temp enabled disp1->set_component_value("active_slider", 0); - disp1->hide_component("slider_high"); - disp1->hide_component("slider_low"); - disp1->hide_component("target_low"); disp1->set_component_text_printf("target_high", "%.1f°", target_temp); - disp1->show_component("target_high"); disp1->set_component_value("climateslider", round(((10*target_temp) - temp_offset) / temp_step)); - disp1->show_component("climateslider"); + set_component_visibility->execute("slider_high", false); + set_component_visibility->execute("slider_low", false); + set_component_visibility->execute("target_low", false); + set_component_visibility->execute("target_high", true); + set_component_visibility->execute("climateslider", true); } else { - disp1->hide_component("slider_high"); + set_component_visibility->execute("climate.slider_high", false); if (target_temp_low > -999) { // Target temp low enabled disp1->set_component_value("active_slider", 2); disp1->set_component_text_printf("target_low", "%.1f°", target_temp_low); - disp1->show_component("target_low"); disp1->set_component_value("slider_low", round(((10*target_temp_low) - temp_offset) / temp_step)); - disp1->show_component("slider_low"); + set_component_visibility->execute("target_low", true); + set_component_visibility->execute("slider_low", true); } else { - disp1->hide_component("target_low"); - disp1->hide_component("slider_low"); + set_component_visibility->execute("target_low", false); + set_component_visibility->execute("slider_low", false); } if (target_temp_high > -999) { // Target temp high enabled disp1->set_component_value("active_slider", 1); disp1->set_component_text_printf("target_high", "%.1f°", target_temp_high); - disp1->show_component("target_high"); disp1->set_component_value("slider_high", round(((10*target_temp_high) - temp_offset) / temp_step)); - disp1->show_component("slider_high"); + set_component_visibility->execute("target_high", true); + set_component_visibility->execute("slider_high", true); } else { - disp1->hide_component("target_high"); - disp1->hide_component("slider_high"); + set_component_visibility->execute("target_high", false); + set_component_visibility->execute("slider_high", false); } } if (target_temp > -999 or target_temp_high > -999 or target_temp_low > -999) { disp1->set_component_text_printf("target_icon", "%s", climate_icon.c_str()); - disp1->show_component("target_icon"); - disp1->show_component("decrease_temp"); - disp1->show_component("increase_temp"); + set_component_visibility->execute("target_icon", true); + set_component_visibility->execute("decrease_temp", true); + set_component_visibility->execute("increase_temp", true); } else { - disp1->hide_component("target_icon"); - disp1->hide_component("decrease_temp"); - disp1->hide_component("increase_temp"); + set_component_visibility->execute("target_icon", false); + set_component_visibility->execute("decrease_temp", false); + set_component_visibility->execute("increase_temp", false); } disp1->set_component_value("embedded", (embedded_climate) ? 1 : 0); } ESP_LOGD(TAG, "Finished"); + - id: set_component_visibility + mode: queued + parameters: + component_id: string + show: bool + then: + - lambda: |- + nspanel_ha_blueprint::NextionComponent component = nspanel_ha_blueprint::extractNextionComponent(component_id, current_page->state); + if (component.is_current_page) { + if (show) + disp1->show_component(component.component_id); + else + disp1->hide_component(component.component_id); + } + - id: setup_sequence mode: restart then: @@ -3283,8 +3293,8 @@ script: } // Chips icon size ESP_LOGV(TAG, "Adjusting icon's sizes"); - for (int i = 1; i <= 10; ++i) { - disp1->send_command_printf("home.icon_top_%02d.font=%i", i, id(home_chip_font_id)); + for (int i = 1; i <= 7; ++i) { + disp1->send_command_printf("home.chip%02d.font=%i", i, id(home_chip_font_id)); } // Custom buttons icon size ESP_LOGV(TAG, "Adjusting custom buttons sizes"); @@ -3296,8 +3306,8 @@ script: disp1->send_command_printf("home.bt_entities.font=%i", id(home_custom_buttons_font_id)); disp1->send_command_printf("home.wifi_icon.font=%i", id(home_chip_font_id)); ESP_LOGV(TAG, "Restoring relay's icon colors"); - disp1->set_component_font_color("home.icon_top_01", id(home_relay1_icon_color)); - disp1->set_component_font_color("home.icon_top_02", id(home_relay2_icon_color)); + disp1->set_component_font_color("home.chip_relay1", id(home_relay1_icon_color)); + disp1->set_component_font_color("home.chip_relay2", id(home_relay2_icon_color)); timer_reset_all->execute("boot"); notification_clear->execute(); id(setup_sequence_completed) = true; diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 9e72cc0..e9f4662 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -7522,7 +7522,7 @@ action: - *variable_entity - service: '{{ nspanel.service.icon }}' data: - id: home.icon_top_03 + id: home.chip_climate icon: '{{ entity.icon if entity.icon is defined else "" }}' icon_color: '{{ entity.icon_color if entity.icon_color is defined else [] }}' visible: '{{ entity_has_value and entity_state in ["heating", "cooling", "drying", "fan_only"] }}' @@ -7536,37 +7536,37 @@ action: inverted: !input 'chip01_inverted' icon: !input 'chip01_icon' icon_color_rgb: !input 'chip01_icon_color' - component: icon_top_04 + component: chip01 - entity: !input 'chip02' inverted: !input 'chip02_inverted' icon: !input 'chip02_icon' icon_color_rgb: !input 'chip02_icon_color' - component: icon_top_05 + component: chip02 - entity: !input 'chip03' inverted: !input 'chip03_inverted' icon: !input 'chip03_icon' icon_color_rgb: !input 'chip03_icon_color' - component: icon_top_06 + component: chip03 - entity: !input 'chip04' inverted: !input 'chip04_inverted' icon: !input 'chip04_icon' icon_color_rgb: !input 'chip04_icon_color' - component: icon_top_07 + component: chip04 - entity: !input 'chip05' inverted: !input 'chip05_inverted' icon: !input 'chip05_icon' icon_color_rgb: !input 'chip05_icon_color' - component: icon_top_08 + component: chip05 - entity: !input 'chip06' inverted: !input 'chip06_inverted' icon: !input 'chip06_icon' icon_color_rgb: !input 'chip06_icon_color' - component: icon_top_09 + component: chip06 - entity: !input 'chip07' inverted: !input 'chip07_inverted' icon: !input 'chip07_icon' icon_color_rgb: !input 'chip07_icon_color' - component: icon_top_10 + component: chip07 - repeat: for_each: > {{ @@ -7576,23 +7576,23 @@ action: }} sequence: - &display_home_page_status_bar - if: '{{ repeat.item.entity is defined and repeat.item.entity is string and repeat.item.entity | length > 0 }}' + if: '{{ repeat.item.entity is defined and repeat.item.entity is string and repeat.item.entity.split(".") | count == 2 }}' then: - variables: entity_id: '{{ repeat.item.entity }}' overlap: icon: '{{ repeat.item.icon if repeat.item.icon is defined else None }}' icon_color: '{{ repeat.item.icon_color_rgb if repeat.item.icon_color_rgb is defined else None }}' - entity_domain: '{{ entity_id.split(".")[0] }}' - entity_state_tmp: '{{ states(entity_id) | default("unknown") }}' + - *variable_entity + - condition: '{{ entity_has_value }}' + - variables: entity_hvac_action: '{{ state_attr(entity_id, "hvac_action") | default("") if entity_domain == "climate" else "unknown" }}' entity_state: > {{ - (entity_hvac_action if entity_hvac_action and entity_hvac_action not in enum.states.unknown else entity_state_tmp) - if entity_domain == "climate" else entity_state_tmp + (entity_hvac_action if entity_hvac_action and entity_hvac_action not in enum.states.unknown else entity_state) + if entity_domain == "climate" else entity_state }} - if: - - '{{ has_value(entity_id) }}' - or: - and: - '{{ not repeat.item.inverted }}' @@ -7607,7 +7607,6 @@ action: - '{{ entity_domain in enum.states and entity_state in enum.states[entity_domain].off }}' - '{{ entity_domain == "climate" and entity_state not in ["heating", "cooling", "drying", "fan_only"] }}' then: - - *variable_entity - service: '{{ nspanel.service.icon }}' data: id: 'home.{{ repeat.item.component }}'