From 276524686a5ad17c44e3c2b7d694e54b81df5635 Mon Sep 17 00:00:00 2001 From: deejaybeam Date: Thu, 2 Feb 2023 17:52:41 +0100 Subject: [PATCH] upd: hw-button hold --- nspanel_blueprint.yaml | 8 ++++- nspanel_esphome.yaml | 78 ++++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index c7bc27c..32e4256 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3308,6 +3308,8 @@ action: {%- elif states(last_click) == "pressbuttonpage04button06" -%} {{ entity30 }} {%- elif states(last_click) == "pressbuttonpage04button07" -%} {{ entity31 }} {%- elif states(last_click) == "pressbuttonpage04button08" -%} {{ entity32 }} + {%- elif states(last_click) == "pressbuttonleft" -%} {{ left_button_entity }} + {%- elif states(last_click) == "pressbuttonright" -%} {{ right_button_entity }} {%- endif -%} ##### Entity Name - Page Lightsettings ##### @@ -3340,10 +3342,12 @@ action: {%- elif states(last_click) == "pressbuttonpage04button02" -%} {{ entity26_name }} {%- elif states(last_click) == "pressbuttonpage04button03" -%} {{ entity27_name }} {%- elif states(last_click) == "pressbuttonpage04button04" -%} {{ entity28_name }} - {%- elif states(last_click) == "pressbuttonpage04button05" -%} {{ entity29_name}} + {%- elif states(last_click) == "pressbuttonpage04button05" -%} {{ entity29_name }} {%- elif states(last_click) == "pressbuttonpage04button06" -%} {{ entity30_name }} {%- elif states(last_click) == "pressbuttonpage04button07" -%} {{ entity31_name }} {%- elif states(last_click) == "pressbuttonpage04button08" -%} {{ entity32_name }} + {%- elif states(last_click) == "pressbuttonleft" -%} {{ left_button_name }} + {%- elif states(last_click) == "pressbuttonright" -%} {{ right_button_name }} {%- endif -%} ##### Entity - Page Lightsettings - Skip Back ##### @@ -3380,6 +3384,8 @@ action: {%- elif states(last_click) == "pressbuttonpage04button06" -%} {{ "page buttonpage04" }} {%- elif states(last_click) == "pressbuttonpage04button07" -%} {{ "page buttonpage04" }} {%- elif states(last_click) == "pressbuttonpage04button08" -%} {{ "page buttonpage04" }} + {%- elif states(last_click) == "pressbuttonleft" -%} {{ "page home" }} + {%- elif states(last_click) == "pressbuttonright" -%} {{ "page home" }} {%- endif -%} ######################################################################################################################## diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index e0a6405..6cda307 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -345,15 +345,11 @@ binary_sensor: inverted: true on_click: - min_length: 50ms - max_length: 999ms + max_length: 1000ms then: - binary_sensor.template.publish: id: left_button_short state: ON - - delay: 500ms - - binary_sensor.template.publish: - id: left_button_short - state: OFF - if: condition: and: @@ -369,28 +365,35 @@ binary_sensor: switch.is_on: relay_1 then: - lambda: id(disp1).send_command_printf("home.icon_top_01.pic=105"); - - min_length: 1000ms - max_length: 10000ms - then: - - binary_sensor.template.publish: - id: left_button_hold - state: ON - delay: 500ms - binary_sensor.template.publish: - id: left_button_hold + id: left_button_short state: OFF + on_press: + then: + - lambda: |- + if (id(disp1_currentpage).state == "lightsettings" or id(disp1_currentpage).state == "coversettings") { + ESP_LOGD("nspanel", "settingspage -> no press"); + } else { + // ESP_LOGD("nspanel", "release button"); + id(disp1_lastclick_general).set_state("pressbuttonleft",true,true); + } + on_release: + then: + - lambda: |- + if (id(disp1_currentpage).state == "lightsettings" or id(disp1_currentpage).state == "coversettings") { + ESP_LOGD("nspanel", "settingspage -> no release"); + } else { + // ESP_LOGD("nspanel", "release button"); + id(disp1_lastclick_general).set_state("releasebuttonleft",true,true); + } - platform: template name: ${device_name} Left Button id: left_button_short lambda: |- return {}; - - - platform: template - name: ${device_name} Left Button hold - id: left_button_hold - lambda: |- - return {}; + ##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY ##### - platform: gpio @@ -401,15 +404,11 @@ binary_sensor: inverted: true on_click: - min_length: 50ms - max_length: 999ms + max_length: 1000ms then: - binary_sensor.template.publish: id: right_button_short state: ON - - delay: 500ms - - binary_sensor.template.publish: - id: right_button_short - state: OFF - if: condition: and: @@ -425,29 +424,34 @@ binary_sensor: switch.is_on: relay_2 then: - lambda: id(disp1).send_command_printf("home.icon_top_02.pic=106"); - - - min_length: 1000ms - max_length: 10000ms - then: - - binary_sensor.template.publish: - id: right_button_hold - state: ON - delay: 500ms - binary_sensor.template.publish: - id: right_button_hold + id: right_button_short state: OFF + on_press: + then: + - lambda: |- + if (id(disp1_currentpage).state == "lightsettings" or id(disp1_currentpage).state == "coversettings") { + ESP_LOGD("nspanel", "settingspage -> no press"); + } else { + // ESP_LOGD("nspanel", "release button"); + id(disp1_lastclick_general).set_state("pressbuttonright",true,true); + } + on_release: + then: + - lambda: |- + if (id(disp1_currentpage).state == "lightsettings" or id(disp1_currentpage).state == "coversettings") { + ESP_LOGD("nspanel", "settingspage -> no release"); + } else { + // ESP_LOGD("nspanel", "release button"); + id(disp1_lastclick_general).set_state("releasebuttonright",true,true); + } - platform: template name: ${device_name} Right Button id: right_button_short lambda: |- return {}; - - - platform: template - name: ${device_name} Right Button hold - id: right_button_hold - lambda: |- - return {}; ##### Restart NSPanel Button - Setting Page ##### - platform: nextion