From 1dfd0e6f9ab9a11df64f3db27bc6ead619c8b58d Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:17:25 +0200 Subject: [PATCH] Cleanup boot sequence Move some functionalities to ESPHome --- nspanel_blueprint.yaml | 390 +++++++++++++++++++---------------------- nspanel_esphome.yaml | 54 +++++- 2 files changed, 229 insertions(+), 215 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index ba1574c..118ac7b 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3529,10 +3529,10 @@ variables: value: 'esphome.{{ nspanel_name }}_send_command_value' printf: 'esphome.{{ nspanel_name }}_send_command_printf' font_color: 'esphome.{{ nspanel_name }}_send_command_font_color' - background_color: 'esphome.{{ nspanel_name }}_send_command_background_color' - notification_show: 'esphome.{{ nspanel_name }}_notification_show' + #background_color: 'esphome.{{ nspanel_name }}_send_command_background_color' + #notification_show: 'esphome.{{ nspanel_name }}_notification_show' notification_clear: 'esphome.{{ nspanel_name }}_notification_clear' - play_rtttl: 'esphome.{{ nspanel_name }}_play_rtttl' + #play_rtttl: 'esphome.{{ nspanel_name }}_play_rtttl' open_entity_settings_page: 'esphome.{{ nspanel_name }}_open_entity_settings_page' hide: 'esphome.{{ nspanel_name }}_send_command_hide' show: 'esphome.{{ nspanel_name }}_send_command_show' @@ -3545,6 +3545,7 @@ variables: page_home_settings: 'esphome.{{ nspanel_name }}_page_home_settings' qrcode: 'esphome.{{ nspanel_name }}_qrcode' alarm_settings: 'esphome.{{ nspanel_name }}_alarm_settings' + wake_up_display: 'esphome.{{ nspanel_name }}_wake_up_display' icon: domain: automation: "\uF6FC" #F6FC @@ -3624,6 +3625,7 @@ variables: - "entitypage03" - "entitypage04" alarm: "alarm" + keyb_num: "keyb_num" ##### MUI Multilingual User Interface ##### language_tmp: !input 'language' @@ -6360,6 +6362,179 @@ action: }} continue_on_error: true + ##### Boot detected ##### + - alias: Boot init + conditions: + - condition: trigger + id: nspanel_boot_init + sequence: + - &global_settings + if: '{{ true }}' + then: + - &variables_wakeup_page + variables: + wakeup_page_input: !input wakeup_page + wakeup_page: '{{ wakeup_page_input if is_number(wakeup_page_input) else 0 }}' + - &variables_hardware + variables: + hardware: + buttons: + left: + entity: !input 'left_button_entity' + name: !input 'left_button_name' + color_rgb: !input 'left_button_color' + hold_select: !input 'left_button_hold_select' + #custom_action: !input 'left_button_hold_custom_action' + right: + entity: !input 'right_button_entity' + name: !input 'right_button_name' + color_rgb: !input 'right_button_color' + hold_select: !input 'right_button_hold_select' + #custom_action: !input 'right_button_hold_custom_action' + relays: + relay1: + icon: !input 'relay01_icon' #E3A5 + icon_color_rgb: !input 'relay01_icon_color' + relay2: + icon: !input 'relay02_icon' #E3A8 + icon_color_rgb: !input 'relay02_icon_color' + + - &variables-home_buttons + variables: + bt_entities: + enabled: !input 'entitypages_enabled' + icon: !input 'home_button06_icon' #EDCF + color_rgb: !input 'home_button06_icon_color' + bt_qrcode: + enabled: !input 'qrcode_enabled' + icon: !input 'home_button05_icon' #E432 + color_rgb: !input 'home_button05_icon_color' + title: !input 'qrcode_label' + qrcode: !input 'qrcode_value' + + - &variables-date_time + variables: + display: + date: + format: + color_rgb: !input 'date_label_color' + time: + format: !input 'time_format' + color_rgb: !input 'time_label_color' + + - service: '{{ nextion.command.page_home_settings }}' + data: + qrcode: '{{ bt_qrcode.enabled }}' + qrcode_icon: > + {{ + all_icons[bt_qrcode.icon.split(":")[1]] | default(bt_qrcode.icon + if bt_qrcode.icon is string + else all_icons["format-list-bulleted-square"]) + }} + qrcode_icon_color: > + {{ + bt_qrcode.color_rgb + if is_number(bt_qrcode.color_rgb) + else + ((bt_qrcode.color_rgb[0] //(2**3)) *(2**11))+ + ((bt_qrcode.color_rgb[1] //(2**2)) *(2**5))+ + (bt_qrcode.color_rgb[2] //(2**3)) + }} + entities_pages: '{{ bt_entities.enabled }}' + entities_pages_icon: > + {{ + all_icons[bt_entities.icon.split(":")[1]] | default(bt_entities.icon + if bt_entities.icon is string + else all_icons["format-list-bulleted-square"]) + }} + entities_pages_icon_color: > + {{ + bt_entities.color_rgb + if is_number(bt_entities.color_rgb) + else + ((bt_entities.color_rgb[0] //(2**3)) *(2**11))+ + ((bt_entities.color_rgb[1] //(2**2)) *(2**5))+ + (bt_entities.color_rgb[2] //(2**3)) + }} + alarm_state: > + {{ + states(alarm) | default("") + if alarm is string and alarm | length > 0 + else "" + }} + continue_on_error: true + - &delay-default + delay: + milliseconds: '{{ delay_value }}' + + - service: '{{ nextion.command.qrcode }}' + data: + title: '{{ bt_qrcode.title }}' + qrcode: '{{ bt_qrcode.qrcode }}' + show: false + continue_on_error: true + - *delay-default + + - service: '{{ nextion.command.global_settings }}' + data: + blueprint_version: '{{ blueprint_version }}' + relay1_local_control: '{{ hardware.buttons.left.entity == relay01_entity }}' + relay1_icon: > + {{ + all_icons[hardware.relays.relay1.icon.split(":")[1]] | default("\uE3A5") + if hardware.relays.relay1.icon.split(":") | count > 0 + else + ( + hardware.relays.relay1.icon + if hardware.relays.relay1.icon is string + else "\uE3A5" + ) + }} + relay1_icon_color: > + {{ + hardware.relays.relay1.icon_color_rgb + if is_number(hardware.relays.relay1.icon_color_rgb) + else ((hardware.relays.relay1.icon_color_rgb[0] //(2**3)) *(2**11))+((hardware.relays.relay1.icon_color_rgb[1] //(2**2)) *(2**5))+(hardware.relays.relay1.icon_color_rgb[2] //(2**3)) + }} + relay2_local_control: '{{ hardware.buttons.right.entity == relay02_entity }}' + relay2_icon: > + {{ + all_icons[hardware.relays.relay2.icon.split(":")[1]] | default("\uE3A8") + if hardware.relays.relay2.icon.split(":") | count > 0 + else + ( + hardware.relays.relay2.icon + if hardware.relays.relay2.icon is string + else "\uE3A8" + ) + }} + relay2_icon_color: > + {{ + hardware.relays.relay2.icon_color_rgb + if is_number(hardware.relays.relay2.icon_color_rgb) + else ((hardware.relays.relay2.icon_color_rgb[0] //(2**3)) *(2**11))+((hardware.relays.relay2.icon_color_rgb[1] //(2**2)) *(2**5))+(hardware.relays.relay2.icon_color_rgb[2] //(2**3)) + }} + date_color: > + {{ + display.date.color_rgb + if is_number(display.date.color_rgb) + else ((display.date.color_rgb[0] //(2**3)) *(2**11))+((display.date.color_rgb[1] //(2**2)) *(2**5))+(display.date.color_rgb[2] //(2**3)) + }} + time_format: '{{ display.time.format }}' + time_color: > + {{ + display.time.color_rgb + if is_number(display.time.color_rgb) + else ((display.time.color_rgb[0] //(2**3)) *(2**11))+((display.time.color_rgb[1] //(2**2)) *(2**5))+(display.time.color_rgb[2] //(2**3)) + }} + embedded_climate: '{{ embedded_climate }}' + wakeup_page: '{{ wakeup_page }}' + continue_on_error: true + - *delay-default + + ##### Update Date & Time before showing the Home page ##### + - *refresh-date + ##### NSPanel event ##### - alias: NSPanel event conditions: @@ -6375,207 +6550,8 @@ action: conditions: - '{{ nspanel_event.type == "boot"}}' - '{{ nspanel_event.step is defined and nspanel_event.step in ["nextion_init", "timeout"]}}' - sequence: &boot_init_sequence - ##### NSPanel boot init only ##### - - delay: - milliseconds: 100 - - alias: Publish blueprint version - service: '{{ nextion.command.text_printf }}' - data: - component: boot.bluep_version - message: '{{ blueprint_version }}' - continue_on_error: true - - &delay-default - delay: - milliseconds: '{{ delay_value }}' - - - &global_settings - if: '{{ true }}' - then: - - &variables_wakeup_page - variables: - wakeup_page_input: !input wakeup_page - wakeup_page: '{{ wakeup_page_input if is_number(wakeup_page_input) else 0 }}' - - &variables_hardware - variables: - hardware: - buttons: - left: - entity: !input 'left_button_entity' - name: !input 'left_button_name' - color_rgb: !input 'left_button_color' - hold_select: !input 'left_button_hold_select' - #custom_action: !input 'left_button_hold_custom_action' - right: - entity: !input 'right_button_entity' - name: !input 'right_button_name' - color_rgb: !input 'right_button_color' - hold_select: !input 'right_button_hold_select' - #custom_action: !input 'right_button_hold_custom_action' - relays: - relay1: - icon: !input 'relay01_icon' #E3A5 - icon_color_rgb: !input 'relay01_icon_color' - relay2: - icon: !input 'relay02_icon' #E3A8 - icon_color_rgb: !input 'relay02_icon_color' - - - &variables-home_buttons - variables: - bt_entities: - enabled: !input 'entitypages_enabled' - icon: !input 'home_button06_icon' #EDCF - color_rgb: !input 'home_button06_icon_color' - bt_qrcode: - enabled: !input 'qrcode_enabled' - icon: !input 'home_button05_icon' #E432 - color_rgb: !input 'home_button05_icon_color' - title: !input 'qrcode_label' - qrcode: !input 'qrcode_value' - - - &variables-date_time - variables: - display: - date: - format: - color_rgb: !input 'date_label_color' - time: - format: !input 'time_format' - color_rgb: !input 'time_label_color' - - - service: '{{ nextion.command.page_home_settings }}' - data: - qrcode: '{{ bt_qrcode.enabled }}' - qrcode_icon: > - {{ - all_icons[bt_qrcode.icon.split(":")[1]] | default(bt_qrcode.icon - if bt_qrcode.icon is string - else all_icons["format-list-bulleted-square"]) - }} - qrcode_icon_color: > - {{ - bt_qrcode.color_rgb - if is_number(bt_qrcode.color_rgb) - else - ((bt_qrcode.color_rgb[0] //(2**3)) *(2**11))+ - ((bt_qrcode.color_rgb[1] //(2**2)) *(2**5))+ - (bt_qrcode.color_rgb[2] //(2**3)) - }} - entities_pages: '{{ bt_entities.enabled }}' - entities_pages_icon: > - {{ - all_icons[bt_entities.icon.split(":")[1]] | default(bt_entities.icon - if bt_entities.icon is string - else all_icons["format-list-bulleted-square"]) - }} - entities_pages_icon_color: > - {{ - bt_entities.color_rgb - if is_number(bt_entities.color_rgb) - else - ((bt_entities.color_rgb[0] //(2**3)) *(2**11))+ - ((bt_entities.color_rgb[1] //(2**2)) *(2**5))+ - (bt_entities.color_rgb[2] //(2**3)) - }} - alarm_state: > - {{ - states(alarm) | default("") - if alarm is string and alarm | length > 0 - else "" - }} - continue_on_error: true - - *delay-default - - - service: '{{ nextion.command.qrcode }}' - data: - title: '{{ bt_qrcode.title }}' - qrcode: '{{ bt_qrcode.qrcode }}' - show: false - continue_on_error: true - - *delay-default - - - service: '{{ nextion.command.global_settings }}' - data: - relay1_local_control: '{{ hardware.buttons.left.entity == relay01_entity }}' - relay1_icon: > - {{ - all_icons[hardware.relays.relay1.icon.split(":")[1]] | default("\uE3A5") - if hardware.relays.relay1.icon.split(":") | count > 0 - else - ( - hardware.relays.relay1.icon - if hardware.relays.relay1.icon is string - else "\uE3A5" - ) - }} - relay1_icon_color: > - {{ - hardware.relays.relay1.icon_color_rgb - if is_number(hardware.relays.relay1.icon_color_rgb) - else ((hardware.relays.relay1.icon_color_rgb[0] //(2**3)) *(2**11))+((hardware.relays.relay1.icon_color_rgb[1] //(2**2)) *(2**5))+(hardware.relays.relay1.icon_color_rgb[2] //(2**3)) - }} - relay2_local_control: '{{ hardware.buttons.right.entity == relay02_entity }}' - relay2_icon: > - {{ - all_icons[hardware.relays.relay2.icon.split(":")[1]] | default("\uE3A8") - if hardware.relays.relay2.icon.split(":") | count > 0 - else - ( - hardware.relays.relay2.icon - if hardware.relays.relay2.icon is string - else "\uE3A8" - ) - }} - relay2_icon_color: > - {{ - hardware.relays.relay2.icon_color_rgb - if is_number(hardware.relays.relay2.icon_color_rgb) - else ((hardware.relays.relay2.icon_color_rgb[0] //(2**3)) *(2**11))+((hardware.relays.relay2.icon_color_rgb[1] //(2**2)) *(2**5))+(hardware.relays.relay2.icon_color_rgb[2] //(2**3)) - }} - date_color: > - {{ - display.date.color_rgb - if is_number(display.date.color_rgb) - else ((display.date.color_rgb[0] //(2**3)) *(2**11))+((display.date.color_rgb[1] //(2**2)) *(2**5))+(display.date.color_rgb[2] //(2**3)) - }} - time_format: '{{ display.time.format }}' - time_color: > - {{ - display.time.color_rgb - if is_number(display.time.color_rgb) - else ((display.time.color_rgb[0] //(2**3)) *(2**11))+((display.time.color_rgb[1] //(2**2)) *(2**5))+(display.time.color_rgb[2] //(2**3)) - }} - embedded_climate: '{{ embedded_climate }}' - wakeup_page: '{{ wakeup_page }}' - continue_on_error: true - - *delay-default - - - &clear_notification - service: '{{ nextion.command.notification_clear }}' - data: {} - continue_on_error: true - - *delay-default - - ###### NSPanel beep ###### - - delay: 2 # Wait 2s - - if: '{{ is_state(notification_sound, "on") }}' - then: - - service: '{{ nextion.command.play_rtttl }}' - data: - song_str: 'two short:d=4,o=5,b=100:16e6,16e6' - continue_on_error: true - - ##### Update Date & Time before showing the Home page ##### - - *refresh-date - - ##### NSPanel boot init finished and jump to Home Page##### - - *variables_wakeup_page - - *delay-default - - &jump_wakeup_page - service: '{{ nextion.command.printf }}' - data: - cmd: "page {{ wakeup_page }}" - continue_on_error: true + sequence: + - *global_settings ##### Service call ##### - alias: NSPanel service call @@ -8941,7 +8917,6 @@ action: sequence: ##### Update global settings (as user may have changed something) ##### - *global_settings - - *refresh-date - choose: ## PAGE HOME ## @@ -9256,7 +9231,10 @@ action: - "{{ trigger.event.data.old_state.state == 'on' }}" - "{{ trigger.event.data.new_state.state == 'off' }}" sequence: - - *jump_wakeup_page + service: '{{ nextion.command.wake_up_display }}' + data: + reset_timer: true + continue_on_error: true ############################################################# ##### CLOSE - Action ##### diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index e7cf7ed..87b972e 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -234,7 +234,8 @@ api: - service: notification_clear then: - logger.log: "Service: notification_clear" - - lambda: |- + - ¬ification_clear + lambda: |- id(disp1).send_command_printf("is_notification=0"); id(notification_label).publish_state(""); id(notification_text).publish_state(""); @@ -397,6 +398,7 @@ api: ##### Service for transferring global settings from the blueprint to ESPHome ##### - service: global_settings variables: + blueprint_version: string relay1_local_control: bool relay1_icon: string relay1_icon_color: int @@ -412,6 +414,9 @@ api: - lambda: |- // Logs - Begin ESP_LOGV("service.global_settings", "Starting"); + ESP_LOGD("service.global_settings", "Blueprint version: %s", blueprint_version.c_str()); + ESP_LOGD("service.global_settings", "ESPHome version: ${version}"); + if (blueprint_version != "${version}") ESP_LOGW("service.global_settings", "Blueprint and ESPHome versions mismatch!"); ESP_LOGV("service.global_settings", "relay1_local_control: %i", (relay1_local_control) ? 1 : 0); ESP_LOGV("service.global_settings", "relay1_icon: %s", relay1_icon.c_str()); ESP_LOGV("service.global_settings", "relay1_icon_color: %i", relay1_icon_color); @@ -457,8 +462,39 @@ api: ESP_LOGV("service.global_settings", "Update home page"); id(update_page_home).execute(); - // Logs - End - ESP_LOGV("service.global_settings", "Finished"); + - if: + condition: + - text_sensor.state: # Is boot page visible? + id: current_page + state: 'boot' + then: + - lambda: |- + ESP_LOGV("service.global_settings", "Boot page is visible"); + id(disp1).set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str()); + ESP_LOGV("service.global_settings", "Wait a bit"); + - wait_until: + condition: + - not: + - text_sensor.state: # Is boot page visible? + id: current_page + state: 'boot' + timeout: 2s + - if: + condition: + - text_sensor.state: # Avoid this being called twice by multiple boot triggers + id: current_page + state: 'boot' + then: + - if: + condition: + switch.is_on: notification_sound + then: + - lambda: ESP_LOGV("service.global_settings", "Play boot sound"); + - rtttl.play: + rtttl: 'two short:d=4,o=5,b=100:16e6,16e6' + - lambda: id(disp1).send_command_printf("page %i", id(wakeup_page_id)); + + - lambda: ESP_LOGV("service.global_settings", "Finished"); #### Service to populate the page Home ##### - service: page_home_settings @@ -1380,18 +1416,16 @@ display: {"step", "start"} }); - delay: 1s - - lambda: |- - id(display_brightness).publish_state(id(display_brightness_global)); - id(display_dim_brightness).publish_state(id(display_dim_brightness_global)); - id(disp1).send_command_printf("settings.brightslider.val=%i", id(display_brightness_global)); - id(disp1).send_command_printf("settings.dimslider.val=%i", id(display_dim_brightness_global)); - if: condition: switch.is_off: sleep_mode then: *sleep_mode-turn_off else: *sleep_mode-turn_on - - delay: 1s - lambda: |- + id(display_brightness).publish_state(id(display_brightness_global)); + id(display_dim_brightness).publish_state(id(display_dim_brightness_global)); + id(disp1).send_command_printf("settings.brightslider.val=%i", id(display_brightness_global)); + id(disp1).send_command_printf("settings.dimslider.val=%i", id(display_dim_brightness_global)); id(nextion_init).publish_state(true); auto ha_event = new esphome::api::CustomAPIDevice(); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", @@ -1401,6 +1435,8 @@ display: }); id(home_relay1_icon) = "\uE3A5"; id(home_relay1_icon) = "\uE3A8"; + - *notification_clear + - switch.turn_off: notification_unread - logger.log: "Nextion start - Done!" ### Script for page_timer