From df0855862f70629a97edc5354c2e0e5f8f39add8 Mon Sep 17 00:00:00 2001 From: deejaybeam Date: Fri, 31 Mar 2023 23:23:43 +0200 Subject: [PATCH] upd: service set_button to improve performance --- nspanel_blueprint.yaml | 178 ++++++++++++++++++++++------------------- nspanel_esphome.yaml | 35 ++++++++ 2 files changed, 131 insertions(+), 82 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 8bf0a9b..b39c408 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -2424,6 +2424,7 @@ variables: command_play_rtttl: "esphome.{{ nspanel_name }}_play_rtttl" command_set_settings_entity: "esphome.{{ nspanel_name }}_set_settings_entity" command_show_all: "esphome.{{ nspanel_name }}_send_command_show_all" + command_set_button: "esphome.{{ nspanel_name }}_set_button" ###### SYNC SETTINGS ##### delay_boot: !input "delay" @@ -4829,91 +4830,104 @@ action: {%- else -%} 0 {%- endif -%} - ##### SET Buttons Background #### - # - ##### SET Button PIC ##### - - service: "{{ command_printf }}" - data: - cmd: "{{ repeat.item.button }}pic.pic={{ btn_pic }}" - ##### SET ICON Background ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_background_color }}" - data: - component: "{{ repeat.item.button }}icon" - message: "{{ btn_bg }}" - ##### SET LABEL Background ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_background_color }}" - data: - component: "{{ repeat.item.button }}text" - message: "{{ btn_bg }}" - ##### SET BRIGHTNESS Background Color ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_background_color }}" - data: - component: "{{ repeat.item.button }}bri" - message: "{{ btn_bg }}" + # ##### SET Buttons Background #### + # # + # ##### SET Button PIC ##### + # - service: "{{ command_printf }}" + # data: + # cmd: "{{ repeat.item.button }}pic.pic={{ btn_pic }}" + # ##### SET ICON Background ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_background_color }}" + # data: + # component: "{{ repeat.item.button }}icon" + # message: "{{ btn_bg }}" + # ##### SET LABEL Background ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_background_color }}" + # data: + # component: "{{ repeat.item.button }}text" + # message: "{{ btn_bg }}" + # ##### SET BRIGHTNESS Background Color ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_background_color }}" + # data: + # component: "{{ repeat.item.button }}bri" + # message: "{{ btn_bg }}" - ##### SET Buttons Font Color #### - # - ##### SET ICON Font Color ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_font_color }}" - data: - component: "{{ repeat.item.button }}icon" - message: "{{ btn_icon_font }}" - ##### SET LABEL Font Color ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_font_color }}" - data: - component: "{{ repeat.item.button }}text" - message: "{{ btn_txt_font }}" - ##### SET BRIGHTNESS Font Color ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_font_color }}" - data: - component: "{{ repeat.item.button }}bri" - message: "{{ btn_bri_font }}" + # ##### SET Buttons Font Color #### + # # + # ##### SET ICON Font Color ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_font_color }}" + # data: + # component: "{{ repeat.item.button }}icon" + # message: "{{ btn_icon_font }}" + # ##### SET LABEL Font Color ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_font_color }}" + # data: + # component: "{{ repeat.item.button }}text" + # message: "{{ btn_txt_font }}" + # ##### SET BRIGHTNESS Font Color ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_font_color }}" + # data: + # component: "{{ repeat.item.button }}bri" + # message: "{{ btn_bri_font }}" - ##### SET Buttons Text Value #### - # - ##### "ICON" Value ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_text_printf }}" - data: - component: "{{ repeat.item.button }}icon" - message: "{{ btn_icon }}" - ##### "LABEL" Value ##### - - delay: - milliseconds: "{{ delay_value }}" - - service: "{{ command_text_printf }}" - data: - component: "{{ repeat.item.button }}text" - message: "{{ btn_label }}" + # ##### SET Buttons Text Value #### + # # + # ##### "ICON" Value ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_text_printf }}" + # data: + # component: "{{ repeat.item.button }}icon" + # message: "{{ btn_icon }}" + # ##### "LABEL" Value ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - service: "{{ command_text_printf }}" + # data: + # component: "{{ repeat.item.button }}text" + # message: "{{ btn_label }}" + + # ##### "BRIGHTNESS" Value ##### + # - delay: + # milliseconds: "{{ delay_value }}" + # - if: + # - condition: template + # value_template: "{{ btn_bri_txt == 0 }}" + # then: + # - service: "{{ command_text_printf }}" + # data: + # component: "{{ repeat.item.button }}bri" + # message: " " + # else: + # - service: "{{ command_text_printf }}" + # data: + # component: "{{ repeat.item.button }}bri" + # message: "{{ btn_bri_txt }}" + + - service: "{{ command_set_button }}" + data: + btn_id: "{{ repeat.item.button }}" + btn_pic: "{{ btn_pic }}" + btn_bg: "{{ btn_bg }}" + btn_icon_font: "{{ btn_icon_font }}" + btn_txt_font: "{{ btn_txt_font }}" + btn_bri_font: "{{ btn_bri_font }}" + btn_icon: "{{ btn_icon }}" + btn_label: "{{ btn_label }}" + btn_bri_txt: "{{ btn_bri_txt }}" - ##### "BRIGHTNESS" Value ##### - - delay: - milliseconds: "{{ delay_value }}" - - if: - - condition: template - value_template: "{{ btn_bri_txt == 0 }}" - then: - - service: "{{ command_text_printf }}" - data: - component: "{{ repeat.item.button }}bri" - message: " " - else: - - service: "{{ command_text_printf }}" - data: - component: "{{ repeat.item.button }}bri" - message: "{{ btn_bri_txt }}" ###### SHOW All component when page loading done ##### - delay: milliseconds: "{{ delay_value }}" diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 9746491..30f3460 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -302,6 +302,41 @@ api: id(disp1).set_component_text_printf("target_temp", "%.1f°", value); id(display_target_temp).publish_state(value); + #### Service to set the buttons #### + - service: set_button + variables: + btn_id: string + btn_pic: int + btn_bg: int + btn_icon_font: int + btn_txt_font: int + btn_bri_font: int + btn_icon: string + btn_label: string + btn_bri_txt: string + then: + - wait_until: + switch.is_on: nextion_init + - lambda: |- + // ESP_LOGD("nextion", "set button %s", btn_id.c_str()); + std::string btnicon = btn_id.c_str() + std::string("icon"); + std::string btntext = btn_id.c_str() + std::string("text"); + std::string btnbri = btn_id.c_str() + std::string("bri"); + id(disp1).send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic); + id(disp1).set_component_background_color(btnicon.c_str(), btn_bg); + id(disp1).set_component_background_color(btntext.c_str(), btn_bg); + id(disp1).set_component_background_color(btnbri.c_str(), btn_bg); + id(disp1).set_component_font_color(btnicon.c_str(), btn_icon_font); + id(disp1).set_component_font_color(btntext.c_str(), btn_txt_font); + id(disp1).set_component_font_color(btnbri.c_str(), btn_bri_font); + id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str()); + id(disp1).set_component_text_printf(btntext.c_str(), "%s", btn_label.c_str()); + id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str()); + // if (strcmp(btn_bri_txt.c_str(), "0") != 0) { + // id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str()); + // } else { + // id(disp1).set_component_text_printf(btnbri.c_str(), "%s", std::string(" ")); + // } ##### START - GLOBALS CONFIGURATION ##### globals: