diff --git a/.test/esphome_common_customizations.yaml b/.test/esphome_common_customizations.yaml index dd691c6d..98fb2701 100644 --- a/.test/esphome_common_customizations.yaml +++ b/.test/esphome_common_customizations.yaml @@ -16,7 +16,7 @@ binary_sensor: id: display_state platform: template lambda: |- - return (current_page_id != ${PAGE_SCREENSAVER_ID}); + return (current_page_id != get_page_id("screensaver")); button: # Adds a button to put the panel to sleep @@ -28,7 +28,7 @@ button: then: - logger.log: Button Sleep pressed - lambda: |- - goto_page->execute(${PAGE_SCREENSAVER_ID}); + goto_page->execute(get_page_id("screensaver")); # Adds a button to wake-up the panel (similar to the existing service) - name: ${device_name} Wake-up @@ -39,7 +39,7 @@ button: then: - logger.log: Button Wake-up pressed - lambda: |- - if (current_page_id == ${PAGE_SCREENSAVER_ID}) id(disp1).goto_page(wakeup_page_id); + if (current_page_id == get_page_id("screensaver")) id(disp1).goto_page(wakeup_page_id); // timer_page->execute(); // enable this if you want page timeout to be reset timer_sleep->execute(); timer_dim->execute(); diff --git a/docs/api.md b/docs/api.md index 0fa8ee12..8bfea8bf 100644 --- a/docs/api.md +++ b/docs/api.md @@ -506,7 +506,6 @@ allowing for real-time interaction with the alarm system directly from the panel **Parameters:** -- `page_title` (string): The title displayed at the top of the alarm settings page. - `state` (string): The current state of the alarm system, such as "armed_home" or "disarmed". - `supported_features` (int): A bitmask indicating the features supported by the alarm system. This determines the controls and options available on the alarm settings page. @@ -521,7 +520,6 @@ The bitmask values are aligned with the ```yaml action: esphome._page_alarm data: - page_title: "Home Security System" state: "disarmed" supported_features: 31 # Example: Supports arm/disarm, home/away modes, etc. code_format: "number" @@ -624,7 +622,6 @@ allowing real-time interaction with the media player directly from the panel. - `entity` (string): The entity ID of the media player. - `state` (string): The current state of the media player (e.g., playing, paused, stopped). - `is_volume_muted` (bool): Indicates whether the volume is currently muted. -- `friendly_name` (string): The friendly name of the media player to be displayed as the page title. - `volume_level` (int): The current volume level of the media player. - `media_title` (string): The title of the currently playing media. - `media_artist` (string): The artist of the currently playing media. @@ -643,7 +640,6 @@ data: entity: "media_player.living_room" state: "playing" is_volume_muted: false - friendly_name: "Living Room Player" volume_level: 40 media_title: "Favorite Song" media_artist: "Famous Artist" diff --git a/docs/customization.md b/docs/customization.md index fdbb97d9..e6f73e4e 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -323,7 +323,7 @@ binary_sensor: id: display_state platform: template lambda: |- - return (current_page_id != ${PAGE_SCREENSAVER_ID}); + return (current_page_id != get_page_id("screensaver")); ``` You can easily invert the meaning to have a sensor for display sleeping: @@ -335,7 +335,7 @@ binary_sensor: id: display_sleeping platform: template lambda: |- - return (current_page_id == ${PAGE_SCREENSAVER_ID}); + return (current_page_id == get_page_id("screensaver")); ``` ### Deep sleep @@ -414,7 +414,7 @@ button: then: - logger.log: Button Sleep pressed - lambda: |- - goto_page->execute(${PAGE_SCREENSAVER_ID}); + goto_page->execute(get_page_id("screensaver")); # Adds a button to wake-up the panel (similar to the existing action) - name: Wake-up @@ -425,7 +425,7 @@ button: then: - logger.log: Button Wake-up pressed - lambda: |- - if (current_page_id == ${PAGE_SCREENSAVER_ID}) disp1->goto_page(wakeup_page_id); + if (current_page_id == get_page_id("screensaver")) disp1->goto_page(wakeup_page_id); // timer_page->execute(); // enable this if you want page timeout to be reset timer_sleep->execute(); timer_dim->execute(); diff --git a/esphome/nspanel_esphome_addon_climate_base.yaml b/esphome/nspanel_esphome_addon_climate_base.yaml index 989e9c43..e040400a 100644 --- a/esphome/nspanel_esphome_addon_climate_base.yaml +++ b/esphome/nspanel_esphome_addon_climate_base.yaml @@ -61,7 +61,7 @@ climate: ESP_LOGW("${TAG_ADDON_CLIMATE}", "Device not ready to work with the new state"); return; } - if (current_page_id == ${PAGE_CLIMATE_ID} and detailed_entity->state == "embedded_climate") { + if (current_page_id == get_page_id("climate") and detailed_entity->state == "embedded_climate") { ESP_LOGV("${TAG_ADDON_CLIMATE}", "Update page 'climate'"); page_climate->execute(); } @@ -200,7 +200,7 @@ script: - id: !extend page_climate then: - lambda: |- - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; if (not id(is_embedded_thermostat)) return; if (detailed_entity->state.empty()) return; if (detailed_entity->state != "embedded_climate") return; @@ -218,7 +218,7 @@ script: // Feed watchdog delay(${DELAY_SHORT}); App.feed_wdt(); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; // Extract temperature values (static since they don't change during runtime) ESP_LOGV("${TAG_ADDON_CLIMATE}", "Extracted temperature values:"); @@ -238,7 +238,7 @@ script: // Feed watchdog delay(${DELAY_SHORT}); App.feed_wdt(); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; // Calculate static values ESP_LOGV("${TAG_ADDON_CLIMATE}", "Calculated static values:"); @@ -251,7 +251,7 @@ script: // Feed watchdog delay(${DELAY_SHORT}); App.feed_wdt(); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; // Get dynamic temperature values ESP_LOGV("${TAG_ADDON_CLIMATE}", "Get dynamic temperature values:"); @@ -274,7 +274,7 @@ script: ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_target_low: %f${temp_units}", temp_target_low); ESP_LOGV("${TAG_ADDON_CLIMATE}", " temp_current: %f${temp_units}", temp_current); feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; #ifdef NSPANEL_EASY_ADDON_CLIMATE_DUAL ESP_LOGV("${TAG_ADDON_CLIMATE}", "Is add-on Climate dual: YES"); @@ -302,7 +302,7 @@ script: set_climate_climate_icon = ""; set_climate_embedded_climate = true; feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; // Execute set_climate ESP_LOGV("${TAG_ADDON_CLIMATE}", "Call set_climate"); @@ -330,7 +330,7 @@ script: (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? Colors::WHITE : Colors::GRAY_DARK)); #endif // NSPANEL_EASY_ADDON_CLIMATE_DUAL feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; #if defined(NSPANEL_EASY_ADDON_CLIMATE_HEAT) || defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL) disp1->show_component("button03"); // Heat @@ -342,7 +342,7 @@ script: (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? Colors::DEEP_ORANGE : Colors::GRAY_DARK)); #endif // NSPANEL_EASY_ADDON_CLIMATE_HEAT || NSPANEL_EASY_ADDON_CLIMATE_DUAL feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; #if defined(NSPANEL_EASY_ADDON_CLIMATE_COOL) || defined(NSPANEL_EASY_ADDON_CLIMATE_DUAL) disp1->show_component("button04"); // Cool @@ -354,17 +354,17 @@ script: (thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? Colors::BLUE : Colors::GRAY_DARK)); #endif // NSPANEL_EASY_ADDON_CLIMATE_COOL || NSPANEL_EASY_ADDON_CLIMATE_DUAL feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; disp1->hide_component("button05"); disp1->set_component_font_color("climate.button05", static_cast(Colors::GRAY_DARK)); feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; disp1->hide_component("button06"); disp1->set_component_font_color("climate.button06", static_cast(Colors::GRAY_DARK)); feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; disp1->show_component("button07"); // Off disp1->set_component_font_color("climate.button07", static_cast( diff --git a/esphome/nspanel_esphome_addon_display_light.yaml b/esphome/nspanel_esphome_addon_display_light.yaml index 1452d390..d6ff2d1c 100644 --- a/esphome/nspanel_esphome_addon_display_light.yaml +++ b/esphome/nspanel_esphome_addon_display_light.yaml @@ -25,12 +25,12 @@ light: on_turn_on: then: - lambda: |- - if (current_page_id == ${PAGE_SCREENSAVER_ID}) disp1->goto_page(wakeup_page_id); + if (current_page_id == get_page_id("screensaver")) disp1->goto_page(wakeup_page_id); timer_reset_all->execute(); on_turn_off: then: - lambda: |- - goto_page->execute(${PAGE_SCREENSAVER_ID}); + goto_page->execute(get_page_id("screensaver")); output: # Output required by `display_light` to send the commands to Nextion @@ -55,10 +55,10 @@ script: then: - lambda: |- ESP_LOGV("${TAG_ADDON_DISPLAY_LIGHT}", "is_on(): %s", display_light->current_values.is_on() ? "True" : "False"); - if (current_page_id == ${PAGE_SCREENSAVER_ID} and display_light->current_values.is_on()) { + if (current_page_id == get_page_id("screensaver") and display_light->current_values.is_on()) { auto call = display_light->turn_off(); call.perform(); - } else if (current_page_id != ${PAGE_SCREENSAVER_ID} and (not display_light->current_values.is_on())) { + } else if (current_page_id != get_page_id("screensaver") and (not display_light->current_values.is_on())) { auto call = display_light->turn_on(); call.perform(); } @@ -69,7 +69,7 @@ script: - lambda: |- uint8_t current_light_brightness = int(round(display_light->current_values.is_on() ? (display_light->current_values.get_brightness() * 100.0f) : 0.0)); if (brightness != current_light_brightness) { - if (current_page_id != ${PAGE_SCREENSAVER_ID} and brightness > 0) { + if (current_page_id != get_page_id("screensaver") and brightness > 0) { auto call = display_light->turn_on(); call.set_brightness(brightness / 100.0f); call.perform(); diff --git a/esphome/nspanel_esphome_api.yaml b/esphome/nspanel_esphome_api.yaml index 43e9a898..524d83c7 100644 --- a/esphome/nspanel_esphome_api.yaml +++ b/esphome/nspanel_esphome_api.yaml @@ -404,13 +404,13 @@ script: - lambda: |- update_flag_api_ready->execute(); if (!system_flags.api_ready and - current_page_id != ${PAGE_BOOT_ID} and - current_page_id != ${PAGE_CONFIRM_ID} and - current_page_id != ${PAGE_HOME_ID} and - current_page_id != ${PAGE_QRCODE_ID} and - current_page_id != ${PAGE_SCREENSAVER_ID} and - current_page_id != ${PAGE_SETTINGS_ID}) { + current_page_id != get_page_id("boot") and + current_page_id != get_page_id("confirm") and + current_page_id != get_page_id("home") and + current_page_id != get_page_id("qrcode") and + current_page_id != get_page_id("screensaver") and + current_page_id != get_page_id("settings")) { ESP_LOGW("${TAG_API}", "API disconnected. Falling back to Home page."); - goto_page->execute(${PAGE_HOME_ID}); + goto_page->execute(get_page_id("home")); } ... diff --git a/esphome/nspanel_esphome_page_alarm.yaml b/esphome/nspanel_esphome_page_alarm.yaml index 7ac59fe4..3d9d9de8 100644 --- a/esphome/nspanel_esphome_page_alarm.yaml +++ b/esphome/nspanel_esphome_page_alarm.yaml @@ -13,8 +13,6 @@ substitutions: PAGE_ALARM_DELAY_LONG: ${DELAY_LONG} PAGE_ALARM_DELAY_SHORT: ${DELAY_SHORT} - BOOT_STEP_PAGE_ALARM: 10 - PAGE_ALARM_ID: 23 TAG_PAGE_ALARM: nspanel.page.alarm api: @@ -22,7 +20,6 @@ api: # Updates the alarm settings page with current state and configuration, integrating with the panel's interface. - action: page_alarm variables: - page_title: string # Title for the alarm settings page, displayed prominently at the top. state: string # Current state of the alarm system (e.g., "armed_home", "disarmed"). supported_features: int # Bitmask representing the alarm system's supported features, determining available controls on the page. code_format: string # Format required for the alarm code (numeric, alphanumeric). @@ -31,7 +28,7 @@ api: then: # To do: This page constructor should be moved to Blueprint - lambda: |- - if (current_page_id != ${PAGE_ALARM_ID}) return; + if (current_page_id != get_page_id("alarm")) return; // Helper function to update alarm button state and visibility // Handles feature checking, logging, and UI updates for all buttons including disarm @@ -131,20 +128,6 @@ api: 10, ${LANG_BYTES_PER_CHAR}).c_str()); feed_wdt_delay(${PAGE_ALARM_DELAY_SHORT}); - // Page header - ESP_LOGV("${TAG_PAGE_ALARM}", "Page header"); - update_alarm_icon->execute("icon_state", state.c_str()); // Icon - // Page header - Title - std::string title = page_title.c_str(); - - // Replace the first occurrence of "\r" (two chars: backslash + r) with a space - auto pos = title.find("\\r"); - if (pos != std::string::npos) { - title.replace(pos, 2, " "); - } - - disp1->set_component_text("page_label", title.c_str()); - ESP_LOGV("${TAG_PAGE_ALARM}", "Done!"); esphome: @@ -177,9 +160,9 @@ script: if (code_format == "number" && (key == "disarm" || code_arm_req == "1")) { ESP_LOGV("${TAG_PAGE_ALARM}", "Open keypad"); - goto_page->execute(${PAGE_KEYB_NUM_ID}); + goto_page->execute(get_page_id("keyb_num")); - disp1->set_component_value("page_id", ${PAGE_ALARM_ID}); + disp1->set_component_value("page_id", get_page_id("alarm")); disp1->set_component_text("domain", "alarm"); disp1->set_component_text("key", key.c_str()); disp1->set_component_text("value", "click"); @@ -243,7 +226,7 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id == ${PAGE_ALARM_ID}) + if (new_page_id == get_page_id("alarm")) page_alarm->execute(); - id: !extend stop_all diff --git a/esphome/nspanel_esphome_page_boot.yaml b/esphome/nspanel_esphome_page_boot.yaml index 2024aadf..db0ee7b6 100644 --- a/esphome/nspanel_esphome_page_boot.yaml +++ b/esphome/nspanel_esphome_page_boot.yaml @@ -8,7 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_BOOT: 29 PAGE_BOOT_COMPONENT_ID_BT_REBOOT: 21 PAGE_BOOT_DELAY_TO_EXIT: 30s PAGE_BOOT_ID: 0 @@ -22,7 +21,7 @@ display: - lambda: |- if ( !touch_event and // Only act with release - page_id == ${PAGE_BOOT_ID} and + page_id == get_page_id("boot") and component_id == ${PAGE_BOOT_COMPONENT_ID_BT_REBOOT} // Reboot button ) { screen_power->turn_off(); @@ -38,7 +37,7 @@ script: - id: !extend boot_log then: - lambda: |- - if (current_page_id == ${PAGE_BOOT_ID}) { + if (current_page_id == get_page_id("boot")) { disp1->send_command_printf("log_body.txt+=\"%s: %s\\r\"", category.c_str(), log_message.c_str()); feed_wdt_delay(${DELAY_SHORT}); } @@ -105,14 +104,14 @@ script: - delay: ${PAGE_BOOT_DELAY_TO_EXIT} - script.wait: wait_for_version_tft - lambda: |- - if (current_page_id == ${PAGE_BOOT_ID}) + if (current_page_id == get_page_id("boot")) wakeup->execute(false); - id: page_boot_show_blueprint_version mode: single then: - lambda: |- - if (current_page_id == ${PAGE_BOOT_ID} and version_blueprint > 0) + if (current_page_id == get_page_id("boot") and version_blueprint > 0) disp1->set_component_text_printf("ver_blueprint", "Blueprint: %" PRIu8, version_blueprint); - id: page_boot_show_ip @@ -120,7 +119,7 @@ script: then: - lambda: |- if (!wifi_component->is_connected()) return; - if (current_page_id != ${PAGE_BOOT_ID}) return; + if (current_page_id != get_page_id("boot")) return; auto ips = network::get_ip_addresses(); if (ips.empty()) return; char ip[16]; // sufficient for IPv4: "255.255.255.255" + '\0' @@ -130,7 +129,7 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id == ${PAGE_BOOT_ID} and display_mode != 4) + if (new_page_id == get_page_id("boot") and display_mode != 4) page_boot->execute(); - id: !extend stop_all @@ -155,7 +154,8 @@ script: then: - while: condition: - - lambda: return current_page_id == ${PAGE_BOOT_ID}; + - lambda: |- + return current_page_id == get_page_id("boot"); then: - lambda: |- ESP_LOGV("${TAG_PAGE_BOOT}", "Waiting for boot page exit"); @@ -164,7 +164,7 @@ script: - id: !extend watchdog_round then: - lambda: |- - if (current_page_id == ${PAGE_BOOT_ID} and version_tft > 0) + if (current_page_id == get_page_id("boot") and version_tft > 0) wakeup->execute(true); wifi: diff --git a/esphome/nspanel_esphome_page_button.yaml b/esphome/nspanel_esphome_page_button.yaml index 2f5fdf94..1d3580ef 100644 --- a/esphome/nspanel_esphome_page_button.yaml +++ b/esphome/nspanel_esphome_page_button.yaml @@ -7,7 +7,6 @@ ##################################################################################################### --- substitutions: - PAGE_BUTTON_ID: 33 page_button_color_idle: 16904 page_button_color_pressed: 15483 page_button_color_unavail: 10565 diff --git a/esphome/nspanel_esphome_page_buttons.yaml b/esphome/nspanel_esphome_page_buttons.yaml index 44048951..91a088a9 100644 --- a/esphome/nspanel_esphome_page_buttons.yaml +++ b/esphome/nspanel_esphome_page_buttons.yaml @@ -11,12 +11,7 @@ --- substitutions: - BOOT_STEP_PAGE_BUTTONS: 11 BUTTON_LONG_PRESS_DELAY: 800ms - PAGE_BUTTONPAGE01_ID: 12 - PAGE_BUTTONPAGE02_ID: 13 - PAGE_BUTTONPAGE03_ID: 14 - PAGE_BUTTONPAGE04_ID: 15 TAG_PAGE_BUTTONS: nspanel.page.buttons THEME_PAGE_BUTTONS_DARK_PIC_BUTTON: 46 THEME_PAGE_BUTTONS_DARK_PIC_PRESSED: 47 diff --git a/esphome/nspanel_esphome_page_climate.yaml b/esphome/nspanel_esphome_page_climate.yaml index 8e9fc375..beb2a32e 100644 --- a/esphome/nspanel_esphome_page_climate.yaml +++ b/esphome/nspanel_esphome_page_climate.yaml @@ -7,8 +7,6 @@ ##################################################################################################### --- substitutions: - BOOT_STEP_PAGE_CLIMATE: 12 - PAGE_CLIMATE_ID: 7 TAG_PAGE_CLIMATE: nspanel.page.climate api: @@ -43,7 +41,7 @@ api: ESP_LOGV("${TAG_PAGE_CLIMATE}", " entity: %s", entity.c_str()); // Set detailed entity sensor - if (current_page_id == ${PAGE_CLIMATE_ID}) + if (current_page_id == get_page_id("climate")) detailed_entity->publish_state(entity.c_str()); set_climate_current_temp = current_temp; @@ -71,7 +69,7 @@ display: component_id == hmi::home::INDR_TEMP_ICON.id)) { // Indoor temp icon detailed_entity->publish_state((id(is_embedded_thermostat)) ? "embedded_climate" : ""); disp1->set_component_value("climate.embedded", id(is_embedded_thermostat) ? 1 : 0); - goto_page->execute(${PAGE_CLIMATE_ID}); + goto_page->execute(get_page_id("climate")); return; } @@ -144,7 +142,7 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_CLIMATE_ID}) page_climate->execute(); + - lambda: if (new_page_id == get_page_id("climate")) page_climate->execute(); - id: page_climate mode: single @@ -166,7 +164,7 @@ script: ESP_LOGV("${TAG_PAGE_CLIMATE}", " set_climate_climate_icon: %s", set_climate_climate_icon.c_str()); ESP_LOGV("${TAG_PAGE_CLIMATE}", " set_climate_embedded_climate: %s", YESNO(set_climate_embedded_climate)); - if (current_page_id != ${PAGE_CLIMATE_ID}) { + if (current_page_id != get_page_id("climate")) { ESP_LOGW("${TAG_PAGE_CLIMATE}", "'set_climate' was called when page 'climate' is not visible"); return; } @@ -192,7 +190,7 @@ script: char buffer[15]; const bool useDecimal = (set_climate_temp_step % 10 != 0); feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; if (set_climate_current_temp > -999) { // Current temp enabled ESP_LOGV("${TAG_PAGE_CLIMATE}", "Show current temperature"); @@ -203,7 +201,7 @@ script: disp1->set_component_text("current_temp", "${LOCALIZATION[LANG].unavailable}"); } feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; uint8_t active_slider = UINT8_MAX; @@ -244,7 +242,7 @@ script: disp1->hide_component("slider_low"); } feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; if (set_climate_target_temp_high > -999) { // Target temp high enabled active_slider = 1; @@ -263,7 +261,7 @@ script: } } feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; if ( set_climate_target_temp > -999 or // Target temp enabled @@ -280,7 +278,7 @@ script: disp1->hide_component("increase_temp"); } feed_wdt_delay(${DELAY_SHORT}); - if (current_page_id != ${PAGE_CLIMATE_ID}) return; + if (current_page_id != get_page_id("climate")) return; if (active_slider != UINT8_MAX) disp1->set_component_value("active_slider", active_slider); diff --git a/esphome/nspanel_esphome_page_confirm.yaml b/esphome/nspanel_esphome_page_confirm.yaml index 029cbe61..4816f8c4 100644 --- a/esphome/nspanel_esphome_page_confirm.yaml +++ b/esphome/nspanel_esphome_page_confirm.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_CONFIRM: 13 - PAGE_CONFIRM_ID: 26 TAG_PAGE_CONFIRM: nspanel.page.confirm esphome: @@ -21,14 +19,14 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id == ${PAGE_CONFIRM_ID}) + if (new_page_id == get_page_id("confirm")) page_confirm->execute(); - id: page_confirm mode: single then: - lambda: |- - if (current_page_id != ${PAGE_CONFIRM_ID}) return; + if (current_page_id != get_page_id("confirm")) return; if (!is_device_ready_for_tasks()) return; disp1->set_component_text("confirm.title", wrapText( "${LOCALIZATION[LANG].please_confirm}", diff --git a/esphome/nspanel_esphome_page_cover.yaml b/esphome/nspanel_esphome_page_cover.yaml index 86c3f6a4..d745666c 100644 --- a/esphome/nspanel_esphome_page_cover.yaml +++ b/esphome/nspanel_esphome_page_cover.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_COVER: 14 - PAGE_COVER_ID: 11 TAG_PAGE_COVER: nspanel.page.cover esphome: diff --git a/esphome/nspanel_esphome_page_entities.yaml b/esphome/nspanel_esphome_page_entities.yaml index c9f8b358..82441205 100644 --- a/esphome/nspanel_esphome_page_entities.yaml +++ b/esphome/nspanel_esphome_page_entities.yaml @@ -8,11 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_ENTITIES: 15 - PAGE_ENTITYPAGE01_ID: 18 - PAGE_ENTITYPAGE02_ID: 19 - PAGE_ENTITYPAGE03_ID: 20 - PAGE_ENTITYPAGE04_ID: 21 half_width_chars: "iljtIf '-,;:!.\\\"|()[]{}*^~\\\\/_" TAG_PAGE_ENTITIES: nspanel.page.entities @@ -90,7 +85,7 @@ script: if (component == "is_entitypages") { // Visibility of entity pages button on page "Home" const uint8_t is_entitypages = (val > 0) ? 1 : 0; disp1->send_command_printf("vis_bt_entities=%d", is_entitypages); - if (current_page_id == ${PAGE_HOME_ID}) { + if (current_page_id == get_page_id("home")) { disp1->send_command_printf("vis bt_entities,%d", is_entitypages); } } @@ -98,10 +93,10 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id == ${PAGE_ENTITYPAGE01_ID}) page_entitypage->execute(1); - else if (new_page_id == ${PAGE_ENTITYPAGE02_ID}) page_entitypage->execute(2); - else if (new_page_id == ${PAGE_ENTITYPAGE03_ID}) page_entitypage->execute(3); - else if (new_page_id == ${PAGE_ENTITYPAGE04_ID}) page_entitypage->execute(4); + if (new_page_id == get_page_id("entitypage01")) page_entitypage->execute(1); + else if (new_page_id == get_page_id("entitypage02")) page_entitypage->execute(2); + else if (new_page_id == get_page_id("entitypage03")) page_entitypage->execute(3); + else if (new_page_id == get_page_id("entitypage04")) page_entitypage->execute(4); - id: page_entitypage mode: single @@ -110,10 +105,10 @@ script: then: - lambda: |- // Set value alignment - if (current_page_id == ${PAGE_ENTITYPAGE01_ID} or - current_page_id == ${PAGE_ENTITYPAGE02_ID} or - current_page_id == ${PAGE_ENTITYPAGE03_ID} or - current_page_id == ${PAGE_ENTITYPAGE04_ID}) { + if (current_page_id == get_page_id("entitypage01") or + current_page_id == get_page_id("entitypage02") or + current_page_id == get_page_id("entitypage03") or + current_page_id == get_page_id("entitypage04")) { for (uint8_t i = 1; i <= 8; ++i) { disp1->send_command_printf("value%02d.xcen=%" PRIu8, i, page_entities_value_horizontal_alignment); } diff --git a/esphome/nspanel_esphome_page_fan.yaml b/esphome/nspanel_esphome_page_fan.yaml index 6c85c8c5..8b99e7ee 100644 --- a/esphome/nspanel_esphome_page_fan.yaml +++ b/esphome/nspanel_esphome_page_fan.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_FAN: 16 - PAGE_FAN_ID: 22 TAG_PAGE_FAN: nspanel.page.fan display: @@ -18,7 +16,7 @@ display: then: - lambda: |- if ( - page_id == ${PAGE_FAN_ID} and // Page fan + page_id == get_page_id("fan") and // Page fan !touch_event // Only act with release ) { switch (component_id) { @@ -82,7 +80,7 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_FAN_ID}) page_fan->execute(); + - lambda: if (new_page_id == get_page_id("fan")) page_fan->execute(); - id: page_fan mode: single diff --git a/esphome/nspanel_esphome_page_home.yaml b/esphome/nspanel_esphome_page_home.yaml index ca357c26..9e0f2ada 100644 --- a/esphome/nspanel_esphome_page_home.yaml +++ b/esphome/nspanel_esphome_page_home.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_HOME: 17 - PAGE_HOME_ID: 1 TAG_PAGE_HOME: nspanel.page.home THEME_DARK_PIC_PAGE_HOME_WEATHER_OFFSET: 48 @@ -216,7 +214,9 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == hmi::home::PAGE.id) page_home->execute(); + - lambda: |- + if (new_page_id == get_page_id("home")) + page_home->execute(); - id: page_home mode: single @@ -233,7 +233,7 @@ script: show: bool then: - lambda: |- - const bool is_current_page = (current_page_id == hmi::home::PAGE.id); + const bool is_current_page = (current_page_id == get_page_id("home")); // Extract component parts (handles both "id" and "page.id" formats) const esphome::nspanel_easy::NSPanelEasyNextionComponent component = diff --git a/esphome/nspanel_esphome_page_keyb_num.yaml b/esphome/nspanel_esphome_page_keyb_num.yaml index 19085cb1..f8f94210 100644 --- a/esphome/nspanel_esphome_page_keyb_num.yaml +++ b/esphome/nspanel_esphome_page_keyb_num.yaml @@ -7,8 +7,6 @@ ##################################################################################################### --- substitutions: - BOOT_STEP_PAGE_KEYBOARD_NUM: 18 - PAGE_KEYB_NUM_ID: 24 TAG_PAGE_KEYB_NUM: nspanel.page.keyb_num esphome: @@ -45,12 +43,14 @@ script: ESP_LOGV("${TAG_PAGE_KEYB_NUM}", "Navigating to: %s", base_domain.empty() ? "home" : base_domain.c_str()); - goto_page->execute(base_domain.empty() ? ${PAGE_HOME_ID} : get_page_id(base_domain.c_str())); + goto_page->execute(base_domain.empty() ? get_page_id("home") : get_page_id(base_domain.c_str())); } // endif params[0] == "keyb_num" - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_KEYB_NUM_ID}) page_keyb_num->execute(); + - lambda: |- + if (new_page_id == get_page_id("keyb_num")) + page_keyb_num->execute(); - id: page_keyb_num mode: single diff --git a/esphome/nspanel_esphome_page_light.yaml b/esphome/nspanel_esphome_page_light.yaml index 28234784..8693bc1b 100644 --- a/esphome/nspanel_esphome_page_light.yaml +++ b/esphome/nspanel_esphome_page_light.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_LIGHT: 19 - PAGE_LIGHT_ID: 10 TAG_PAGE_LIGHT: nspanel.page.light display: @@ -18,7 +16,7 @@ display: then: - lambda: |- if ( - page_id == ${PAGE_LIGHT_ID} and // Page light + page_id == get_page_id("light") and // Page light !touch_event and // Release component_id == 29 // power button ) { @@ -107,7 +105,9 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_LIGHT_ID}) page_light->execute(); + - lambda: |- + if (new_page_id == get_page_id("light")) + page_light->execute(); - id: page_light mode: single diff --git a/esphome/nspanel_esphome_page_media_player.yaml b/esphome/nspanel_esphome_page_media_player.yaml index 4699abaa..c4dd2d3e 100644 --- a/esphome/nspanel_esphome_page_media_player.yaml +++ b/esphome/nspanel_esphome_page_media_player.yaml @@ -8,12 +8,9 @@ --- substitutions: - BOOT_STEP_PAGE_MEDIA_PLAYER: 20 PAGE_MEDIA_PLAYER_DELAY_DEFAULT: ${DELAY_DEFAULT} PAGE_MEDIA_PLAYER_DELAY_LONG: ${DELAY_LONG} PAGE_MEDIA_PLAYER_DELAY_SHORT: ${DELAY_SHORT} - PAGE_MEDIA_PLAYER_ID: 25 - PAGE_MEDIA_PLAYER_NAME: media_player COMPONENT_ID_MEDIA_PLAYER_BT_VOL_DOWN: 6 COMPONENT_ID_MEDIA_PLAYER_BT_VOL_UP: 7 MEDIA_PLAYER_FEATURE_PAUSE: 1 @@ -51,7 +48,6 @@ api: entity: string # Entity ID of the media player, used for state updates and control. state: string # Current playback state of the media player (e.g., "playing", "paused", "stopped"). is_volume_muted: bool # Indicates if the media volume is currently muted. - friendly_name: string # Display name of the media player, shown as the page title. volume_level: int # Current volume level, typically expressed as a percentage. media_title: string # Title of the currently playing media. media_artist: string # Artist of the currently playing media. @@ -65,7 +61,6 @@ api: ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " entity: %s", entity.c_str()); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " state: %s", state.c_str()); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " is_volume_muted: %s", YESNO(is_volume_muted)); - ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " friendly_name: %s", friendly_name.c_str()); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " volume_level: %i", volume_level); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " media_title: %s", media_title.c_str()); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " media_artist: %s", media_artist.c_str()); @@ -74,7 +69,7 @@ api: ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " media_position_delta: %i", media_position_delta); ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", " supported_features: %i", supported_features); - if (current_page_id != ${PAGE_MEDIA_PLAYER_ID}) { + if (current_page_id != get_page_id("media_player")) { ESP_LOGW("${TAG_PAGE_MEDIA_PLAYER}", "Not on Media Player page"); return; } @@ -83,10 +78,6 @@ api: ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", "Set detailed entity sensor"); detailed_entity->publish_state(entity.c_str()); - // Page header - ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", "Page header"); - disp1->set_component_text("page_label", friendly_name.c_str()); - // Media title ESP_LOGV("${TAG_PAGE_MEDIA_PLAYER}", "Media title"); disp1->set_component_text("track", wrapText(media_title.c_str(), @@ -200,7 +191,7 @@ script: - lambda: |- if (params_count < 2) return; - if (params[0] == "${PAGE_MEDIA_PLAYER_NAME}") { + if (params[0] == "media_player") { // CSV Format: // media_player,volume_mute, // media_player,volume_set, @@ -259,7 +250,7 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_MEDIA_PLAYER_ID}) page_media_player->execute(); + - lambda: if (new_page_id == get_page_id("media_player")) page_media_player->execute(); - id: page_media_player mode: restart diff --git a/esphome/nspanel_esphome_page_notification.yaml b/esphome/nspanel_esphome_page_notification.yaml index e0ffd490..38c79bee 100644 --- a/esphome/nspanel_esphome_page_notification.yaml +++ b/esphome/nspanel_esphome_page_notification.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_NOTIFICATION: 21 - PAGE_NOTIFICATION_ID: 16 tone_notification: "two short:d=4,o=5,b=100:16e6,16e6" TAG_PAGE_NOTIFICATION: nspanel.page.notification @@ -34,10 +32,10 @@ api: notification_label = label; notification_text = message; notification_unread->publish_state(true); - if (current_page_id == ${PAGE_NOTIFICATION_ID}) { + if (current_page_id == get_page_id("notification")) { page_notification->execute(); } else { - goto_page->execute(${PAGE_NOTIFICATION_ID}); + goto_page->execute(get_page_id("notification")); } // Only when buzzer is available #ifdef NSPANEL_EASY_HW_BUZZER @@ -62,7 +60,7 @@ display: then: - lambda: |- if ( - page_id == ${PAGE_NOTIFICATION_ID} and // Page notification + page_id == get_page_id("notification") and // Page notification !touch_event // Only act with release ) { switch (component_id) { @@ -103,13 +101,13 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_NOTIFICATION_ID}) page_notification->execute(); + - lambda: if (new_page_id == get_page_id("notification")) page_notification->execute(); - id: page_notification mode: single then: - lambda: |- - if (current_page_id == ${PAGE_NOTIFICATION_ID}) { + if (current_page_id == get_page_id("notification")) { disp1->set_component_text("notifi_label", notification_label.c_str()); disp1->set_component_text("notifi_text01", wrapText(notification_text.c_str(), display_mode == 2 ? 23 : 32, @@ -137,7 +135,7 @@ script: mode: single then: - lambda: |- - if (current_page_id == ${PAGE_NOTIFICATION_ID}) + if (current_page_id == get_page_id("notification")) goto_page->execute(hmi::home::PAGE.id); notification_label = ""; notification_text = ""; diff --git a/esphome/nspanel_esphome_page_qrcode.yaml b/esphome/nspanel_esphome_page_qrcode.yaml index dabdcb51..3fa58235 100644 --- a/esphome/nspanel_esphome_page_qrcode.yaml +++ b/esphome/nspanel_esphome_page_qrcode.yaml @@ -15,7 +15,6 @@ substitutions: qrcode_background_color: 65535 qrcode_foreground_color: 0 qrcode_border_size: 8 - PAGE_QRCODE_ID: 17 TAG_PAGE_QRCODE: nspanel.page.qrcode api: @@ -41,7 +40,7 @@ api: id(qrcode_title) = title; id(qrcode_string) = qrcode; if (show) { - goto_page->execute(hmi::qrcode::PAGE.id); + goto_page->execute(get_page_id("qrcode")); } else { page_qrcode->execute(); } @@ -58,10 +57,10 @@ display: then: - lambda: |- if (touch_event) return; // Ignore the touch, so only the release will be used - if (page_id == hmi::home::PAGE.id and // Page `home` - component_id == hmi::home::BT_QRCODE.id and // QRcode button - !id(qrcode_string).empty()) { // QRcode string is not empty - goto_page->execute(hmi::qrcode::PAGE.id); + if (page_id == hmi::home::PAGE.id and // Page `home` + component_id == get_page_id("qrcode") and // QRcode button + !id(qrcode_string).empty()) { // QRcode string is not empty + goto_page->execute(get_page_id("qrcode")); return; } @@ -133,7 +132,9 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == hmi::qrcode::PAGE.id) page_qrcode->execute(); + - lambda: |- + if (new_page_id == get_page_id("qrcode")) + page_qrcode->execute(); - id: !extend page_home then: @@ -146,7 +147,7 @@ script: mode: single then: - lambda: |- - if (current_page_id != hmi::qrcode::PAGE.id) { + if (current_page_id != get_page_id("qrcode")) { return; // Page QRcode not visible } diff --git a/esphome/nspanel_esphome_page_screensaver.yaml b/esphome/nspanel_esphome_page_screensaver.yaml index a39b01ec..3f4c80dd 100644 --- a/esphome/nspanel_esphome_page_screensaver.yaml +++ b/esphome/nspanel_esphome_page_screensaver.yaml @@ -9,8 +9,7 @@ --- substitutions: wakeup_with_button_press: false - BOOT_STEP_PAGE_SCREENSAVER: 23 - PAGE_SCREENSAVER_ID: 9 + PAGE_SCREENSAVER_ID: 9 # Kept for back compatibility for users using customizations TAG_PAGE_SCREENSAVER: nspanel.page.screensaver esphome: @@ -67,7 +66,7 @@ number: on_value: then: - lambda: |- - if (x == 0 and current_page_id == ${PAGE_SCREENSAVER_ID}) { + if (x == 0 and current_page_id == get_page_id("screensaver")) { wakeup->execute(false); } timer_sleep->execute(); @@ -100,7 +99,7 @@ script: - id: !extend ha_button then: - lambda: |- - if (current_page_id != ${PAGE_SCREENSAVER_ID}) { + if (current_page_id != get_page_id("screensaver")) { timer_reset_all->execute(); return; } @@ -111,14 +110,14 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_SCREENSAVER_ID}) page_screensaver->execute(); + - lambda: if (new_page_id == get_page_id("screensaver")) page_screensaver->execute(); - id: page_screensaver mode: single then: - if: condition: - - lambda: return (current_page_id == ${PAGE_SCREENSAVER_ID} and not system_flags.tft_upload_active); + - lambda: return (current_page_id == get_page_id("screensaver") and not system_flags.tft_upload_active); then: - lambda: |- page_screensaver_set_brightness->execute(); @@ -136,7 +135,7 @@ script: mode: single then: - lambda: |- - if (current_page_id == ${PAGE_SCREENSAVER_ID}) + if (current_page_id == get_page_id("screensaver")) set_brightness->execute(int(display_sleep_brightness->state)); - id: !extend stop_all @@ -157,11 +156,11 @@ script: - lambda: |- if ( timeout_sleep->state > 0 and - current_page_id != ${PAGE_SCREENSAVER_ID} and + current_page_id != get_page_id("screensaver") and current_page_id != ${PAGE_BOOT_ID} ) { ESP_LOGD("${TAG_PAGE_SCREENSAVER}", "Sleep from '%s'", page_names[current_page_id]); - goto_page->execute(${PAGE_SCREENSAVER_ID}); + goto_page->execute(get_page_id("screensaver")); set_brightness->execute(display_sleep_brightness->state); } diff --git a/esphome/nspanel_esphome_page_settings.yaml b/esphome/nspanel_esphome_page_settings.yaml index e18cb6b3..4937420e 100644 --- a/esphome/nspanel_esphome_page_settings.yaml +++ b/esphome/nspanel_esphome_page_settings.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_SETTINGS: 28 - PAGE_SETTINGS_ID: 8 TAG_PAGE_SETTINGS: nspanel.page.settings display: @@ -19,7 +17,7 @@ display: - lambda: |- if ( !touch_event and // Only act with release - page_id == ${PAGE_SETTINGS_ID} and + page_id == get_page_id("settings") and component_id == 9 // Reboot button ) { screen_power->turn_off(); @@ -37,7 +35,7 @@ number: then: - lambda: |- disp1->set_component_value("settings.brightslider", int(x)); - if (current_page_id == ${PAGE_SETTINGS_ID}) + if (current_page_id == get_page_id("settings")) disp1->set_component_text_printf("bright_text", "%i%%", int(x)); - id: !extend display_dim_brightness @@ -45,7 +43,7 @@ number: then: - lambda: |- disp1->set_component_value("settings.dimslider", int(x)); - if (current_page_id == ${PAGE_SETTINGS_ID}) + if (current_page_id == get_page_id("settings")) disp1->set_component_text_printf("dim_text", "%i%%", int(x)); script: @@ -81,14 +79,14 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id == ${PAGE_SETTINGS_ID}) + if (new_page_id == get_page_id("settings")) page_settings->execute(); - id: page_settings mode: single then: - lambda: |- - if (current_page_id != ${PAGE_SETTINGS_ID}) return; + if (current_page_id != get_page_id("settings")) return; disp1->set_component_text("lbl_reboot", "${LOCALIZATION[LANG].settings.reboot}"); disp1->set_component_text("lbl_brightness", "${LOCALIZATION[LANG].settings.brightness}"); disp1->set_component_text("lbl_bright", "${LOCALIZATION[LANG].settings.bright}"); diff --git a/esphome/nspanel_esphome_page_utilities.yaml b/esphome/nspanel_esphome_page_utilities.yaml index 7e3c7070..cb98396c 100644 --- a/esphome/nspanel_esphome_page_utilities.yaml +++ b/esphome/nspanel_esphome_page_utilities.yaml @@ -8,8 +8,6 @@ --- substitutions: - BOOT_STEP_PAGE_UTILITIES: '24' - PAGE_UTILITIES_ID: 27 TAG_PAGE_UTILITIES: nspanel.page.utilities api: diff --git a/esphome/nspanel_esphome_page_water_heater.yaml b/esphome/nspanel_esphome_page_water_heater.yaml index f8437693..ae99314b 100644 --- a/esphome/nspanel_esphome_page_water_heater.yaml +++ b/esphome/nspanel_esphome_page_water_heater.yaml @@ -7,7 +7,6 @@ ##################################################################################################### --- substitutions: - PAGE_WATER_HEATER_ID: 30 TAG_PAGE_WATER_HEATER: nspanel.page.water_heater esphome: @@ -53,7 +52,9 @@ script: - id: !extend page_change then: - - lambda: if (new_page_id == ${PAGE_WATER_HEATER_ID}) page_water_heater->execute(); + - lambda: |- + if (new_page_id == get_page_id("water_heater")) + page_water_heater->execute(); - id: page_water_heater mode: single diff --git a/esphome/nspanel_esphome_page_weather.yaml b/esphome/nspanel_esphome_page_weather.yaml index db8b3088..99be2f8e 100644 --- a/esphome/nspanel_esphome_page_weather.yaml +++ b/esphome/nspanel_esphome_page_weather.yaml @@ -7,11 +7,6 @@ ##################################################################################################### --- substitutions: - PAGE_WEATHER01_ID: 2 - PAGE_WEATHER02_ID: 3 - PAGE_WEATHER03_ID: 4 - PAGE_WEATHER04_ID: 5 - PAGE_WEATHER05_ID: 6 TAG_PAGE_WEATHER: nspanel.page.weather SECONDS_PER_DAY: 86400 @@ -21,11 +16,11 @@ display: then: - lambda: |- if (touch_event) return; // Ignore the touch, so only the release will be used - if (page_id == hmi::home::PAGE.id and // Page `home` + if (page_id == get_page_id("home") and // Page `home` system_flags.api_ready and // Is API available? (component_id == hmi::home::WEATHER.id or // Outdoor temperature component_id == hmi::home::OUTDOOR_TEMP.id)) { // Weather picture - goto_page->execute(${PAGE_WEATHER01_ID}); + goto_page->execute(get_page_id("weather01")); return; } @@ -53,14 +48,14 @@ script: - id: !extend page_change then: - lambda: |- - if (new_page_id >= ${PAGE_WEATHER01_ID} and new_page_id <= ${PAGE_WEATHER05_ID}) + if (new_page_id >= get_page_id("weather01") and new_page_id <= get_page_id("weather05")) page_weather->execute(); - id: page_weather mode: restart then: - lambda: |- - const uint8_t page_index = current_page_id - ${PAGE_WEATHER01_ID}; + const uint8_t page_index = current_page_id - get_page_id("weather01"); if (page_index >= 5) { ESP_LOGW("${TAG_PAGE_WEATHER}", "Unexpected page_index: %" PRIu8, page_index); return; @@ -99,10 +94,10 @@ script: - id: theme_update_all_weather_icon then: - lambda: |- - if ( current_page_id >= ${PAGE_WEATHER01_ID} and current_page_id <= ${PAGE_WEATHER05_ID}) { + if ( current_page_id >= get_page_id("weather01") and current_page_id <= get_page_id("weather05")) { const uint8_t weather_icon_corrected = id(weather_icon) + ((current_theme == ThemeMode::LIGHT) ? ${THEME_DARK_PIC_PAGE_HOME_WEATHER_OFFSET} : 0); - ESP_LOGD("${TAG_PAGE_HOME}", "Update weather icon: %" PRIu8, weather_icon_corrected); + ESP_LOGD("${TAG_PAGE_WEATHER}", "Update weather icon: %" PRIu8, weather_icon_corrected); disp1->set_component_pic("weather_icon", weather_icon_corrected); } ... diff --git a/esphome/nspanel_esphome_version.yaml b/esphome/nspanel_esphome_version.yaml index 362837cd..a8621f95 100644 --- a/esphome/nspanel_esphome_version.yaml +++ b/esphome/nspanel_esphome_version.yaml @@ -11,7 +11,7 @@ substitutions: # Value is imported from versioning/version.yaml <<: !include ../versioning/version.yaml # Minimum required versions for compatibility - min_blueprint_version: 12 + min_blueprint_version: 13 min_tft_version: 13 min_esphome_compiler_version: 2026.1.0 TAG_VERSIONING: nspanel.versioning diff --git a/nspanel_easy_blueprint.yaml b/nspanel_easy_blueprint.yaml index 50c83e18..7a8a8c56 100644 --- a/nspanel_easy_blueprint.yaml +++ b/nspanel_easy_blueprint.yaml @@ -11,7 +11,7 @@ blueprint: description: > # NSPanel Easy Configuration via Blueprint - **Blueprint release**: 12 + **Blueprint release**: 13 This project enables comprehensive configuration of your NSPanel through a Blueprint featuring a user interface. @@ -4211,7 +4211,7 @@ trigger_variables: }} variables: - blueprint_version: 12 + blueprint_version: 13 pages: current: '{{ states(currentpage) }}' alarm: "alarm" @@ -7752,6 +7752,35 @@ actions: if nspanel_event is defined and nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 1 else (trigger.entity_id if trigger.entity_id is defined else trigger.event.data.entity_id) }} + - *variable_entity + - &entity_details_title_with_icon + alias: Fill title of entity details page + if: '{{ entity is defined }}' + then: + - if: + - '{{ entity.name is defined }}' + - '{{ entity.name is string }}' + - '{{ entity.name | length > 0 }}' + then: + - *delay_default + - action: 'esphome.{{ nspanel_name }}_component_text' + data: + page: "" + id: page_label + txt: '{{ entity.name }}' + continue_on_error: true + - if: + - '{{ entity.icon is defined }}' + - '{{ entity.icon is string }}' + - '{{ entity.icon | length > 0 }}' + then: + - *delay_default + - action: 'esphome.{{ nspanel_name }}_component_text' + data: + page: "" + id: icon_state + txt: '{{ entity.icon }}' + continue_on_error: true - &variables_light_modes variables: entity_id_valid: '{{ entity_id is defined and entity_id is string and entity_id.split(".") | count == 2 }}' @@ -7898,13 +7927,13 @@ actions: conditions: '{{ nspanel_event.page == pages.cover }}' sequence: &refresh_page_cover - variables: - cover_entity: > + entity_id: > {{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 1 else (trigger.entity_id if trigger.entity_id is defined else trigger.event.data.entity_id) }} - entity_device_class: '{{ state_attr(cover_entity, "device_class") | default("") }}' + entity_device_class: '{{ state_attr(entity_id, "device_class") | default("") }}' cover_icons: open: > {{ @@ -7928,6 +7957,8 @@ actions: device_class_icons.cover[entity_device_class ~ "-closed"] in all_icons else all_icons[device_class_icons.cover["shutter-closed"]] }} + - *variable_entity + - *entity_details_title_with_icon ##### Cover Open/close Icons ##### - *delay_default - action: 'esphome.{{ nspanel_name }}_component_text' @@ -7950,23 +7981,23 @@ actions: data: page: cover id: coverslider - val: '{{ (state_attr(cover_entity, "current_position") | int ) | round(0) }}' + val: '{{ (state_attr(entity_id, "current_position") | int ) | round(0) }}' continue_on_error: true - *delay_default - action: 'esphome.{{ nspanel_name }}_component_text' data: page: cover id: cover_value - txt: '{{ (state_attr(cover_entity, "current_position") | int ) | round(0) }} %' + txt: '{{ (state_attr(entity_id, "current_position") | int ) | round(0) }} %' continue_on_error: true ##### COVER Battery ICON Yes / NO ##### - variables: - battery_attribute: '{{ state_attr(cover_entity, "battery") | default("unavailable") }}' + battery_attribute: '{{ state_attr(entity_id, "battery") | default("unavailable") }}' battery_level: > {% if battery_attribute and battery_attribute not in enum.states.unknown %} {{ battery_attribute }} - {% elif expand(device_entities(device_id(cover_entity))) + {% elif expand(device_entities(device_id(entity_id))) | selectattr("attributes.device_class", "defined") | selectattr("attributes.device_class", "eq", "battery") | map(attribute="state") @@ -7974,7 +8005,7 @@ actions: | list | count > 0 %} {{ - expand(device_entities(device_id(cover_entity))) + expand(device_entities(device_id(entity_id))) | selectattr("attributes.device_class", "defined") | selectattr("attributes.device_class", "eq", "battery") | map(attribute="state") | map("float") @@ -7982,10 +8013,10 @@ actions: | first | round(0) }} - {% elif has_value(cover_entity | replace("cover.","sensor.") ~ "_battery") %} - {{ states(cover_entity | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} - {% elif has_value(cover_entity | replace("cover.","sensor.") | replace("cover", "battery")) %} - {{ states(cover_entity | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} + {% elif has_value(entity_id | replace("cover.","sensor.") ~ "_battery") %} + {{ states(entity_id | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} + {% elif has_value(entity_id | replace("cover.","sensor.") | replace("cover", "battery")) %} + {{ states(entity_id | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} {% else %} unavailable {% endif %} - if: '{{ is_number(battery_level) }}' @@ -8030,27 +8061,29 @@ actions: conditions: '{{ nspanel_event.page == pages.fan }}' sequence: &refresh_page_fan - variables: - fan_entity: > + entity_id: > {{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 1 else (trigger.entity_id if trigger.entity_id is defined else trigger.event.data.entity_id) }} fan: - supported_features: '{{ state_attr(fan_entity, "supported_features") | int(0) }}' + supported_features: '{{ state_attr(entity_id, "supported_features") | int(0) }}' percentage: > {{ - state_attr(fan_entity, "percentage") | int(0) - if is_state(fan_entity, 'on') + state_attr(entity_id, "percentage") | int(0) + if is_state(entity_id, 'on') else 0 }} steps: > - {% set percentage_step = state_attr(fan_entity, "percentage_step") | float(0) %} + {% set percentage_step = state_attr(entity_id, "percentage_step") | float(0) %} {{ (100/percentage_step) | round(0) | int(0) if percentage_step > 0 else 0 }} + - *variable_entity + - *entity_details_title_with_icon - if: '{{ fan.steps > 0 and fan.supported_features | bitwise_and(2) > 0 }}' # Oscillate then: - *delay_default @@ -8058,7 +8091,7 @@ actions: data: page: fan id: bt_oscillate - txt: '{{ all_icons["autorenew"] if state_attr(fan_entity, "oscillating") | default(false) else all_icons["autorenew-off"] }}' + txt: '{{ all_icons["autorenew"] if state_attr(entity_id, "oscillating") | default(false) else all_icons["autorenew-off"] }}' continue_on_error: true - *delay_default - action: 'esphome.{{ nspanel_name }}_component_color' @@ -8121,13 +8154,15 @@ actions: conditions: '{{ nspanel_event.page == pages.media_player }}' sequence: &refresh_page_media_player - variables: - media_player_entity: > + entity_id: > {{ nspanel_event.entity if nspanel_event is defined and nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 1 else (trigger.entity_id if trigger.entity_id is defined else trigger.event.data.entity_id) }} wait_completed: false + - *variable_entity + - *entity_details_title_with_icon - alias: Refresh page in a loop repeat: sequence: @@ -8145,28 +8180,27 @@ actions: milliseconds: '{{ media_player_update_delay }}' - variables: media_player: - state: '{{ states(media_player_entity) }}' - is_volume_muted: '{{ state_attr(media_player_entity, "is_volume_muted") | default(false) }}' - friendly_name: '{{ state_attr(media_player_entity, "friendly_name") | default("Media player") }}' - volume_level: '{{ (state_attr(media_player_entity, "volume_level") | round(2, default=0) * 100) | int(0) }}' - media_title: '{{ state_attr(media_player_entity, "media_title") }}' - media_artist: '{{ state_attr(media_player_entity, "media_artist") }}' - media_duration: '{{ state_attr(media_player_entity, "media_duration") | int(0) }}' - media_position: '{{ state_attr(media_player_entity, "media_position") | int(0) }}' - media_position_updated_at: '{{ state_attr(media_player_entity, "media_position_updated_at") | default(now()) }}' + state: '{{ states(entity_id) }}' + is_volume_muted: '{{ state_attr(entity_id, "is_volume_muted") | default(false) }}' + friendly_name: '{{ state_attr(entity_id, "friendly_name") | default("Media player") }}' + volume_level: '{{ (state_attr(entity_id, "volume_level") | round(2, default=0) * 100) | int(0) }}' + media_title: '{{ state_attr(entity_id, "media_title") }}' + media_artist: '{{ state_attr(entity_id, "media_artist") }}' + media_duration: '{{ state_attr(entity_id, "media_duration") | int(0) }}' + media_position: '{{ state_attr(entity_id, "media_position") | int(0) }}' + media_position_updated_at: '{{ state_attr(entity_id, "media_position_updated_at") | default(now()) }}' supported_features: > {{ (1+4+8+16+32+128+256+512+4096+16384) - if (state_attr(media_player_entity, "mass_player_type") | default("")) == "group" - else state_attr(media_player_entity, "supported_features") | int(0) + if (state_attr(entity_id, "mass_player_type") | default("")) == "group" + else state_attr(entity_id, "supported_features") | int(0) }} - *delay_default - action: 'esphome.{{ nspanel_name }}_page_media_player' data: - entity: '{{ media_player_entity }}' + entity: '{{ entity_id }}' state: '{{ media_player.state if media_player.state is string else "" }}' is_volume_muted: '{{ media_player.is_volume_muted if media_player.is_volume_muted is boolean else false }}' - friendly_name: '{{ media_player.friendly_name if media_player.friendly_name is string else "" }}' volume_level: '{{ media_player.volume_level }}' media_title: > {{ @@ -8237,8 +8271,9 @@ actions: - variables: entity_id: '{{ alarm_entity }}' supported_features: '{{ state_attr(entity_id, "supported_features") | default(0) }}' - - *variable_entity - condition: '{{ supported_features > 0 }}' + - *variable_entity + - *entity_details_title_with_icon - variables: # https://github.com/home-assistant/core/blob/dev/homeassistant/components/alarm_control_panel/const.py alarm: code_format: '{{ state_attr(entity_id, "code_format") }}' @@ -8246,7 +8281,6 @@ actions: - *delay_default - action: 'esphome.{{ nspanel_name }}_page_alarm' data: - page_title: '{{ entity.name }}' state: '{{ entity_state }}' supported_features: '{{ supported_features }}' code_format: '{{ alarm.code_format if alarm.code_format else "none" }}' @@ -8549,26 +8583,10 @@ actions: - '{{ entity_id.split(".")[0] in ["button", "input_button"] }}' - *variable_entity - condition: '{{ entity is defined }}' - - - if: '{{ entity.name is defined and entity.name is string and entity.name | length > 0 }}' - then: - - *delay_default - - action: 'esphome.{{ nspanel_name }}_component_text' - data: - page: "" - id: page_label - txt: '{{ entity.name }}' - continue_on_error: true + - *entity_details_title_with_icon - if: '{{ entity.icon is defined and entity.icon is string and entity.icon | length > 0 }}' then: - *delay_default - - action: 'esphome.{{ nspanel_name }}_component_text' - data: - page: "" - id: icon_state - txt: '{{ entity.icon }}' - continue_on_error: true - - *delay_default - action: 'esphome.{{ nspanel_name }}_component_text' data: page: "" @@ -8610,25 +8628,7 @@ actions: - '{{ entity_id.split(".")[0] in ["switch", "input_boolean"] }}' - *variable_entity - condition: '{{ entity is defined }}' - - - if: '{{ entity.name is defined and entity.name is string and entity.name | length > 0 }}' - then: - - *delay_default - - action: 'esphome.{{ nspanel_name }}_component_text' - data: - page: "" - id: page_label - txt: '{{ entity.name }}' - continue_on_error: true - - if: '{{ entity.icon is defined and entity.icon is string and entity.icon | length > 0 }}' - then: - - *delay_default - - action: 'esphome.{{ nspanel_name }}_component_text' - data: - page: "" - id: icon_state - txt: '{{ entity.icon }}' - continue_on_error: true + - *entity_details_title_with_icon - *delay_default - action: 'esphome.{{ nspanel_name }}_component_val' data: @@ -9818,15 +9818,6 @@ actions: entity: '{{ "embedded_climate" if entity_id == thermostat_embedded else entity_id }}' back_page: '{{ back_page }}' continue_on_error: true - - if: '{{ entity is defined and entity.icon is defined and entity.icon is string and entity.icon | length > 0 }}' - then: - - *delay_default - - action: 'esphome.{{ nspanel_name }}_component_text' - data: - page: "" - id: icon_state - txt: '{{ entity.icon }}' - continue_on_error: true - if: '{{ entity is defined and entity.name is defined and entity.name is string and entity.name | length > 0 }}' then: - *delay_default