From 6dd4733b4b861138ebf400041921fbdc115d4626 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Tue, 16 Jan 2024 08:42:14 +0100 Subject: [PATCH] Rebuild Embedded Climate page constructor Partially solves #1613 Partially solves #1627 --- .../nspanel_esphome_addon_climate_base.yaml | 99 +++++++++---------- .../nspanel_esphome_addon_upload_tft.yaml | 6 +- .../esphome/nspanel_esphome_advanced.yaml | 18 ++-- advanced/esphome/nspanel_esphome_core.yaml | 80 +++++++-------- .../esphome/nspanel_esphome_prebuilt.yaml | 2 +- 5 files changed, 99 insertions(+), 106 deletions(-) diff --git a/advanced/esphome/nspanel_esphome_addon_climate_base.yaml b/advanced/esphome/nspanel_esphome_addon_climate_base.yaml index 46768a6..0801a63 100644 --- a/advanced/esphome/nspanel_esphome_addon_climate_base.yaml +++ b/advanced/esphome/nspanel_esphome_addon_climate_base.yaml @@ -34,7 +34,7 @@ substitutions: climate: - platform: thermostat - name: ${device_name} Thermostat + name: ${name} Thermostat id: thermostat_embedded sensor: temp_nspanel min_idle_time: ${min_idle_time}s @@ -67,11 +67,11 @@ globals: - id: addon_climate_friendly_name type: std::string restore_value: false - initial_value: '"${device_name} Thermostat"' + initial_value: '"${name} Thermostat"' switch: ##### PHYSICAL SWITCH 0 (Dummy) - Used when relay is not set ##### - - name: ${device_name} Relay 0 (dummy) + - name: ${name} Relay 0 (dummy) platform: template id: relay_0 lambda: !lambda return false; @@ -105,61 +105,52 @@ script: - id: !extend page_climate then: - lambda: |- - static const char *const TAG = "addon_climate_base.script.page_climate"; - ESP_LOGD(TAG, "Climate page constructor:"); - ESP_LOGD(TAG, " Current page: %s", current_page->state.c_str()); - ESP_LOGD(TAG, " Detailed entity: %s", detailed_entity->state.c_str()); - ESP_LOGD(TAG, " Embedded climate: %s", id(is_addon_climate_visible) ? "True" : "False"); - if (current_page->state == "climate" and id(is_addon_climate_visible)) - { - ESP_LOGD(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown"))); - ESP_LOGV(TAG, " Page label: %s", id(addon_climate_friendly_name).c_str()); - disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str()); - float temp_step = ${temp_step}; - float temp_offset = ${temp_min}; - float temp_max = ${temp_max}; - float total_steps = (temp_max-temp_offset)/temp_step; - set_climate->execute - ( - thermostat_embedded->current_temperature, // current_temp - 0, // supported_features - thermostat_embedded->target_temperature, // target_temp - thermostat_embedded->target_temperature_high, // target_temp_high - thermostat_embedded->target_temperature_low, // target_temp_low - int(round(${temp_step}*10)), // temp_step - int(round(total_steps)), // total_steps //int(round((10*thermostat_embedded->target_temperature-temp_offset)/temp_step)), // slider_val - int(round(${temp_min}*10)), // temp_offset - "", // climate_icon - true // embedded_climate - ); + id(is_addon_climate_visible) = (current_page->state == "climate" and detailed_entity->state == "embedded_climate"); + if (id(is_addon_climate_visible)) { + static const char *const TAG = "addon_climate_base.script.page_climate"; + ESP_LOGV(TAG, "Climate page constructor:"); + ESP_LOGV(TAG, " Add-on mode: %s", (${addon_climate_dual}) ? "Dual" : ((${addon_climate_heat}) ? "Heat" : ((${addon_climate_cool}) ? "Cool" : "Unknown"))); + disp1->set_component_text_printf("page_label", id(addon_climate_friendly_name).c_str()); + float temp_step = ${temp_step}; + float temp_offset = ${temp_min}; + float temp_max = ${temp_max}; + float total_steps = (temp_max-temp_offset)/temp_step; + set_climate->execute + ( + thermostat_embedded->current_temperature, // current_temp + 0, // supported_features + thermostat_embedded->target_temperature, // target_temp + thermostat_embedded->target_temperature_high, // target_temp_high + thermostat_embedded->target_temperature_low, // target_temp_low + int(round(${temp_step}*10)), // temp_step + int(round(total_steps)), // total_steps //int(round((10*thermostat_embedded->target_temperature-temp_offset)/temp_step)), // slider_val + int(round(${temp_min}*10)), // temp_offset + "", // climate_icon + true // embedded_climate + ); - // Update target temp icon - update_climate_icon->execute("target_icon", int(thermostat_embedded->action), int(thermostat_embedded->mode)); + // Update target temp icon + update_climate_icon->execute("target_icon", int(thermostat_embedded->action), int(thermostat_embedded->mode)); - // Update buttons bar - // Hide not supported hotspots - disp1->hide_component("button01"); - if (${addon_climate_dual}) disp1->show_component("button02"); else disp1->hide_component("button02"); - if (${addon_climate_heat} or ${addon_climate_dual}) disp1->show_component("button03"); else disp1->hide_component("button03"); //Heat - if (${addon_climate_cool} or ${addon_climate_dual}) disp1->show_component("button04"); else disp1->hide_component("button04"); //Cool - disp1->hide_component("button05"); - disp1->hide_component("button06"); - disp1->show_component("button07"); //Off - // Set buttons colors - disp1->set_component_font_color("button01", 6339); - disp1->set_component_font_color("button02", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? 65535 : ((${addon_climate_dual}) ? 48631 : 6339)); - disp1->set_component_font_color("button03", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? 64164 : ((${addon_climate_heat} or ${addon_climate_dual}) ? 48631 : 6339)); - disp1->set_component_font_color("button04", (thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? 1055 : ((${addon_climate_cool} or ${addon_climate_dual}) ? 48631 : 6339)); - disp1->set_component_font_color("button05", 6339); - disp1->set_component_font_color("button06", 6339); - disp1->set_component_font_color("button07", (thermostat_embedded->mode==climate::CLIMATE_MODE_OFF) ? 10597 : 35921); + // Update buttons bar + // Hide not supported hotspots + disp1->hide_component("button01"); + if (${addon_climate_dual}) disp1->show_component("button02"); else disp1->hide_component("button02"); + if (${addon_climate_heat} or ${addon_climate_dual}) disp1->show_component("button03"); else disp1->hide_component("button03"); //Heat + if (${addon_climate_cool} or ${addon_climate_dual}) disp1->show_component("button04"); else disp1->hide_component("button04"); //Cool + disp1->hide_component("button05"); + disp1->hide_component("button06"); + disp1->show_component("button07"); //Off + // Set buttons colors + disp1->set_component_font_color("button01", 6339); + disp1->set_component_font_color("button02", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT_COOL) ? 65535 : ((${addon_climate_dual}) ? 48631 : 6339)); + disp1->set_component_font_color("button03", (thermostat_embedded->mode==climate::CLIMATE_MODE_HEAT) ? 64164 : ((${addon_climate_heat} or ${addon_climate_dual}) ? 48631 : 6339)); + disp1->set_component_font_color("button04", (thermostat_embedded->mode==climate::CLIMATE_MODE_COOL) ? 1055 : ((${addon_climate_cool} or ${addon_climate_dual}) ? 48631 : 6339)); + disp1->set_component_font_color("button05", 6339); + disp1->set_component_font_color("button06", 6339); + disp1->set_component_font_color("button07", (thermostat_embedded->mode==climate::CLIMATE_MODE_OFF) ? 10597 : 35921); } - - id: !extend page_changed - then: - - lambda: |- - id(is_addon_climate_visible) = (page == "climate" and detailed_entity->state == "embedded_climate"); - - id: !extend page_home then: - lambda: |- diff --git a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml index 78dfd01..0e3b630 100644 --- a/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml +++ b/advanced/esphome/nspanel_esphome_addon_upload_tft.yaml @@ -50,7 +50,7 @@ api: button: ##### UPDATE TFT DISPLAY ##### - id: tft_update - name: ${device_name} Update TFT display + name: ${name} Update TFT display platform: template icon: mdi:file-sync entity_category: config @@ -579,7 +579,7 @@ script: select: - id: tft_file_branch - name: ${device_name} Update TFT display - Branch + name: ${name} Update TFT display - Branch platform: template options: - "main" @@ -596,7 +596,7 @@ select: - script.execute: set_tft_file - id: tft_file_model - name: ${device_name} Update TFT display - Model + name: ${name} Update TFT display - Model platform: template options: - "Use nextion_update_url" diff --git a/advanced/esphome/nspanel_esphome_advanced.yaml b/advanced/esphome/nspanel_esphome_advanced.yaml index 4ccd4b6..1b8786f 100644 --- a/advanced/esphome/nspanel_esphome_advanced.yaml +++ b/advanced/esphome/nspanel_esphome_advanced.yaml @@ -16,7 +16,7 @@ substitutions: button: ##### EXIT REPARSE TFT DISPLAY ##### - - name: ${device_name} Exit reparse + - name: ${name} Exit reparse platform: template icon: mdi:file-sync id: tft_reparse_off @@ -26,7 +26,7 @@ button: - script.execute: exit_reparse ##### UPDATE TFT BLANK DISPLAY ##### - - name: ${device_name} Update TFT display (blank) + - name: ${name} Update TFT display (blank) platform: template icon: mdi:file-sync id: tft_update_blank @@ -41,12 +41,12 @@ captive_portal: sensor: ##### Uptime Sensors ##### - - name: ${device_name} Uptime seconds + - name: ${name} Uptime seconds id: uptime_sec platform: uptime internal: true - - name: ${device_name} API uptime + - name: ${name} API uptime id: api_timestamp platform: template lambda: 'return id(time_provider).now().timestamp;' @@ -56,7 +56,7 @@ sensor: accuracy_decimals: 0 update_interval: never - - name: ${device_name} Device uptime + - name: ${name} Device uptime id: device_timestamp platform: template lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);' @@ -68,20 +68,20 @@ sensor: text_sensor: ##### ESPhome version used to compile the app ##### - - name: ${device_name} ESPhome Version + - name: ${name} ESPhome Version platform: version disabled_by_default: true - platform: wifi_info ip_address: - name: ${device_name} IP + name: ${name} IP disabled_by_default: true id: ip_address ssid: - name: ${device_name} SSID + name: ${name} SSID disabled_by_default: true bssid: - name: ${device_name} BSSID + name: ${name} BSSID disabled_by_default: true time: diff --git a/advanced/esphome/nspanel_esphome_core.yaml b/advanced/esphome/nspanel_esphome_core.yaml index 74460c6..7732914 100644 --- a/advanced/esphome/nspanel_esphome_core.yaml +++ b/advanced/esphome/nspanel_esphome_core.yaml @@ -13,6 +13,8 @@ substitutions: invalid_cooldown: "100ms" ota_password: ${wifi_password} ap_password: ${wifi_password} + device_name: NSPanel + name: ${device_name} ##### DON'T CHANGE THIS ###### version: "4.2.2dev" ############################## @@ -26,7 +28,7 @@ external_components: ##### ESPHOME CONFIGURATION ##### esphome: - name: ${device_name} + name: ${name} min_version: 2023.12.0 platformio_options: build_flags: @@ -53,7 +55,7 @@ wifi: ssid: ${wifi_ssid} password: ${wifi_password} ap: - ssid: "${device_name}" + ssid: "${name}" password: ${ap_password} on_connect: then: @@ -956,7 +958,7 @@ globals: binary_sensor: ###### LEFT BUTTON BELOW DISPLAY TO TOGGLE RELAY##### - - name: ${device_name} Left Button + - name: ${name} Left Button platform: gpio id: left_button pin: @@ -1009,7 +1011,7 @@ binary_sensor: - script.execute: setup_sequence ##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY ##### - - name: ${device_name} Right Button + - name: ${name} Right Button platform: gpio id: right_button pin: @@ -1053,7 +1055,7 @@ binary_sensor: - button.press: restart_nspanel ##### Restart NSPanel Button - Setting Page ##### - - name: ${device_name} Restart + - name: ${name} Restart platform: nextion page_id: 7 component_id: 9 @@ -1061,7 +1063,7 @@ binary_sensor: on_click: - button.press: restart_nspanel ##### Restart NSPanel Button - Boot Page ##### - - name: ${device_name} Restart + - name: ${name} Restart platform: nextion page_id: 8 component_id: 4 @@ -1070,7 +1072,7 @@ binary_sensor: - button.press: restart_nspanel ## Delays initial info from HA to the display ##### - - name: ${device_name} Nextion display + - name: ${name} Nextion display id: nextion_init platform: template device_class: connectivity @@ -1079,7 +1081,7 @@ binary_sensor: icon: mdi:tablet-dashboard ##### API connection status - - name: ${device_name} Status + - name: ${name} Status platform: status id: api_status on_state: @@ -1089,14 +1091,14 @@ binary_sensor: ##### START - BUTTON CONFIGURATION ##### button: ###### REBOOT BUTTON ##### - - name: ${device_name} Restart + - name: ${name} Restart platform: restart id: restart_nspanel ##### START - NUMBER CONFIGURATION ##### number: ##### SCREEN BRIGHTNESS ##### - - name: ${device_name} Display Brightness + - name: ${name} Display Brightness id: display_brightness platform: template entity_category: config @@ -1122,7 +1124,7 @@ number: } ##### SCREEN BRIGHTNESS DIMMED DOWN ##### - - name: ${device_name} Display Brightness Dimdown + - name: ${name} Display Brightness Dimdown id: display_dim_brightness platform: template entity_category: config @@ -1147,7 +1149,7 @@ number: } ##### SCREEN BRIGHTNESS SLEEP ##### - - name: ${device_name} Display Brightness Sleep + - name: ${name} Display Brightness Sleep id: display_sleep_brightness platform: template entity_category: config @@ -1166,7 +1168,7 @@ number: page_screensaver->execute(); ##### Temperature Correction ##### - - name: ${device_name} Temperature Correction + - name: ${name} Temperature Correction platform: template id: temperature_correction entity_category: config @@ -1185,7 +1187,7 @@ number: - lambda: temp_nspanel->publish_state(temp_nspanel->raw_state); ##### Timers settings ##### - - name: ${device_name} Timeout Page + - name: ${name} Timeout Page platform: template id: timeout_page entity_category: config @@ -1199,7 +1201,7 @@ number: unit_of_measurement: "s" set_action: - lambda: timer_page->execute(current_page->state.c_str(), int(x)); - - name: ${device_name} Timeout Dimming + - name: ${name} Timeout Dimming platform: template id: timeout_dim entity_category: config @@ -1213,7 +1215,7 @@ number: unit_of_measurement: "s" set_action: - lambda: timer_dim->execute(current_page->state.c_str(), int(x)); - - name: ${device_name} Timeout Sleep + - name: ${name} Timeout Sleep platform: template id: timeout_sleep entity_category: config @@ -1233,7 +1235,7 @@ number: ##### START - SELECT CONFIGURATION ##### select: - id: baud_rate - name: ${device_name} Baud rate + name: ${name} Baud rate platform: template options: - "2400" @@ -1260,7 +1262,7 @@ select: - lambda: set_baud_rate->execute(stoi(x), true); - id: wakeup_page_name - name: ${device_name} Wake-up page + name: ${name} Wake-up page platform: template options: - buttonpage01 @@ -1306,7 +1308,7 @@ sensor: ##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) ##### - id: temp_nspanel - name: ${device_name} Temperature + name: ${name} Temperature platform: ntc sensor: resistance_sensor unit_of_measurement: ${temp_units} @@ -1328,7 +1330,7 @@ sensor: ###### Display Brightness GET VALUE FROM NSPanel SLIDER ##### - id: brightslider - name: ${device_name} brightness Slider + name: ${name} brightness Slider platform: nextion variable_name: brightslider internal: true @@ -1342,7 +1344,7 @@ sensor: ###### Display DIM Brightness GET VALUE FROM NSPanel SLIDER ##### - id: dimslider - name: ${device_name} dim brightness slider + name: ${name} dim brightness slider platform: nextion variable_name: dimslider internal: true @@ -1355,7 +1357,7 @@ sensor: timer_reset_all->execute("settings"); - id: page_id - name: ${device_name} Page Id + name: ${name} Page Id platform: nextion variable_name: dp precision: 0 @@ -1377,7 +1379,7 @@ sensor: ##### Display mode (1 = EU, 2 = US, 3 = US Landscape) - id: display_mode - name: ${device_name} Display mode + name: ${name} Display mode platform: nextion variable_name: display_mode precision: 0 @@ -1385,7 +1387,7 @@ sensor: entity_category: diagnostic ##### Charset (1 = International (original), 2 = CJK languages) - - name: ${device_name} Display charset + - name: ${name} Display charset id: display_charset platform: nextion variable_name: charset @@ -1394,7 +1396,7 @@ sensor: entity_category: diagnostic ##### WIFI Signal stregth - - name: ${device_name} RSSI + - name: ${name} RSSI id: wifi_rssi platform: wifi_signal internal: false @@ -1405,7 +1407,7 @@ sensor: switch: ##### Notification unread ##### - - name: ${device_name} Notification unread + - name: ${name} Notification unread platform: template id: notification_unread entity_category: config @@ -1423,7 +1425,7 @@ switch: - lambda: set_component_color->execute("home.bt_notific", id(home_notify_icon_color_normal)); ##### Notification sound ##### - - name: ${device_name} Notification sound + - name: ${name} Notification sound platform: template id: notification_sound entity_category: config @@ -1431,7 +1433,7 @@ switch: restore_mode: RESTORE_DEFAULT_OFF ##### PHYSICAL SWITCH 1 ##### - - name: ${device_name} Relay 1 + - name: ${name} Relay 1 platform: gpio id: relay_1 pin: @@ -1444,7 +1446,7 @@ switch: then: - script.execute: refresh_relays ##### PHYSICAL SWITCH 2 ###### - - name: ${device_name} Relay 2 + - name: ${name} Relay 2 platform: gpio id: relay_2 pin: @@ -1458,7 +1460,7 @@ switch: - script.execute: refresh_relays ##### DISPLAY ALWAYS ON ##### - - name: ${device_name} Nextion display - Power + - name: ${name} Nextion display - Power platform: gpio id: screen_power entity_category: diagnostic @@ -1483,7 +1485,7 @@ switch: nextion_init->publish_state(false); ##### Relay Local control ##### - - name: ${device_name} Relay 1 Local + - name: ${name} Relay 1 Local platform: template id: relay1_local entity_category: config @@ -1494,7 +1496,7 @@ switch: - logger.log: "Relay 1 Local turned On!" on_turn_off: - logger.log: "Relay 1 Local turned Off!" - - name: ${device_name} Relay 2 Local + - name: ${name} Relay 2 Local platform: template id: relay2_local entity_category: config @@ -1510,7 +1512,7 @@ switch: text_sensor: ##### Entity Id of the entity displayed on the detailed pages - - name: ${device_name} Detailed Entity + - name: ${name} Detailed Entity id: detailed_entity platform: template icon: mdi:tablet-dashboard @@ -1518,23 +1520,23 @@ text_sensor: disabled_by_default: false ##### Current page name ##### - - name: ${device_name} Current page + - name: ${name} Current page id: current_page platform: template icon: mdi:tablet-dashboard internal: false disabled_by_default: false - - name: ${device_name} Notification Label + - name: ${name} Notification Label platform: template id: notification_label - - name: ${device_name} Notification Text + - name: ${name} Notification Text platform: template id: notification_text ##### NSPanel event sensor, the main action sensor - push to HA ##### - - name: ${device_name} NSPanel event + - name: ${name} NSPanel event platform: nextion nextion_id: disp1 id: disp1_nspanel_event @@ -1572,7 +1574,7 @@ text_sensor: }); ##### NSPanel event - Execute actions from ESPHome - NO push to HA ##### - - name: ${device_name} NSPanel local event + - name: ${name} NSPanel local event platform: nextion nextion_id: disp1 id: disp1_local_event @@ -1673,7 +1675,7 @@ text_sensor: } - id: version_tft - name: ${device_name} TFT version + name: ${name} TFT version platform: nextion component_name: tft_version entity_category: diagnostic diff --git a/advanced/esphome/nspanel_esphome_prebuilt.yaml b/advanced/esphome/nspanel_esphome_prebuilt.yaml index 0ae54b0..d2d981b 100644 --- a/advanced/esphome/nspanel_esphome_prebuilt.yaml +++ b/advanced/esphome/nspanel_esphome_prebuilt.yaml @@ -93,7 +93,7 @@ logger: ota: id: my_ota - password: "" + password: !remove ota_http: