Home page: Removing unnecessary calls to panel (#629)

Trying to gain a bit on performance by not sending calls to the panel when not needed (element not available, etc.).
This commit is contained in:
Edward Firmo
2023-04-10 23:57:35 +02:00
committed by GitHub
parent 1ea041c731
commit 59727e294d

View File

@@ -2317,6 +2317,7 @@ The goal was to create a version that allows everyone to use the NSpanel fully l
mode: parallel mode: parallel
max: 5000 max: 5000
trace: trace:
stored_traces: 10 stored_traces: 10
@@ -2356,7 +2357,7 @@ variables:
date_format: !input "date_format" date_format: !input "date_format"
time_format: !input "time_format" time_format: !input "time_format"
time: "{{ as_timestamp(now()) | timestamp_custom(time_format) }}" time: "{{ as_timestamp(now()) | timestamp_custom(time_format) }}"
meridiem: "{{ as_timestamp(now()) | timestamp_custom('%p') if time_format == '%-I:%M' else '' }}" meridiem: "{{ as_timestamp(now()) | timestamp_custom('%p') if time_format == '%-I:%M' }}"
sun_is_up: "{{ is_state('sun.sun', 'above_horizon') }}" sun_is_up: "{{ is_state('sun.sun', 'above_horizon') }}"
notification_sound: "switch.{{ nspanel_name }}_notification_sound" notification_sound: "switch.{{ nspanel_name }}_notification_sound"
@@ -3693,20 +3694,6 @@ condition: "{{ is_state(nextion_inited_trigger, 'on') | default(false) if nextio
##### START - Action ##### ##### START - Action #####
############################################################# #############################################################
action: action:
- variables:
#settings_entity_value: "{{ states(settings_entity) }}"
settings_entity_value: "{{ states(settings_entity) | default('unavailable') if settings_entity is string else 'unavailable' }}"
settings_entity_split: "{{ settings_entity_value.split(',') if settings_entity_value is string and settings_entity_value not in ['unavailable', 'unknown', None] else [] }}"
settings_entity_count: "{{ settings_entity_split | count if settings_entity_split else 0 }}"
entity_long: "{{ settings_entity_split[0] if settings_entity_count >= 1 else 'unknown' }}"
entity_back: "{{ settings_entity_split[1] if settings_entity_count >= 2 else 'unknown' }}"
entity_long_name: "{{ settings_entity_split[2] if settings_entity_count >= 3 else 'unknown' }}"
entity_long_icon: "{{ settings_entity_split[3] if settings_entity_count >= 4 else 'unknown' }}"
entity_long_icon_color: "{{ settings_entity_split[4] if settings_entity_count >= 5 else 'unknown' }}"
entity_long_domain: "{{ entity_long.split('.')[0] if entity_long.split('.') | count > 0 else 'unknown' }}"
########################################################################################################################
# main - alias: "choose alias (name)" # main - alias: "choose alias (name)"
- alias: Main choices - alias: Main choices
choose: choose:
@@ -3716,8 +3703,21 @@ action:
- condition: trigger - condition: trigger
id: settings_entity id: settings_entity
- "{{ trigger.event.data.new_state.state not in ['unavailable', 'unknown', None] }}" - "{{ trigger.event.data.new_state.state not in ['unavailable', 'unknown', None] }}"
- "{{ entity_long_domain in ['light', 'cover', 'climate'] }}"
sequence: sequence:
- &variables-settings_entity
variables:
settings_entity_value: "{{ states(settings_entity) | default('unavailable') if settings_entity is string else 'unavailable' }}"
settings_entity_split: "{{ settings_entity_value.split(',') if settings_entity_value is string and settings_entity_value not in ['unavailable', 'unknown', None] else [] }}"
settings_entity_count: "{{ settings_entity_split | count if settings_entity_split else 0 }}"
entity_long: "{{ settings_entity_split[0] if settings_entity_count >= 1 else 'unknown' }}"
entity_back: "{{ settings_entity_split[1] if settings_entity_count >= 2 else 'unknown' }}"
entity_long_name: "{{ settings_entity_split[2] if settings_entity_count >= 3 else 'unknown' }}"
entity_long_icon: "{{ settings_entity_split[3] if settings_entity_count >= 4 else 'unknown' }}"
entity_long_icon_color: "{{ settings_entity_split[4] if settings_entity_count >= 5 else 'unknown' }}"
- variables:
entity_long_domain: "{{ entity_long.split('.')[0] if entity_long.split('.') | count > 0 else 'unknown' }}"
- if: "{{ entity_long_domain in ['light', 'cover', 'climate'] }}"
then:
- service: "{{ nextion.commands.printf }}" - service: "{{ nextion.commands.printf }}"
data: data:
cmd: "page {{ nextion.pages[entity_long_domain] }}" cmd: "page {{ nextion.pages[entity_long_domain] }}"
@@ -3786,6 +3786,7 @@ action:
display_target_temperature_state: "{{ states(display_target_temperature) | default('unavailable') if display_target_temperature is string else 'unavailable' }}" display_target_temperature_state: "{{ states(display_target_temperature) | default('unavailable') if display_target_temperature is string else 'unavailable' }}"
- if: "{{ is_number(display_target_temperature_state) }}" - if: "{{ is_number(display_target_temperature_state) }}"
then: then:
- *variables-settings_entity
- service: climate.set_temperature - service: climate.set_temperature
data: data:
entity_id: "{{ entity_long }}" entity_id: "{{ entity_long }}"
@@ -3831,6 +3832,8 @@ action:
component: home.time component: home.time
message: "{{ time }}" message: "{{ time }}"
continue_on_error: true continue_on_error: true
- if: "{{ meridiem }}"
then:
### TIME Meridiem Font Color ### ### TIME Meridiem Font Color ###
- *delay-default - *delay-default
- service: "{{ nextion.commands.font_color }}" - service: "{{ nextion.commands.font_color }}"
@@ -3850,6 +3853,8 @@ action:
- variables: - variables:
outdoor_temp_state: "{{ states(outdoortemp) | default('unavailable') if outdoortemp is string else 'unavailable' }}" outdoor_temp_state: "{{ states(outdoortemp) | default('unavailable') if outdoortemp is string else 'unavailable' }}"
outdoor_temp: "{{ outdoor_temp_state if is_number(outdoor_temp_state) else state_attr(weather_entity, 'temperature') | default('unavailable') if weather_entity is string else 'unavailable' }}" outdoor_temp: "{{ outdoor_temp_state if is_number(outdoor_temp_state) else state_attr(weather_entity, 'temperature') | default('unavailable') if weather_entity is string else 'unavailable' }}"
- if: "{{ is_number(outdoor_temp) }}"
then:
### LABEL Outdoor Temp Font Color ### ### LABEL Outdoor Temp Font Color ###
- *delay-default - *delay-default
- service: "{{ nextion.commands.font_color }}" - service: "{{ nextion.commands.font_color }}"
@@ -3862,12 +3867,14 @@ action:
- service: "{{ nextion.commands.text_printf }}" - service: "{{ nextion.commands.text_printf }}"
data: data:
component: home.outdoor_temp component: home.outdoor_temp
message: "{{ (outdoor_temp | round(1) ~ temperature_units) if is_number(outdoor_temp) else (mui[language].unavailable if outdoor_temp in ['unavailable', 'unknown', None] else outdoor_temp) }}" message: "{{ outdoor_temp | round(1) ~ temperature_units }}"
continue_on_error: true continue_on_error: true
##### NSPanel Indoor Temp ##### ##### NSPanel Indoor Temp #####
- variables: - variables:
indoor_temp_state: "{{ states(indoortemp) | default('unavailable') if indoortemp is string else 'unavailable' }}" indoor_temp_state: "{{ states(indoortemp) | default('unavailable') if indoortemp is string else 'unavailable' }}"
- if: "{{ is_number(indoor_temp_state) }}"
then:
### ICON Indoor Temp Font Color ### ### ICON Indoor Temp Font Color ###
- *delay-default - *delay-default
- service: "{{ nextion.commands.font_color }}" - service: "{{ nextion.commands.font_color }}"
@@ -4012,6 +4019,11 @@ action:
sequence: sequence:
- &display-home_page_status_bar - &display-home_page_status_bar
if: "{{ repeat.item.entity is defined and repeat.item.entity is string and repeat.item.entity | length > 0 }}" if: "{{ repeat.item.entity is defined and repeat.item.entity is string and repeat.item.entity | length > 0 }}"
then:
- variables:
repeat_item_state: "{{ states(repeat.item.entity) | default('unavailable') }}"
repeat_item_state_is_on: "{{ repeat_item_state in ['on', 'open'] }}"
- if: "{{ repeat_item_state_is_on }}"
then: then:
### ICON Font Color ### ### ICON Font Color ###
- *delay-default - *delay-default
@@ -4025,7 +4037,7 @@ action:
- service: "{{ nextion.commands.text_printf }}" - service: "{{ nextion.commands.text_printf }}"
data: data:
component: "{{ 'home.icon_top_%02d' | format(repeat.index) }}" component: "{{ 'home.icon_top_%02d' | format(repeat.index) }}"
message: "{{ repeat.item.icon if is_state(repeat.item.entity, 'on') | default(False) else nextion.icons.blank }}" message: "{{ repeat.item.icon if repeat_item_state_is_on else nextion.icons.blank }}"
continue_on_error: true continue_on_error: true
# {{ is_state(repeat.item.entity, 'on') | default(False) if repeat.item.entity is string else 'unavailable' }} # {{ is_state(repeat.item.entity, 'on') | default(False) if repeat.item.entity is string else 'unavailable' }}
@@ -4052,7 +4064,7 @@ action:
- &display-home_page_value - &display-home_page_value
if: "{{ repeat.item.entity is string and repeat.item.entity is match 'sensor.' and states(repeat.item.entity) not in ['unavailable', 'unknown', None] }}" if: "{{ repeat.item.entity is string and repeat.item.entity is match 'sensor.' and states(repeat.item.entity) not in ['unavailable', 'unknown', None] }}"
then: then:
- if: "{{ repeat.item.entity_icon | length > 0 }}" - if: "{{ repeat.item.icon | length > 0 }}"
then: then:
### ICON Font Color ### ### ICON Font Color ###
- *delay-default - *delay-default
@@ -4068,6 +4080,11 @@ action:
component: "{{ 'home.value%02d_icon' | format(repeat.index) }}" component: "{{ 'home.value%02d_icon' | format(repeat.index) }}"
message: "{{ repeat.item.icon }}" message: "{{ repeat.item.icon }}"
continue_on_error: true continue_on_error: true
- variables:
repeat_item_state: "{{ states(repeat.item.entity) | default('unavailable') }}"
repeat_item_state_available: "{{ repeat_item_state not in ['unavailable', 'unknown', None] }}"
- if: "{{ repeat_item_state_available }}"
then:
### LABEL Font Color ### ### LABEL Font Color ###
- *delay-default - *delay-default
- service: "{{ nextion.commands.font_color }}" - service: "{{ nextion.commands.font_color }}"
@@ -4080,14 +4097,17 @@ action:
- service: "{{ nextion.commands.text_printf }}" - service: "{{ nextion.commands.text_printf }}"
data: data:
component: "{{ 'home.value%02d_state' | format(repeat.index) }}" component: "{{ 'home.value%02d_state' | format(repeat.index) }}"
message: "{{ (states(repeat.item.entity) | round(1) ~ (state_attr(repeat.item.entity, 'unit_of_measurement') if state_attr(repeat.item.entity, 'unit_of_measurement') else '')) if is_number(states(repeat.item.entity)) else states(repeat.item.entity) | default('unknown') }}" message: "{{ (repeat_item_state | round(1) ~ state_attr(repeat.item.entity, 'unit_of_measurement') | default('')) if is_number(repeat_item_state) else repeat_item_state }}"
continue_on_error: true continue_on_error: true
##### Set notify icon ##### ##### Set notify icon #####
- variables: - variables:
notification_unread_state: "{{ states(notification_unread) | default('unavailable') if notification_unread is string else 'unavailable' }}" notification_unread_state: "{{ states(notification_unread) | default('unavailable') if notification_unread is string else 'unavailable' }}"
- if: "{{ notification_unread_state in ['on', 'off'] }}"
then:
- variables:
notification_text_state: "{{ states(notification_text) | default(None) if notification_text is string else None }}" notification_text_state: "{{ states(notification_text) | default(None) if notification_text is string else None }}"
set_button04_icon: "{{ page_home.buttons[3].icon if notification_unread_state in ['on', 'off'] and notification_text_state | length > 0 else nextion.icons.blank }}" set_button04_icon: "{{ page_home.buttons[3].icon if notification_unread_state == 'on' and notification_text_state | length > 0 else nextion.icons.blank }}"
set_button04_icon_font: "{{ (page_home.buttons[3].color_rgb[notification_unread_state] if is_number(page_home.buttons[3].color_rgb[notification_unread_state]) else ((page_home.buttons[3].color_rgb[notification_unread_state][0] //(2**3)) *(2**11))+((page_home.buttons[3].color_rgb[notification_unread_state][1] //(2**2)) *(2**5))+(page_home.buttons[3].color_rgb[notification_unread_state][2] //(2**3))) if notification_unread_state in ['on', 'off'] and notification_text_state | length > 0 else nextion.colors.grey_light }}" set_button04_icon_font: "{{ (page_home.buttons[3].color_rgb[notification_unread_state] if is_number(page_home.buttons[3].color_rgb[notification_unread_state]) else ((page_home.buttons[3].color_rgb[notification_unread_state][0] //(2**3)) *(2**11))+((page_home.buttons[3].color_rgb[notification_unread_state][1] //(2**2)) *(2**5))+(page_home.buttons[3].color_rgb[notification_unread_state][2] //(2**3))) if notification_unread_state in ['on', 'off'] and notification_text_state | length > 0 else nextion.colors.grey_light }}"
##### SET ICON Font - Notify ##### ##### SET ICON Font - Notify #####
- *delay-default - *delay-default
@@ -4447,6 +4467,7 @@ action:
- alias: Light settings page - alias: Light settings page
conditions: "{{ trigger.event.data.new_state.state == nextion.pages.light }}" conditions: "{{ trigger.event.data.new_state.state == nextion.pages.light }}"
sequence: sequence:
- *variables-settings_entity
- service: "{{ nextion.commands.text_printf }}" - service: "{{ nextion.commands.text_printf }}"
data: data:
component: lightsettings.light_name component: lightsettings.light_name
@@ -4535,6 +4556,7 @@ action:
conditions: "{{ trigger.event.data.new_state.state == nextion.pages.cover }}" conditions: "{{ trigger.event.data.new_state.state == nextion.pages.cover }}"
sequence: sequence:
##### COVER - OPEN / CLOSE ##### ##### COVER - OPEN / CLOSE #####
- *variables-settings_entity
- variables: - variables:
coversettings_icon_font: "{{ entity_long_icon if entity_long_icon | length > 0 else nextion.icons.buttons.cover }}" coversettings_icon_font: "{{ entity_long_icon if entity_long_icon | length > 0 else nextion.icons.buttons.cover }}"
coversettings_icon_font_color: "{{ entity_long_icon_color if is_state(entity_long, 'open') else nextion.colors.grey_light }}" coversettings_icon_font_color: "{{ entity_long_icon_color if is_state(entity_long, 'open') else nextion.colors.grey_light }}"
@@ -4797,6 +4819,7 @@ action:
- alias: Climate page - alias: Climate page
conditions: "{{ trigger.event.data.new_state.state == nextion.pages.climate }}" conditions: "{{ trigger.event.data.new_state.state == nextion.pages.climate }}"
sequence: sequence:
- *variables-settings_entity
- variables: - variables:
hvac_mode: "{{ states(entity_long) | default('unavailable') if entity_long is string else 'unavailable' }}" hvac_mode: "{{ states(entity_long) | default('unavailable') if entity_long is string else 'unavailable' }}"
outdoor_temp_state: "{{ states(outdoortemp) | default('unavailable') if outdoortemp is string else 'unavailable' }}" outdoor_temp_state: "{{ states(outdoortemp) | default('unavailable') if outdoortemp is string else 'unavailable' }}"
@@ -5148,13 +5171,13 @@ action:
- variables: - variables:
##### Entity - Page Button - Toggle Entity ##### ##### Entity - Page Button - Toggle Entity #####
last_click_state: "{{ states(last_click) | default('unavailable') if last_click is string else 'unavailable' }}" last_click_state: "{{ states(last_click) | default('unavailable') if last_click is string else 'unavailable' }}"
last_click_coordinates: "{{ last_click_state.replace('releasebuttonpage', '').split('button') if last_click_state not in ['unavailable', 'unknown', None] else [-1, -1] }}" last_click_coordinates: "{{ last_click_state.replace('releasebuttonpage', '').split('button') if last_click_state not in ['unavailable', 'unknown', None] else None }}"
last_click_entity_index: "{{ (last_click_coordinates[0] | int(-99) -1)*8 + last_click_coordinates[1] | int(-99) - 1 }}" last_click_entity_index: "{{ (last_click_coordinates[0] | int(-99) -1)*8 + last_click_coordinates[1] | int(-99) - 1 if last_click_coordinates and last_click_coordinates | count >= 1 else -1 }}"
- condition: "{{ last_click_entity_index >= 0 }}" - condition: "{{ last_click_entity_index >= 0 }}"
- variables: - variables:
last_click_button: "{{ button_pages_buttons[last_click_entity_index] | default([]) }}" last_click_button: "{{ button_pages_buttons[last_click_entity_index] | default([]) }}"
entity_short: "{{ last_click_button.entity | default('unavailable') if last_click_button and last_click_button.entity is defined }}" entity_short: "{{ last_click_button.entity | default('unavailable') if last_click_button and last_click_button.entity is defined }}"
entity_domain: "{{ (entity_short.split('.')[0] | default('unknown')) if entity_short is string and entity_short | length > 0 else 'unknown' }}" entity_domain: "{{ (entity_short.split('.')[0] | default('unknown')) if entity_short is string and entity_short | length > 0 and entity_short.split('.') | count > 0 else 'unknown' }}"
- condition: "{{ entity_domain not in ['unknown', 'person', 'binary_sensor', 'sensor'] }}" - condition: "{{ entity_domain not in ['unknown', 'person', 'binary_sensor', 'sensor'] }}"
- if: "{{ entity_domain == 'climate' }}" - if: "{{ entity_domain == 'climate' }}"
then: then:
@@ -5290,6 +5313,7 @@ action:
id: light_settings id: light_settings
- "{{ nextion.pages.current == nextion.pages.light }}" - "{{ nextion.pages.current == nextion.pages.light }}"
sequence: sequence:
- *variables-settings_entity
- choose: - choose:
##### Page Lightsettings - Brightness Slider MOVE ##### ##### Page Lightsettings - Brightness Slider MOVE #####
- conditions: - conditions:
@@ -5376,6 +5400,7 @@ action:
id: cover_settings id: cover_settings
- "{{ nextion.pages.current == nextion.pages.cover }}" - "{{ nextion.pages.current == nextion.pages.cover }}"
sequence: sequence:
- *variables-settings_entity
- choose: - choose:
##### Page Coversettings - Cover Slider MOVE ##### ##### Page Coversettings - Cover Slider MOVE #####
- conditions: - conditions:
@@ -5444,6 +5469,7 @@ action:
id: climate_settings id: climate_settings
- "{{ nextion.pages.current == nextion.pages.climate }}" - "{{ nextion.pages.current == nextion.pages.climate }}"
sequence: sequence:
- *variables-settings_entity
- variables: - variables:
entity_long_state: "{{ states(entity_long) | default('unavailable') if entity_long is string else 'unavailable' }}" entity_long_state: "{{ states(entity_long) | default('unavailable') if entity_long is string else 'unavailable' }}"
- choose: - choose: