From 64659f379427d257ae0e0ebe38579e0b15676775 Mon Sep 17 00:00:00 2001 From: Edward Firmo Date: Mon, 3 Jul 2023 08:14:32 +0200 Subject: [PATCH] Physical relay local control We are trying to make your panel as autonomous as possible by moving some of the controls from the Blueprint to ESPHome. This will reduce the load in your network and Home Assistant, but also will make a more reliable system capable to do it's core functionality even when the network is unavailable or Home Assistant is restarting. With this version, the following engines have been moved to your panel (local control): - Physical relay control (when hardware left button is connected to relay 1 or right button to relay 2) Solves #910 --- ReleaseNotes.md | 11 ++++---- nspanel_blueprint.yaml | 13 ++++++++-- nspanel_esphome.yaml | 58 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index a178876..a9a39af 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -43,7 +43,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 ([#ec99b83](https://github.com/Blackymas/NSPanel_HA_Blueprint/commit/ec99b83817be5b36a94c2da3060d0bd0032e419e)) +11. Panel's local control   ## Details of all changes @@ -107,10 +107,11 @@ 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. +### 11. Panel's local control +We are trying to make your panel as autonomous as possible by moving some of the controls from the Blueprint to ESPHome. This will reduce the load in your network and Home Assistant, but also will make a more reliable system capable to do it's core functionality even when the network is unavailable or Home Assistant is restarting. +With this version, the following engines have been moved to your panel (local control): +- Time display +- Physical relay control (when hardware left button is connected to relay 1 or right button to relay 2)   ## Next topics we are currently working on diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index a168b4e..f44d362 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3569,6 +3569,7 @@ variables: set_entity: 'esphome.{{ nspanel_name }}_set_entity' set_climate: 'esphome.{{ nspanel_name }}_set_climate' set_localization: 'esphome.{{ nspanel_name }}_set_localization' + set_relay_local: 'esphome.{{ nspanel_name }}_set_relay_local' icon: domain: automation: "\uF6FC" #F6FC @@ -6106,6 +6107,12 @@ action: data: entity_id: "switch.{{ nspanel_name }}_relay_2_local_fallback" continue_on_error: true + - &set_relay_local + service: '{{ nextion.command.set_relay_local }}' + data: + relay1: '{{ page_home.hardware.buttons.left.entity == relay01_entity }}' + relay2: '{{ page_home.hardware.buttons.right.entity == relay02_entity }}' + continue_on_error: true ##### clear notification icon ##### - service: '{{ nextion.command.notification_clear }}' @@ -8601,6 +8608,7 @@ action: sequence: ##### Update Date & Time before showing the pages (just in case display format changed) ##### - *set_localization + - *set_relay_local - *refresh-datetime - choose: @@ -8874,8 +8882,9 @@ action: - conditions: '{{ button_context.hold_select == "Custom Action" and trigger.id == "right_button_press" }}' sequence: !input right_button_hold_custom_action else: # Single Click - - condition: template - value_template: '{{ button_context.entity | length > 0 }}' + - condition: '{{ button_context.entity | length > 0 }}' + - condition: '{{ trigger.id != "left_button_press" or page_home.hardware.buttons.left.entity != relay01_entity }}' ### Prevents blueprint control when locally controlled + - condition: '{{ trigger.id != "right_button_press" or page_home.hardware.buttons.right.entity != relay02_entity }}' ### Prevents blueprint control when locally controlled - service: > {% if button_domain in ["light", "switch", "cover", "input_boolean", "automation", "fan"] %} {{ button_domain }}.toggle diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 41e2f70..f3ecb96 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -520,6 +520,16 @@ api: id(mui_time_format) = time_format; - *refresh_datetime + ##### Service for setting relays as locally controlled ##### + - service: set_relay_local + variables: + relay1: bool + relay2: bool + then: + - lambda: |- + id(relay1_local).publish_state(relay1); + id(relay2_local).publish_state(relay2); + ##### START - GLOBALS CONFIGURATION ##### globals: @@ -565,10 +575,12 @@ binary_sensor: then: - if: condition: - and: - - switch.is_on: relay1_fallback - - not: - api.connected: + or: + - switch.is_on: relay1_local + - and: + - switch.is_on: relay1_fallback + - not: + api.connected: then: - switch.toggle: relay_1 - if: @@ -592,10 +604,12 @@ binary_sensor: then: - if: condition: - and: - - switch.is_on: relay2_fallback - - not: - api.connected: + or: + - switch.is_on: relay2_local + - and: + - switch.is_on: relay2_fallback + - not: + api.connected: then: - switch.toggle: relay_2 - if: @@ -608,7 +622,6 @@ binary_sensor: - lambda: id(disp1).send_command_printf("home.right_bt_pic.pic=77"); - lambda: id(disp1).send_command_printf("home.icon_top_02","\U0000FFFF"); - ##### Restart NSPanel Button - Setting Page ##### - name: ${device_name} Restart platform: nextion @@ -893,6 +906,32 @@ switch: id: sleep_mode state: OFF + ##### Relay Local control ##### + - name: ${device_name} Relay 1 Local + platform: template + id: relay1_local + entity_category: config + restore_state: true + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF + internal: true + on_turn_on: + - logger.log: "Relay 1 Local turned On!" + on_turn_off: + - logger.log: "Relay 1 Local turned Off!" + - name: ${device_name} Relay 2 Local + platform: template + id: relay2_local + entity_category: config + restore_state: true + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF + internal: true + on_turn_on: + - logger.log: "Relay 2 Local turned On!" + on_turn_off: + - logger.log: "Relay 2 Local turned Off!" + ##### Relay Local control Fallback ##### - name: ${device_name} Relay 1 Local Fallback platform: template @@ -901,7 +940,6 @@ switch: restore_state: true optimistic: true restore_mode: RESTORE_DEFAULT_OFF - - name: ${device_name} Relay 2 Local Fallback platform: template id: relay2_fallback