From 067c1739955fce59feebd717c81d9f0522a1a00d Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Thu, 7 Sep 2023 00:32:20 +0200 Subject: [PATCH] Handle `embedded_indoor_temperature` Internal temperature display will be handled locally (ESPHome) when no other sensor is selected. --- nspanel_blueprint.yaml | 49 +++++++++++++++++++++++++----------------- nspanel_esphome.yaml | 49 +++++++++++++++++++++++++++++++++--------- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index db6dd66..62f8182 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -187,11 +187,13 @@ blueprint: *If no outdoor sensor is available, leave the field empty and the value from your selected weather integration will be used automatically* default: [] - selector: &entity_sensor-selector + selector: &entity_temp_sensor-selector entity: filter: domain: - sensor + device_class: + - temperature home_outdoor_temp_label_color: name: Outdoor Temperature Sensor - LABEL COLOR (Optional) description: > @@ -208,7 +210,7 @@ blueprint: *An indoor temperature sensor is not necessary. Leave the field empty if you want to use the temperature sensor of the NSPanel. Additionally a temperature correction for the NSPanel sensor is possible under HA Devices. So everyone can adjust the sensor exactly* default: [] - selector: *entity_sensor-selector + selector: *entity_temp_sensor-selector home_indoor_temp_icon: name: Indoor Temperature Sensor - ICON (Optional) description: > @@ -249,7 +251,11 @@ blueprint: *Entity which should be displayed* default: [] - selector: *entity_sensor-selector + selector: &entity_sensor-selector + entity: + filter: + domain: + - sensor home_value01_icon: name: Sensor 01 - ICON (Optional) description: > @@ -3532,7 +3538,7 @@ variables: notification_clear: 'esphome.{{ nspanel_name }}_notification_clear' #notification_show: 'esphome.{{ nspanel_name }}_notification_show' open_entity_settings_page: 'esphome.{{ nspanel_name }}_open_entity_settings_page' - page_home_settings: 'esphome.{{ nspanel_name }}_page_home_settings' + page_home: 'esphome.{{ nspanel_name }}_page_home' page_settings: 'esphome.{{ nspanel_name }}_page_settings' #play_rtttl: 'esphome.{{ nspanel_name }}_play_rtttl' printf: 'esphome.{{ nspanel_name }}_send_command_printf' @@ -5669,6 +5675,8 @@ variables: ##### GENERAL ENTITYS ##### climate: !input 'climate' embedded_climate: '{{ climate == thermostat_embedded }}' + indoor_temperature_sensor: !input 'indoortemp' + embedded_indoor_temperature: '{{ indoor_temperature_sensor == nspaneltemp or not (indoor_temperature_sensor is string and indoor_temperature_sensor is match "sensor.")}}' alarm: !input 'alarm' enum: @@ -6243,13 +6251,6 @@ trigger: entity_id: !input 'indoortemp' id: indoortemp_state - ##### NSPAnel Temp Sensor - Trigger 'nspaneltemp_state' ##### - - platform: event - event_type: state_changed - event_data: - entity_id: '{{ nspaneltemp }}' - id: nspaneltemp_state - ##### Trigger - Weather ################################################################################################################# #### Weather state changed ####### - platform: event @@ -6315,6 +6316,13 @@ condition: - climate_button08_state - climate_button09_state - '{{ page.current == page.climate }}' + - condition: or + conditions: + - condition: not + conditions: + - condition: trigger + id: indoortemp_state + - '{{ not embedded_indoor_temperature }}' ############################################################# ##### START - Action ##### @@ -6411,7 +6419,7 @@ action: format: !input 'time_format' color_rgb: !input 'time_label_color' - - service: '{{ nextion.command.page_home_settings }}' + - service: '{{ nextion.command.page_home }}' data: notification_icon: > {{ @@ -6518,6 +6526,8 @@ action: else ((display.time.color_rgb[0] //(2**3)) *(2**11))+((display.time.color_rgb[1] //(2**2)) *(2**5))+(display.time.color_rgb[2] //(2**3)) }} embedded_climate: '{{ embedded_climate }}' + embedded_indoor_temperature: '{{ embedded_indoor_temperature }}' + temperature_unit_is_fahrenheit: '{{ state_attr((nspaneltemp if embedded_indoor_temperature else indoor_temperature_sensor), "unit_of_measurement") | default("") in ["°F", "F"]}}' wakeup_page: '{{ wakeup_page }}' continue_on_error: true - *delay-default @@ -6629,21 +6639,20 @@ action: continue_on_error: true - &refresh-page_home-indoor_temp - if: '{{ true }}' + if: '{{ not embedded_indoor_temperature }}' then: ##### NSPanel Indoor Temp ##### - variables: - indoor_temp_entity: !input 'indoortemp' indoor_temp: - state: '{{ states(indoor_temp_entity, rounded=true) | default("unavailable") if indoor_temp_entity is string and indoor_temp_entity is match "sensor." else states(nspaneltemp, rounded=true) }}' + state: '{{ states(indoor_temperature_sensor, rounded=true) | default("unavailable") if indoor_temperature_sensor is string and indoor_temperature_sensor is match "sensor." else states(nspaneltemp, rounded=true) }}' units: > {{ - state_attr(indoor_temp_entity, "unit_of_measurement") | default(temperature_units) + state_attr(indoor_temperature_sensor, "unit_of_measurement") | default(temperature_units) if - indoor_temp_entity is string and - indoor_temp_entity is match "sensor." and - state_attr(indoor_temp_entity, "unit_of_measurement") is string and - state_attr(indoor_temp_entity, "unit_of_measurement") | length > 0 + indoor_temperature_sensor is string and + indoor_temperature_sensor is match "sensor." and + state_attr(indoor_temperature_sensor, "unit_of_measurement") is string and + state_attr(indoor_temperature_sensor, "unit_of_measurement") | length > 0 else ( state_attr(nspaneltemp, "unit_of_measurement") | default(temperature_units) diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 27ece33..e81721a 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -431,6 +431,8 @@ api: time_format: string time_color: int embedded_climate: bool + embedded_indoor_temperature: bool + temperature_unit_is_fahrenheit: bool wakeup_page: int then: - lambda: |- @@ -447,6 +449,8 @@ api: ESP_LOGV("service.global_settings", "time_format: %s", time_format.c_str()); ESP_LOGV("service.global_settings", "time_color: %i", time_color); ESP_LOGV("service.global_settings", "embedded_climate: %i", (embedded_climate) ? 1 : 0); + ESP_LOGV("service.global_settings", "embedded_indoor_temperature: %i", (embedded_indoor_temperature) ? 1 : 0); + ESP_LOGV("service.global_settings", "temperature_unit_is_fahrenheit: %i", (temperature_unit_is_fahrenheit) ? 1 : 0); ESP_LOGV("service.global_settings", "wakeup_page: %i", wakeup_page); // Blueprint version @@ -471,6 +475,11 @@ api: // Embedded thermostat id(addon_climate_global_settings)->execute(embedded_climate); + // Indoor temperature + id(embedded_indoor_temp) = embedded_indoor_temperature; + id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit; + id(display_embedded_temp)->execute(); + // Wakeup page ESP_LOGV("service.global_settings", "Wakeup page - Start"); id(wakeup_page_id) = wakeup_page; @@ -521,7 +530,7 @@ api: - lambda: ESP_LOGV("service.global_settings", "Finished"); #### Service to populate the page Home ##### - - service: page_home_settings + - service: page_home variables: notification_icon: string notification_icon_color_normal: int[] @@ -731,6 +740,17 @@ globals: restore_value: true initial_value: '0.0' + ##### Temperature unit ##### + ##### Is embedded sensor used for indoor temperature? ##### + - id: embedded_indoor_temp + type: bool + restore_value: true + initial_value: 'true' + - id: temp_unit_fahrenheit + type: bool + restore_value: true + initial_value: 'false' + ##### Date/time formats ##### #- id: mui_date_format # type: std::string @@ -977,14 +997,7 @@ sensor: on_value: then: # Show panel's temperature if API or Wi-Fi are out - - if: - condition: - - not: - - and: - - api.connected: - - wifi.connected: - then: - - lambda: id(disp1).set_component_text_printf("home.current_temp", "%.1f°", id(temp_nspanel).state); + - lambda: id(display_embedded_temp)->execute(); ###### Display Brightness GET VALUE FROM NSPanel SLIDER ##### - name: ${device_name} brightness Slider @@ -1498,7 +1511,7 @@ display: uart_id: tf_uart tft_url: ${nextion_update_url} on_page: # I couldn't make this trigger to work, so used text_sensor nspanelevent and localevent instead - - logger.log: "NEXTION PAGE CHANGED" + - lambda: ESP_LOGW("display.disp1", "NEXTION PAGE CHANGED"); on_setup: then: - lambda: |- @@ -2022,6 +2035,22 @@ script: ESP_LOGV("script.display_wrapped_text", "text (new): %s", wrappedText.c_str()); id(disp1).set_component_text_printf(component.c_str(), "%s", wrappedText.c_str()); + - id: display_embedded_temp + mode: restart + then: + - if: + condition: + - or: + - lambda: return id(embedded_indoor_temp); + - not: + - api.connected: + - not: + - wifi.connected: + then: + - lambda: |- + if (id(temp_unit_fahrenheit)) id(disp1).set_component_text_printf("home.current_temp", "%.0f°F", ((id(temp_nspanel).state * 9.0 / 5.0) + 32.0)); // °F = (°C × 9/5) + 32 + else id(disp1).set_component_text_printf("home.current_temp", "%.1f°C", id(temp_nspanel).state); + - id: check_versions mode: restart then: