From e2ca51454b1747c701b3e2bba2470ed5c6cd1e7b Mon Sep 17 00:00:00 2001 From: ujp83wi Date: Wed, 25 Aug 2021 14:44:17 +0200 Subject: [PATCH 1/5] [#12712 / #12713] Add SetOption129 which changes behavior of SwitchMode11 & 12: SetOption129 0 (default) triggers the single press event (State#2) at push (for mode 12 it is inverted) SetOption129 1 triggers the single press event (State#2) at release (for mode 12 it is inverted) This makes the double-click usable for other things than switching the relay which is switched by single-click --- tasmota/settings.h | 2 +- tasmota/support_switch.ino | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 9fb21e886..30a665cf0 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -158,7 +158,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t ds18x20_mean : 1; // bit 12 (v9.3.1.2) - SetOption126 - (DS18x20) Enable arithmetic mean over teleperiod for JSON temperature (1) uint32_t wifi_no_sleep : 1; // bit 13 (v9.5.0.2) - SetOption127 - (Wifi) Keep wifi in no-sleep mode, prevents some occasional unresponsiveness uint32_t disable_referer_chk : 1; // bit 14 (v9.5.0.5) - SetOption128 - (Web) Allow access without referer check - uint32_t spare15 : 1; // bit 15 + uint32_t switch_dimmer_act_at_rls : 1; // bit 15 (v9.5.0.7) - SetOption129 - (Switch) With Switchmode11 & 12, State#2 is tiggered at push (0, default) or release (1) uint32_t spare16 : 1; // bit 16 uint32_t spare17 : 1; // bit 17 uint32_t spare18 : 1; // bit 18 diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 68400e5a9..852cb595a 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -240,11 +240,14 @@ void SwitchHandler(uint32_t mode) { if (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) { Switch.hold_timer[i]--; if ((Switch.hold_timer[i] & SM_TIMER_MASK) == loops_per_second * Settings->param[P_HOLD_TIME] / 25) { - if ((switchmode == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) { - SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT - } - if ((switchmode == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i])) { - SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT + if ((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)){ + if (((switchmode == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) | ((switchmode == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i]))) { + SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT + } + else if ((Settings->flag5.switch_dimmer_act_at_rls) & ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS)) { + switchflag = POWER_TOGGLE; // Toggle with pushbutton + Switch.hold_timer[i] = 0; + } } } if (0 == (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) { @@ -351,7 +354,9 @@ void SwitchHandler(uint32_t mode) { if ((Switch.hold_timer[i] & SM_TIMER_MASK) > loops_per_second * Settings->param[P_HOLD_TIME] / 25) { if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - switchflag = POWER_TOGGLE; // Toggle with pushbutton + if (!Settings->flag5.switch_dimmer_act_at_rls){ + switchflag = POWER_TOGGLE; // Toggle with pushbutton + } } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT @@ -377,7 +382,9 @@ void SwitchHandler(uint32_t mode) { if ((Switch.hold_timer[i] & SM_TIMER_MASK)> loops_per_second * Settings->param[P_HOLD_TIME] / 25) { if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - switchflag = POWER_TOGGLE; // Toggle with pushbutton + if (!Settings->flag5.switch_dimmer_act_at_rls){ + switchflag = POWER_TOGGLE; // Toggle with pushbutton + } } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT From 5791908584e7053ae1d8d1614b7c02e764f922e2 Mon Sep 17 00:00:00 2001 From: ujp83wi Date: Wed, 25 Aug 2021 14:52:23 +0200 Subject: [PATCH 2/5] Commit Changelog entry based on previous commit for [#12712 / #12713] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d62165be9..5f2b38ee9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Turn HTTP API (command ``SetOption128 1``) default on for backward compatibility - Support for IEM3155 Wattmeter (#12940) - Berry support for vararg +- Switchmode11 and 12: ``SetOption129 1`` delays single press events from pressing to release switch (#12712 / #12713) ### Changed - Shelly EM template needs to use GPIO ADE7953_IRQ_2 From 1d5fd6f20a19b487510e9ef4abb5b15db1dbb61a Mon Sep 17 00:00:00 2001 From: Seestern93 <75477504+Seestern93@users.noreply.github.com> Date: Sun, 29 Aug 2021 23:03:14 +0200 Subject: [PATCH 3/5] SwitchState10 Add Switch#State=10 to SwitchMode11&12; Revert changes done by arendst (Switchmode17&18) as new proposal for integrating POWER_DELAYED into existing switch modes 11 & 12 --- tasmota/settings.h | 2 +- tasmota/support_switch.ino | 42 ++++++++++++------------------------- tasmota/support_tasmota.ino | 1 + tasmota/tasmota.h | 3 +-- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 30a665cf0..9fb21e886 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -158,7 +158,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t ds18x20_mean : 1; // bit 12 (v9.3.1.2) - SetOption126 - (DS18x20) Enable arithmetic mean over teleperiod for JSON temperature (1) uint32_t wifi_no_sleep : 1; // bit 13 (v9.5.0.2) - SetOption127 - (Wifi) Keep wifi in no-sleep mode, prevents some occasional unresponsiveness uint32_t disable_referer_chk : 1; // bit 14 (v9.5.0.5) - SetOption128 - (Web) Allow access without referer check - uint32_t switch_dimmer_act_at_rls : 1; // bit 15 (v9.5.0.7) - SetOption129 - (Switch) With Switchmode11 & 12, State#2 is tiggered at push (0, default) or release (1) + uint32_t spare15 : 1; // bit 15 uint32_t spare16 : 1; // bit 16 uint32_t spare17 : 1; // bit 17 uint32_t spare18 : 1; // bit 18 diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 4b1688c72..0c8d1e15a 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -37,7 +37,7 @@ const uint8_t AC_PERIOD = (20 + SWITCH_FAST_PROBE_INTERVAL - 1) / SWITCH_FAST_PR #define POWER_NONE 99 const char kSwitchPressStates[] PROGMEM = - "||||POWER_INCREMENT|POWER_INV|POWER_CLEAR|POWER_RELEASE|POWER_100|"; + "||||POWER_INCREMENT|POWER_INV|POWER_CLEAR|POWER_RELEASE|POWER_100|POWER_DELAYED"; #include @@ -237,32 +237,20 @@ void SwitchHandler(uint32_t mode) { uint32_t mqtt_action = POWER_NONE; uint32_t switchmode = Settings->switchmode[i]; - bool push_hold_multi_delay = ((PUSHHOLDMULTIDELAY == switchmode) || (PUSHHOLDMULTIDELAY_INV == switchmode)); - if (push_hold_multi_delay) { - switchmode -= (PUSHHOLDMULTIDELAY - PUSHHOLDMULTI); - } - bool push_hold_multi = ((PUSHHOLDMULTI == switchmode) || (PUSHHOLDMULTI_INV == switchmode)); - - if (Switch.hold_timer[i] & ((push_hold_multi) ? SM_TIMER_MASK : SM_NO_TIMER_MASK)) { + if (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) { Switch.hold_timer[i]--; if ((Switch.hold_timer[i] & SM_TIMER_MASK) == loops_per_second * Settings->param[P_HOLD_TIME] / 25) { - bool do_sendkey = false; - switch (switchmode) { - case PUSHHOLDMULTI: - do_sendkey = (NOT_PRESSED == Switch.last_state[i]); - break; - case PUSHHOLDMULTI_INV: - do_sendkey = (PRESSED == Switch.last_state[i]); - break; - } - if (do_sendkey) { - SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT - } else if (push_hold_multi_delay && ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS)) { - switchflag = POWER_TOGGLE; // Toggle with pushbutton - Switch.hold_timer[i] = 0; + if ((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)){ + if (((switchmode == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) | ((switchmode == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i]))) { + SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT + } + else if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) { + switchflag = POWER_DELAYED; // Toggle with pushbutton + Switch.hold_timer[i] = 0; + } } } - if (0 == (Switch.hold_timer[i] & ((push_hold_multi) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) { + if (0 == (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) { switch (switchmode) { case TOGGLEMULTI: switchflag = POWER_TOGGLE; // Toggle after hold @@ -365,9 +353,7 @@ void SwitchHandler(uint32_t mode) { if ((Switch.hold_timer[i] & SM_TIMER_MASK) > loops_per_second * Settings->param[P_HOLD_TIME] / 25) { if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - if (!push_hold_multi_delay) { - switchflag = POWER_TOGGLE; // Toggle with pushbutton - } + switchflag = POWER_TOGGLE; // Toggle with pushbutton } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT @@ -393,9 +379,7 @@ void SwitchHandler(uint32_t mode) { if ((Switch.hold_timer[i] & SM_TIMER_MASK)> loops_per_second * Settings->param[P_HOLD_TIME] / 25) { if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - if (!push_hold_multi_delay) { - switchflag = POWER_TOGGLE; // Toggle with pushbutton - } + switchflag = POWER_TOGGLE; // Toggle with pushbutton } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 22bb3a136..af5a9075e 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -515,6 +515,7 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state) // state 6 = POWER_CLEAR = button released // state 7 = POWER_RELEASE = button released // state 9 = CLEAR_RETAIN = clear retain flag +// state 10 = POWER_DELAYED = button released delayed char stopic[TOPSZ]; char scommand[CMDSZ]; diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 19f485329..5a475cc9d 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -280,8 +280,7 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D enum WifiConfigOptions {WIFI_RESTART, EX_WIFI_SMARTCONFIG, WIFI_MANAGER, EX_WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, - FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_INV, PUSH_IGNORE, PUSHNOTUSED, PUSHHOLDMULTIDELAY, - PUSHHOLDMULTIDELAY_INV, MAX_SWITCH_OPTION}; + FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_INV, PUSH_IGNORE, MAX_SWITCH_OPTION}; enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; From dbeb82c93e55b6a6268efcefb08e96df35df73c6 Mon Sep 17 00:00:00 2001 From: Seestern93 <75477504+Seestern93@users.noreply.github.com> Date: Sun, 29 Aug 2021 23:24:31 +0200 Subject: [PATCH 4/5] Update tasmota.h Add enum of new state#10 --- tasmota/tasmota.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 5a475cc9d..294384522 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -293,7 +293,7 @@ enum UploadTypes { UPL_TASMOTA = 1, UPL_SETTINGS, UPL_EFM8BB1, UPL_TASMOTACLIENT enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, POWER_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE, POWER_SHOW_STATE = 16 }; -enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7, POWER_100 = 8, CLEAR_RETAIN = 9 }; +enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7, POWER_100 = 8, CLEAR_RETAIN = 9, POWER_DELAYED = 10}; enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH }; enum SendKeyMultiClick { SINGLE = 10, DOUBLE = 11, TRIPLE = 12, QUAD = 13, PENTA = 14}; From d24221da004cd2ff5a50408f0c6f259169b56bcb Mon Sep 17 00:00:00 2001 From: Seestern93 <75477504+Seestern93@users.noreply.github.com> Date: Mon, 30 Aug 2021 00:13:40 +0200 Subject: [PATCH 5/5] Adapt action for state 10 Adapt action to execute switch#state=10 as needed. --- tasmota/support_switch.ino | 5 +++-- tasmota/tasmota.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 0c8d1e15a..485f932d9 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -37,7 +37,7 @@ const uint8_t AC_PERIOD = (20 + SWITCH_FAST_PROBE_INTERVAL - 1) / SWITCH_FAST_PR #define POWER_NONE 99 const char kSwitchPressStates[] PROGMEM = - "||||POWER_INCREMENT|POWER_INV|POWER_CLEAR|POWER_RELEASE|POWER_100|POWER_DELAYED"; + "||||POWER_INCREMENT|POWER_INV|POWER_CLEAR|POWER_RELEASE|POWER_100||POWER_DELAYED"; #include @@ -245,7 +245,8 @@ void SwitchHandler(uint32_t mode) { SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT } else if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) { - switchflag = POWER_DELAYED; // Toggle with pushbutton + SendKey(KEY_SWITCH, i +1, POWER_DELAYED); // Execute command via MQTT + mqtt_action = POWER_DELAYED; Switch.hold_timer[i] = 0; } } diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 294384522..6adc7ffb3 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -293,7 +293,8 @@ enum UploadTypes { UPL_TASMOTA = 1, UPL_SETTINGS, UPL_EFM8BB1, UPL_TASMOTACLIENT enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, POWER_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE, POWER_SHOW_STATE = 16 }; -enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7, POWER_100 = 8, CLEAR_RETAIN = 9, POWER_DELAYED = 10}; +enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7, + POWER_100 = 8, CLEAR_RETAIN = 9, POWER_DELAYED = 10 }; enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH }; enum SendKeyMultiClick { SINGLE = 10, DOUBLE = 11, TRIPLE = 12, QUAD = 13, PENTA = 14};