diff --git a/.gitignore b/.gitignore index d0af3ba..db0c583 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ Nextion2Text.* .idea # Ignore dev folder -dev \ No newline at end of file +dev + +nspanel_esphome_prebuilt.yaml diff --git a/custom_configuration/nspanel_blank.HMI b/custom_configuration/nspanel_blank.HMI index 5fc756c..7fb4a37 100644 Binary files a/custom_configuration/nspanel_blank.HMI and b/custom_configuration/nspanel_blank.HMI differ diff --git a/custom_configuration/nspanel_blank.tft b/custom_configuration/nspanel_blank.tft index 3b45242..e3ef411 100644 Binary files a/custom_configuration/nspanel_blank.tft and b/custom_configuration/nspanel_blank.tft differ diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 9dd5eef..9c4dc03 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -6462,7 +6462,7 @@ condition: conditions: - '{{ trigger.event is defined and trigger.event.data is defined }}' - '{{ trigger.event.data.entity_id is defined }}' - #- '{{ trigger.event.data.entity_id is match "light." }}' + - '{{ trigger.event.data.entity_id is match "light." }}' - condition: and conditions: - '{{ trigger.event is defined and trigger.event.data is defined }}' @@ -6543,6 +6543,78 @@ condition: ##### START - Action ##### ############################################################# action: + - if: '{{ false }}' # Global anchor repository + then: + - variables: + entity_id: '{{ None }}' + overlap: + icon: '{{ None }}' + icon_color: '{{ None }}' + frendly_name: '{{ None }}' + - &variable_entity + variables: + entity_id_is_valid: '{{ entity_id is defined and entity_id is string and entity_id.split(".") | count == 2 }}' + entity_state: '{{ states(entity_id) | default(None) if entity_id_is_valid else None }}' + entity_domain: '{{ entity_id.split(".")[0] if entity_id_is_valid else None }}' + entity_rgb_color: '{{ state_attr(entity_id, "rgb_color") | default(None) if entity_id_is_valid else None }}' + entity_brightness: '{{ state_attr(entity_id, "brightness") | default(None) if entity_id_is_valid else None }}' + entity_brightness_index: '{{ (entity_brightness | int(255))/255 if entity_brightness else 1 }}' + entity_icon: '{{ state_attr(entity_id, "icon") | default(None) if entity_id_is_valid else None }}' + entity_icon_color: > + {{ + entity_rgb_color | list + if entity_rgb_color is sequence + else + ( + nextion.color.on + if entity_state in enum.states.on + else nextion.color.off + ) + }} + entity_icon_color_adjusted: > + {{ + [ + min(255,entity_icon_color[0] * entity_brightness_index) | round(0), + min(255,entity_icon_color[1] * entity_brightness_index) | round(0), + min(255,entity_icon_color[2] * entity_brightness_index) | round(0) + ] + if entity_icon_color is sequence and entity_icon_color | count == 3 + else entity_icon_color + }} + entity: + id: '{{ entity_id }}' + valid: '{{ entity_id_is_valid }}' + state: '{{ entity_state }}' + state_is_number: '{{ is_number(entity_state) }}' + domain: '{{ entity_domain }}' + unit_of_measurement: '{{ state_attr(entity_id, "unit_of_measurement") | default(None) if entity_id_is_valid else None }}' + friendly_name: > + {{ + overlap.frendly_name + if overlap is defined and overlap.frendly_name is defined and overlap.frendly_name is string + else + ( + state_attr(entity_id, "friendly_name") | default(None) + if entity_id_is_valid + else None + ) + }} + supported_features: '{{ state_attr(entity_id, "supported_features") | default(None) if entity_id_is_valid else None }}' + icon: > + {% set icon_domain = nextion.icon.domain[entity_domain] | default(all_icons.blank) %} + {{ + all_icons[overlap.icon[1]] | default(icon_domain) + if overlap is defined and overlap.icon is defined and overlap.icon is string and overlap.icon.split(":") | count == 2 + else + ( + all_icons[entity_icon[1]] | default(icon_domain) + if entity_id_is_valid and entity_icon is string and entity_icon.split(":") | count == 2 + else icon_domain + ) + }} + icon_color: '{{ entity_icon_color_adjusted }}' + rgb_color: '{{ entity_rgb_color }}' + - alias: Main choices choose: ##### DATE ##### @@ -7031,42 +7103,21 @@ action: if: '{{ repeat.item.entity is defined and repeat.item.entity is string and repeat.item.entity | length > 0 }}' then: - variables: - entity_domain: '{{ repeat.item.entity.split(".")[0] if repeat.item.entity and repeat.item.entity.split(".") | count > 1 else "unknown" }}' - entity_state: '{{ states(repeat.item.entity) }}' - rgb_color: '{{ state_attr(repeat.item.entity, "rgb_color") | default(None) }}' - brightness: '{{ (state_attr(repeat.item.entity, "brightness") | int(255))/255 }}' - icon_color: > - {{ - rgb_color | list - if rgb_color is sequence - else - ( - nextion.color.on - if entity_state in enum.states.on - else nextion.color.off - ) - }} - icon_color_adjusted: > - {{ - [ - min(255,icon_color[0] * brightness) | round(0), - min(255,icon_color[1] * brightness) | round(0), - min(255,icon_color[2] * brightness) | round(0) - ] - if icon_color is sequence and icon_color | count == 3 - else icon_color - }} + entity_id: '{{ repeat.item.entity }}' + overlap: + icon: '{{ repeat.item.icon }}' + - *variable_entity - service: '{{ nextion.command.set_component_color }}' data: component: 'home.{{ repeat.item.component }}' - foreground: '{{ icon_color_adjusted }}' + foreground: '{{ entity.icon_color }}' background: [] continue_on_error: true - *delay-default - service: '{{ nextion.command.text_printf }}' data: component: 'home.{{ repeat.item.component }}' - message: > + message: '{{ entity.icon }}' {% if repeat.item.icon | length > 0 %} {{ all_icons[repeat.item.icon.split(":")[1]] | default(all_icons.unknown) @@ -8907,37 +8958,34 @@ action: - *variables_hardware - variables: last_click_button: '{{ hardware.buttons.left if nspanel_event.component == "hw_bt_left" else hardware.buttons.right }}' - entity_domain: > - {{ - last_click_button.entity.split(".")[0] | default("unknown") - if - last_click_button.entity is string and - last_click_button.entity | length > 0 and - last_click_button.entity.split(".") | count > 0 - else "unknown" - }} + entity_id: '{{ last_click_button.entity }}' + - *variable_entity + - condition: '{{ entity.valid }}' - choose: - alias: Long click conditions: - - '{{ nspanel_event.command == "long_click" or entity_domain in ["climate", "media_player"] }}' + - '{{ nspanel_event.command == "long_click" or entity.domain in ["climate", "media_player"] }}' sequence: - choose: - alias: Default conditions: - - '{{ last_click_button.hold_select == "Default" and last_click_button.entity | length > 0 }}' - - '{{ entity_domain in ["climate", "cover", "light", "fan", "media_player"] }}' - #- '{{ entity_domain != "cover" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(4) > 0 }}' - #- '{{ entity_domain != "fan" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(1) > 0 }}' - #- '{{ entity_domain != "light" or state_attr(last_click_button.entity, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' + - '{{ last_click_button.hold_select == "Default" }}' + - '{{ entity.domain in ["climate", "cover", "light", "fan", "media_player"] }}' + #- '{{ entity.domain != "cover" or entity.supported_features | bitwise_and(4) > 0 }}' + #- '{{ entity.domain != "fan" or entity.supported_features | bitwise_and(1) > 0 }}' + #- '{{ entity.domain != "light" or state_attr(entity.id, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' sequence: - - service: '{{ nextion.command.open_entity_settings_page }}' - data: - page: '{{ entity_domain }}' - page_label: '{{ last_click_button.name if last_click_button.name is string and last_click_button.name | length > 0 else state_attr(last_click_button.entity, "friendly_name") }}' - page_icon: '{{ nextion.icon.domain[entity_domain] }}' - page_icon_color: [-1 ] #No color set - entity: '{{ "embedded_climate" if last_click_button.entity == thermostat_embedded else last_click_button.entity }}' + - variables: back_page: '{{ page.home }}' + - &open_entity_settings_page + service: '{{ nextion.command.open_entity_settings_page }}' + data: + page: '{{ entity.domain }}' + page_label: '{{ entity.friendly_name }}' + page_icon: '{{ entity.icon }}' + page_icon_color: '{{ entity.icon_color }}' + entity: '{{ "embedded_climate" if entity.id == thermostat_embedded else entity.id }}' + back_page: '{{ back_page }}' continue_on_error: true - alias: Custom action - Left conditions: '{{ last_click_button.hold_select == "Custom Action" and nspanel_event.component == "hw_bt_left" }}' @@ -8993,43 +9041,28 @@ action: - condition: '{{ last_click_button | count >= 0 }}' - variables: last_click_button: '{{ last_click_button[0] }}' - entity_domain: > - {{ - last_click_button.entity.split(".")[0] | default("unknown") - if - last_click_button.entity is string and - last_click_button.entity | length > 0 and - last_click_button.entity.split(".") | count > 0 - else "unknown" - }} + entity_id: '{{ last_click_button.entity }}' + overlap: + icon: '{{ last_click_button.icon }}' + friendly_name: '{{ last_click_button.name }}' + - *variable_entity + - condition: '{{ entity.valid }}' - choose: - alias: Long click conditions: - - '{{ nspanel_event.command == "long_click" or entity_domain in ["climate", "media_player"] }}' - - '{{ last_click_button.entity | length > 0 }}' - - '{{ entity_domain in ["climate", "cover", "light", "fan", "media_player"] }}' - #- '{{ entity_domain != "cover" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(4) > 0 }}' - #- '{{ entity_domain != "fan" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(1) > 0 }}' - #- '{{ entity_domain != "light" or state_attr(last_click_button.entity, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' + - '{{ nspanel_event.command == "long_click" or entity.domain in ["climate", "media_player"] }}' + - '{{ entity.domain in ["climate", "cover", "light", "fan", "media_player"] }}' + #- '{{ entity.domain != "cover" or entity.supported_features | bitwise_and(4) > 0 }}' + #- '{{ entity.domain != "fan" or entity.supported_features | bitwise_and(1) > 0 }}' + #- '{{ entity.domain != "light" or state_attr(entity_id, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' sequence: - - service: '{{ nextion.command.open_entity_settings_page }}' - data: - page: '{{ entity_domain }}' - page_label: '{{ last_click_button.name if last_click_button.name is string and last_click_button.name | length > 0 else state_attr(last_click_button.entity, "friendly_name") }}' - page_icon: > - {{ - all_icons[last_click_button.icon.split(":")[1]] | default(last_click_button.icon if last_click_button.icon is defined and last_click_button.icon is string else nextion.icon.domain[entity_domain]) - if last_click_button.icon not in ["unavailable", "unknown", "", None] and last_click_button.icon | length > 0 - else nextion.icon.domain[entity_domain] - }} - page_icon_color: '{{ [ last_click_button.icon_color_rgb ] if is_number(last_click_button.icon_color_rgb) else last_click_button.icon_color_rgb }}' - entity: '{{ "embedded_climate" if last_click_button.entity == thermostat_embedded else last_click_button.entity }}' + - variables: back_page: '{{ nspanel_event.page }}' - continue_on_error: true + - *open_entity_settings_page - alias: Short click conditions: - - '{{ nspanel_event.command == "short_click" and entity_domain not in ["climate", "media_player"] }}' - - '{{ entity_domain not in ["unknown", "person", "binary_sensor", "sensor"] }}' + - '{{ nspanel_event.command == "short_click" and entity.domain not in ["climate", "media_player"] }}' + - '{{ entity.domain not in ["unknown", "person", "binary_sensor", "sensor"] }}' sequence: - *short_press-service_call @@ -9078,36 +9111,21 @@ action: - condition: '{{ last_click_button | count >= 0 }}' - variables: last_click_button: '{{ last_click_button[0] }}' - entity_domain: > - {{ - last_click_button.entity.split(".")[0] | default("unknown") - if - last_click_button.entity is string and - last_click_button.entity | length > 0 and - last_click_button.entity.split(".") | count > 0 - else "unknown" - }} + entity_id: '{{ last_click_button.entity }}' + overlap: + icon: '{{ last_click_button.icon }}' + friendly_name: '{{ last_click_button.name }}' + - *variable_entity + - condition: '{{ entity.valid }}' - if: - - '{{ entity_domain in ["climate", "cover", "fan", "light", "media_player"] }}' - - '{{ last_click_button.entity | length > 0 }}' - #- '{{ entity_domain != "cover" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(4) > 0 }}' - #- '{{ entity_domain != "fan" or state_attr(last_click_button.entity, "supported_features") | int(0) | bitwise_and(1) > 0 }}' - #- '{{ entity_domain != "light" or state_attr(last_click_button.entity, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' + - '{{ entity.domain in ["climate", "cover", "fan", "light", "media_player"] }}' + #- '{{ entity.domain != "cover" or entity.supported_features | bitwise_and(4) > 0 }}' + #- '{{ entity.domain != "fan" or entity.supported_features | bitwise_and(1) > 0 }}' + #- '{{ entity.domain != "light" or state_attr(entity.id, "supported_color_modes") | default("unknown") | string not in ["unknown", "onoff", enum.color_mode.unknown, enum.color_mode.onoff, "", none] }}' then: - - service: '{{ nextion.command.open_entity_settings_page }}' - data: - page: '{{ entity_domain }}' - page_label: '{{ last_click_button.name if last_click_button.name is string and last_click_button.name | length > 0 else state_attr(last_click_button.entity, "friendly_name") }}' - page_icon: > - {{ - all_icons[last_click_button.icon.split(":")[1]] | default(last_click_button.icon if last_click_button.icon is defined and last_click_button.icon is string else nextion.icon.domain[entity_domain]) - if last_click_button.icon not in ["unavailable", "unknown", "", None] and last_click_button.icon | length > 0 - else nextion.icon.domain[entity_domain] - }} - page_icon_color: [-1 ] #No color set - entity: '{{ "embedded_climate" if last_click_button.entity == thermostat_embedded else last_click_button.entity }}' + - variables: back_page: '{{ page.home }}' - continue_on_error: true + - *open_entity_settings_page else: - *short_press-service_call @@ -9188,15 +9206,12 @@ action: - '{{ nspanel_event.value == "release" }}' - '{{ climate | length > 0 }} ' sequence: - - service: '{{ nextion.command.open_entity_settings_page }}' - data: - page: 'climate' - page_label: '{{ state_attr(climate, "friendly_name") }}' - page_icon: '' - page_icon_color: [ -1 ] #No color set - entity: '{{ "embedded_climate" if climate == thermostat_embedded else climate }}' + - variables: + entity_id: '{{ climate }}' back_page: '{{ page.home }}' - continue_on_error: true + - *variable_entity + - condition: '{{ entity.valid }}' + - *open_entity_settings_page - alias: Show button - Notification clear conditions: