From fb09556f7c166df04b006ef1a2852fe3b597318c Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:10:59 +0100 Subject: [PATCH] Use `state_translated` from HA v2023.3.0 Solves #1777 --- esphome/nspanel_esphome_core.yaml | 9 ++++----- nspanel_blueprint.yaml | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 4204569..8f849cf 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -52,7 +52,7 @@ esphome: - priority: 600.0 # This is where most sensors are set up. then: - lambda: |- - blueprint_status->publish_state(0); + if (isnan(blueprint_status->raw_state)) blueprint_status->publish_state(0); std::string s = "${device_name}"; std::string result; bool last_was_underscore = false; @@ -470,7 +470,6 @@ api: disp1->set_component_font_color("home.bt_qrcode", esphome::display::ColorUtil::color_to_565(esphome::Color(qrcode_icon_color[0], qrcode_icon_color[1], qrcode_icon_color[2]))); // Entities pages button - disp1->send_command_printf("is_entities=%i", entities_pages ? 1 : 0); disp1->set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str()); disp1->set_component_font_color("home.bt_entities", esphome::display::ColorUtil::color_to_565(esphome::Color(entities_pages_icon_color[0], entities_pages_icon_color[1], @@ -1390,8 +1389,8 @@ sensor: # 6 # reserved # # 7 # reserved # ############################## - - name: Blueprint - id: blueprint_status + - id: blueprint_status + name: Blueprint platform: template unit_of_measurement: "%" accuracy_decimals: 1 @@ -1401,7 +1400,7 @@ sensor: disabled_by_default: false filters: - lambda: |- - if (isnan(x) and x>0) + if (!isnan(x) and x>0) return (x / 62) * 100.0f; else return 0; diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 8734afb..c845e15 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -41,7 +41,7 @@ blueprint: source_url: https://github.com/Blackymas/NSPanel_HA_Blueprint/blob/main/nspanel_blueprint.yaml domain: automation homeassistant: - min_version: 2023.12.0 + min_version: 2024.3.0 # yamllint disable rule:indentation rule:comments-indentation input: @@ -7672,14 +7672,6 @@ action: entity_friendly_name: '{{ state_attr(entity_id, "friendly_name") | default("") if entity_id_valid }}' entity_device_class: '{{ state_attr(entity_id, "device_class") | default("") if entity_id_valid }}' entity: - state_mui: > - {{ - ( - entity_state - if entity_domain != "alarm_control_panel" - else ( mui[language].alarm[entity_state | replace("armed_", "") | replace("disarmed", "disarm")] | default(entity_state) if entity_state else "unknown" ) - ) if entity_id_valid - }} name: > {{ ( @@ -8509,7 +8501,11 @@ action: name: "" value: > {{ - (states(entity_id, rounded=true) ~ unit_of_measurement) + ( + (states(entity_id, rounded=true) ~ unit_of_measurement) + if is_number(entity_state) + else state_translated(entity_id) + ) if entity_has_value else mui[language].unavailable }} @@ -9311,8 +9307,12 @@ action: name: '{{ entity.name }}' value: > {{ - (states(entity_id, rounded=true) ~ (unit_of_measurement if unit_of_measurement and unit_of_measurement is string and unit_of_measurement | length > 0 else "")) - if has_value(entity_id) + ( + (states(entity_id, rounded=true) ~ unit_of_measurement) + if is_number(entity_state) + else state_translated(entity_id) + ) + if entity_has_value else mui[language].unavailable }} value_color: []