From ec99b83817be5b36a94c2da3060d0bd0032e419e Mon Sep 17 00:00:00 2001 From: Edward Firmo Date: Sat, 1 Jul 2023 14:04:42 +0200 Subject: [PATCH] Time engine on ESPHome --- ReleaseNotes.md | 12 ++++++-- nspanel_blueprint.yaml | 41 ++++++--------------------- nspanel_esphome.yaml | 63 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 34 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0922fe2..57f89f3 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -24,9 +24,10 @@ Since in this update lots of input to the blueprint changed, we highly recommend - [(DE) HowTo - Alle wichtigen Dinge die man wissen sollte - Update](https://github.com/Blackymas/NSPanel_HA_Blueprint/wiki/(DE)-HowTo---Alle-wichtigen-Dinge-die-man-wissen-sollte#2-update-blueprint)   ## Breaking changes -1. New requirement: Home Assistant 2023.5.0 or later +1. New requirement: Home Assistant 2023.5.0 or later. 2. Exisiting users will have o select again the language for the panel, otherwise English will be used to display strings. -3. Removed entity `sensor.xxxxx_settings_entity` and service `esphome.xxxxx_set_settings_entity` +3. Removed entity `sensor.xxxxx_settings_entity` and service `esphome.xxxxx_set_settings_entity`. +4. Due to the changes on the time display engine, you might have to select your time format again in the blueprint settings.   ## Overview of all changes @@ -40,6 +41,7 @@ Since in this update lots of input to the blueprint changed, we highly recommend 8. Light & cover settings pages will show only the supported features (#896) 9. New "Fan speed page" (#897) 10. Select wake-up page (#898) +11. Time engine on ESPHome   ## Details of all changes @@ -103,6 +105,12 @@ Now you can select the wake-up page on the blueprint settings: This selected page will be shown after a boot (after the boot page) and with a touch in the screen when on screen saver page. After showing this wake-up page, all the previous behavior for closing the page (with a click or after a timeout) will be the same.   +### 11. Time engine on ESPHome +The time displayed in your panel is now managed directly into ESPHome, freeing up resources from the Blueprint and communication between the Home Assistant and your panel, and the time on the display will be update even when your network is down or Home Assistant is restarting. + +This is part of an effort to reduce the load into your network and Home Assistant and make your panel more resilient in case of network or Home Assisstant outages. +  + ## Next topics we are currently working on See here: https://github.com/Blackymas/NSPanel_HA_Blueprint/labels/roadmap diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 511fad4..e64f9fd 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -106,7 +106,7 @@ blueprint: - label: 'HH:MM (ex. 08:30 and 20:30)' value: '%H:%M' - label: 'H:MM AM/PM (ex. 8:30AM and 8:30PM)' - value: '%-I:%M' + value: '%-I:%M %p' - label: 'H:MM 24H (ex. 8:30 and 20:30)' value: '%-H:%M' @@ -3517,8 +3517,6 @@ variables: }} time_format: !input 'time_format' - time: '{{ as_timestamp(now()) | timestamp_custom(time_format) }}' - meridiem: '{{ as_timestamp(now()) | timestamp_custom("%p") if time_format == "%-I:%M" }}' sun_is_up: '{{ is_state("sun.sun", "above_horizon") }}' notification_sound: 'switch.{{ nspanel_name }}_notification_sound' @@ -3570,6 +3568,7 @@ variables: set_button: 'esphome.{{ nspanel_name }}_set_button' set_entity: 'esphome.{{ nspanel_name }}_set_entity' set_climate: 'esphome.{{ nspanel_name }}_set_climate' + set_localization: 'esphome.{{ nspanel_name }}_set_localization' icon: domain: automation: "\uF6FC" #F6FC @@ -6081,34 +6080,6 @@ action: else ((page_home.general.time.label.color_rgb[0] //(2**3)) *(2**11))+((page_home.general.time.label.color_rgb[1] //(2**2)) *(2**5))+(page_home.general.time.label.color_rgb[2] //(2**3)) }} continue_on_error: true - ### TIME Font ### - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: home.time - message: '{{ time }}' - continue_on_error: true - - if: '{{ meridiem }}' - then: - ### TIME Meridiem Font Color ### - - *delay-default - - service: '{{ nextion.command.font_color }}' - data: - component: home.meridiem - message: > - {{ - page_home.general.time.label.color_rgb - if is_number(page_home.general.time.label.color_rgb) - else ((page_home.general.time.label.color_rgb[0] //(2**3)) *(2**11))+((page_home.general.time.label.color_rgb[1] //(2**2)) *(2**5))+(page_home.general.time.label.color_rgb[2] //(2**3)) - }} - continue_on_error: true - ### TIME Meridiem Font ### - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: home.meridiem - message: '{{ meridiem }}' - continue_on_error: true ##### BOOT NSPANEL - boot init ##### - alias: Boot init @@ -6152,6 +6123,11 @@ action: continue_on_error: true ##### Update Date & Time before showing the Home page ##### + - &set_localization + service: '{{ nextion.command.set_localization }}' + data: + time_format: '{{ time_format }}' + continue_on_error: true - *refresh-datetime ##### NSPanel boot init finished and jump to Home Page##### @@ -8617,6 +8593,7 @@ action: id: automation_reloaded sequence: ##### Update Date & Time before showing the pages (just in case display format changed) ##### + - *set_localization - *refresh-datetime - choose: @@ -8985,4 +8962,4 @@ action: ############################################################# ##### CLOSE - Action ##### -############################################################# +############################################################# \ No newline at end of file diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 16ee69c..41e2f70 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -25,6 +25,8 @@ substitutions: # dns: "10.0.0.138" # domain: ".local" + time_source: "homeassistant" # Either "homeassistant" or "sntp" are supported + ###### USE THIS ONLY FOR YOUR FIRST TFT UPLOAD ###### AND IF EXIT-REPARSE BUTTON FAILS ###### ONCE IT WORKED, REMOVE THESE LINES @@ -119,6 +121,47 @@ uart: # sequence: # - lambda: UARTDebug::log_string(direction, bytes); +### Keeps time display updated +time: + - platform: ${time_source} + id: time_provider + on_time: + - seconds: 0 + then: + - wait_until: + binary_sensor.is_on: nextion_init + - &refresh_datetime + lambda: |- + std::string time_format_str = id(mui_time_format); + if (time_format_str.find("%p") != std::string::npos) + { + std::string meridiem_text = id(time_provider).now().strftime("%p"); + id(disp1).set_component_text_printf("home.meridiem", "%s", meridiem_text.c_str()); + } + else { id(disp1).set_component_text_printf("home.meridiem", " "); } + if (time_format_str.find("%-H") != std::string::npos) { time_format_str = time_format_str.replace(time_format_str.find("%-H"), sizeof("%-H")-1, to_string((int)(id(time_provider).now().hour))); } + if (time_format_str.find("%-I") != std::string::npos) + { + if (id(time_provider).now().hour>12) + { + time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour-12))); + } + else if (id(time_provider).now().hour==0) + { + time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, "12"); + } + else + { + time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour))); + } + } + std::string time_text = id(time_provider).now().strftime(time_format_str); + id(disp1).set_component_text_printf("home.time", "%s", time_text.c_str()); + on_time_sync: + then: + - logger.log: "Synchronized system clock" + - *refresh_datetime + ##### START - BUTTON CONFIGURATION ##### button: ###### REBOOT BUTTON ##### @@ -467,6 +510,16 @@ api: id(disp1).send_command_printf("%s", entxcen.c_str()); } + ##### Service for localization of global vars ##### + - service: set_localization + variables: + time_format: string + then: + - lambda: |- + ESP_LOGD("set_localization", "time_format: %s", time_format.c_str()); + id(mui_time_format) = time_format; + - *refresh_datetime + ##### START - GLOBALS CONFIGURATION ##### globals: @@ -488,6 +541,16 @@ globals: restore_value: true initial_value: '0.0' + ##### Date/time formats ##### + #- id: mui_date_format + # type: std::string + # restore_value: no + # initial_value: '"%A, %d.%m"' + - id: mui_time_format + type: std::string + restore_value: no + initial_value: '"%H:%M"' + ##### START - BINARY SENSOR CONFIGURATION ##### binary_sensor: