From 642a78364a1f857a9ca88206b4b01e4eaddbba91 Mon Sep 17 00:00:00 2001 From: deejaybeam Date: Fri, 14 Apr 2023 23:22:19 +0200 Subject: [PATCH] upd: set_entity-service --- nspanel_blueprint.yaml | 25 +++++++------------------ nspanel_esphome.yaml | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 4f2dd5f..03b6e46 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -2383,6 +2383,7 @@ variables: show_all: "esphome.{{ nspanel_name }}_send_command_show_all" tft_upload: "esphome.{{ nspanel_name }}_upload_tft" set_button: "esphome.{{ nspanel_name }}_set_button" + set_entity: "esphome.{{ nspanel_name }}_set_entity" icons: battery: "\U0000F2A1" #F2A1 blank: "\U0000FFFF" #blank macbook bug @@ -4815,30 +4816,18 @@ action: {% if repeat.item.icon is string and repeat.item.icon | length > 0 %}{{ nextion.icons.all[repeat.item.icon.split(':')[1]] | default(repeat.item.icon) }} {% elif state_attr(repeat.item.entity, 'icon') | default('') not in ['unavailable', 'unknown', '', None] %}{{ nextion.icons.all[state_attr(repeat.item.entity, 'icon').split(':')[1]] | default(None) }} {% endif %} - - if: "{{ repeat_item_icon is string and repeat_item_icon | length > 0 }}" - then: - - *delay-default - - service: "{{ nextion.commands.text_printf }}" - data: - component: "{{ repeat.item.component }}_pic" - message: "{{ repeat_item_icon }}" - continue_on_error: true - - *delay-default - - service: "{{ nextion.commands.text_printf }}" + - service: "{{ nextion.commands.set_entity }}" data: - component: "{{ repeat.item.component }}_label" - message: >- + ent_id: "{{ repeat.item.component }}" + ent_icon: "{{ repeat_item_icon }}" + ent_label: >- {%- if repeat.item.name | length > 0 -%} {{ repeat.item.name }} {%- elif repeat_item_state in ['unavailable', 'unknown', None] -%} {{ repeat.item.entity }} {%- else -%} {{ state_attr(repeat.item.entity, 'friendly_name') | default(mui[language].no_name) }} {%- endif -%} + ent_value: "{{ repeat_item_state ~ ((state_attr(repeat.item.entity, 'unit_of_measurement') | default('')) if state_attr(repeat.item.entity, 'unit_of_measurement') else '') }}" continue_on_error: true - - *delay-default - - service: "{{ nextion.commands.text_printf }}" - data: - component: "{{ repeat.item.component }}" - message: "{{ repeat_item_state ~ ((state_attr(repeat.item.entity, 'unit_of_measurement') | default('')) if state_attr(repeat.item.entity, 'unit_of_measurement') else '') }}" - continue_on_error: true + ## PAGE CLIMATE ## - alias: Climate page diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 6ccc2ea..b257aa2 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -355,6 +355,26 @@ api: } else { id(disp1).set_component_text_printf(btnbri.c_str(), " "); } + #### Service to set the entities #### + - service: set_entity + variables: + ent_id: string + ent_icon: string + ent_label: string + ent_value: string + then: + - wait_until: + switch.is_on: nextion_init + - lambda: |- + // ESP_LOGD("nextion", "set entity %s", ent_id.c_str()); + std::string enticon = ent_id.c_str() + std::string("_pic"); + std::string entlabel = ent_id.c_str() + std::string("_label"); + id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); + if (strcmp(ent_icon.c_str(), "0") != 0) { + id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str()); + } + id(disp1).set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str()); + id(disp1).set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str()); ##### START - GLOBALS CONFIGURATION ##### globals: