upd: service set_button to improve performance

This commit is contained in:
deejaybeam
2023-03-31 23:23:43 +02:00
parent d23fe9616c
commit df0855862f
2 changed files with 131 additions and 82 deletions

View File

@@ -2424,6 +2424,7 @@ variables:
command_play_rtttl: "esphome.{{ nspanel_name }}_play_rtttl" command_play_rtttl: "esphome.{{ nspanel_name }}_play_rtttl"
command_set_settings_entity: "esphome.{{ nspanel_name }}_set_settings_entity" command_set_settings_entity: "esphome.{{ nspanel_name }}_set_settings_entity"
command_show_all: "esphome.{{ nspanel_name }}_send_command_show_all" command_show_all: "esphome.{{ nspanel_name }}_send_command_show_all"
command_set_button: "esphome.{{ nspanel_name }}_set_button"
###### SYNC SETTINGS ##### ###### SYNC SETTINGS #####
delay_boot: !input "delay" delay_boot: !input "delay"
@@ -4829,91 +4830,104 @@ action:
{%- else -%} 0 {%- else -%} 0
{%- endif -%} {%- endif -%}
##### SET Buttons Background #### # ##### SET Buttons Background ####
# # #
##### SET Button PIC ##### # ##### SET Button PIC #####
- service: "{{ command_printf }}" # - service: "{{ command_printf }}"
data: # data:
cmd: "{{ repeat.item.button }}pic.pic={{ btn_pic }}" # cmd: "{{ repeat.item.button }}pic.pic={{ btn_pic }}"
##### SET ICON Background ##### # ##### SET ICON Background #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_background_color }}" # - service: "{{ command_background_color }}"
data: # data:
component: "{{ repeat.item.button }}icon" # component: "{{ repeat.item.button }}icon"
message: "{{ btn_bg }}" # message: "{{ btn_bg }}"
##### SET LABEL Background ##### # ##### SET LABEL Background #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_background_color }}" # - service: "{{ command_background_color }}"
data: # data:
component: "{{ repeat.item.button }}text" # component: "{{ repeat.item.button }}text"
message: "{{ btn_bg }}" # message: "{{ btn_bg }}"
##### SET BRIGHTNESS Background Color ##### # ##### SET BRIGHTNESS Background Color #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_background_color }}" # - service: "{{ command_background_color }}"
data: # data:
component: "{{ repeat.item.button }}bri" # component: "{{ repeat.item.button }}bri"
message: "{{ btn_bg }}" # message: "{{ btn_bg }}"
##### SET Buttons Font Color #### # ##### SET Buttons Font Color ####
# # #
##### SET ICON Font Color ##### # ##### SET ICON Font Color #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_font_color }}" # - service: "{{ command_font_color }}"
data: # data:
component: "{{ repeat.item.button }}icon" # component: "{{ repeat.item.button }}icon"
message: "{{ btn_icon_font }}" # message: "{{ btn_icon_font }}"
##### SET LABEL Font Color ##### # ##### SET LABEL Font Color #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_font_color }}" # - service: "{{ command_font_color }}"
data: # data:
component: "{{ repeat.item.button }}text" # component: "{{ repeat.item.button }}text"
message: "{{ btn_txt_font }}" # message: "{{ btn_txt_font }}"
##### SET BRIGHTNESS Font Color ##### # ##### SET BRIGHTNESS Font Color #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_font_color }}" # - service: "{{ command_font_color }}"
data: # data:
component: "{{ repeat.item.button }}bri" # component: "{{ repeat.item.button }}bri"
message: "{{ btn_bri_font }}" # message: "{{ btn_bri_font }}"
##### SET Buttons Text Value #### # ##### SET Buttons Text Value ####
# # #
##### "ICON" Value ##### # ##### "ICON" Value #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_text_printf }}" # - service: "{{ command_text_printf }}"
data: # data:
component: "{{ repeat.item.button }}icon" # component: "{{ repeat.item.button }}icon"
message: "{{ btn_icon }}" # message: "{{ btn_icon }}"
##### "LABEL" Value ##### # ##### "LABEL" Value #####
- delay: # - delay:
milliseconds: "{{ delay_value }}" # milliseconds: "{{ delay_value }}"
- service: "{{ command_text_printf }}" # - service: "{{ command_text_printf }}"
data: # data:
component: "{{ repeat.item.button }}text" # component: "{{ repeat.item.button }}text"
message: "{{ btn_label }}" # 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 ##### ###### SHOW All component when page loading done #####
- delay: - delay:
milliseconds: "{{ delay_value }}" milliseconds: "{{ delay_value }}"

View File

@@ -302,6 +302,41 @@ api:
id(disp1).set_component_text_printf("target_temp", "%.1f°", value); id(disp1).set_component_text_printf("target_temp", "%.1f°", value);
id(display_target_temp).publish_state(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 ##### ##### START - GLOBALS CONFIGURATION #####
globals: globals: