mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 19:56:30 +00:00
Breaking change when `SetOption73 1
`
Breaking change when ``SetOption73 1`` JSON result from `{"ACTION":"SINGLE"}` to `{"Button1":{"Action":"SINGLE"}}`
This commit is contained in:
parent
54f9532919
commit
9f191d9214
@ -16,13 +16,14 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Zigbee command ``ZbOccupancy`` to configure the time-out for PIR
|
- Zigbee command ``ZbOccupancy`` to configure the time-out for PIR
|
||||||
- Command ``Gpios 255`` to show all possible GPIO configurations
|
- Command ``Gpios 255`` to show all possible GPIO configurations
|
||||||
- Command ``SwitchText`` to change JSON switch names by barbudor (#9691)
|
- Command ``SwitchText`` to change JSON switch names by barbudor (#9691)
|
||||||
- Command ``SetOption114 1`` to detach Swiches from Relays and enable MQTT action state for all the SwitchModes
|
- Command ``SetOption114 1`` to detach Swiches from Relays and enable MQTT action state for all the SwitchModes returning `{"Switch1":{"Action":"ON"}}`
|
||||||
- HM10 Beacon support and refactoring by Christian Baars (#9702)
|
- HM10 Beacon support and refactoring by Christian Baars (#9702)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- PlatformIO library structure redesigned for compilation speed by Jason2866
|
- PlatformIO library structure redesigned for compilation speed by Jason2866
|
||||||
- Zigbee flash storage refactor adding commands ``ZbProbe``, ``ZbStatus2`` and ``ZbRestore`` (#9641)
|
- Zigbee flash storage refactor adding commands ``ZbProbe``, ``ZbStatus2`` and ``ZbRestore`` (#9641)
|
||||||
- Default otaurl in my_user_config.h to http://ota.tasmota.com/tasmota/release/tasmota.bin.gz
|
- Default otaurl in my_user_config.h to http://ota.tasmota.com/tasmota/release/tasmota.bin.gz
|
||||||
|
- When ``SetOption73 1`` JSON result from `{"ACTION":"SINGLE"}` to `{"Button1":{"Action":"SINGLE"}}`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Rule Break not working as expected when ONCE is enabled (#9245)
|
- Rule Break not working as expected when ONCE is enabled (#9245)
|
||||||
|
@ -90,6 +90,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
|
|||||||
- TLS fingerprint ``#define MQTT_FINGERPRINT`` from string to hexnumbers (#9570)
|
- TLS fingerprint ``#define MQTT_FINGERPRINT`` from string to hexnumbers (#9570)
|
||||||
- Command ``Status`` output for disabled status types now returns {"Command":"Error"}
|
- Command ``Status`` output for disabled status types now returns {"Command":"Error"}
|
||||||
- MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103)
|
- MAX31865 driver to support up to 6 thermocouples selected by ``MX31865 CS`` instead of ``SSPI CS`` (#9103)
|
||||||
|
- When ``SetOption73 1`` JSON result from `{"ACTION":"SINGLE"}` to `{"Button1":{"Action":"SINGLE"}}`
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Command ``Gpio17`` replaces command ``Adc``
|
- Command ``Gpio17`` replaces command ``Adc``
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#define D_JSON_BOOTVERSION "Boot"
|
#define D_JSON_BOOTVERSION "Boot"
|
||||||
#define D_JSON_BOOTCOUNT "BootCount"
|
#define D_JSON_BOOTCOUNT "BootCount"
|
||||||
#define D_JSON_BSSID "BSSId"
|
#define D_JSON_BSSID "BSSId"
|
||||||
|
#define D_JSON_BUTTON "Button"
|
||||||
#define D_JSON_BUILDDATETIME "BuildDateTime"
|
#define D_JSON_BUILDDATETIME "BuildDateTime"
|
||||||
#define D_JSON_CHANNEL "Channel"
|
#define D_JSON_CHANNEL "Channel"
|
||||||
#define D_JSON_CO2 "CarbonDioxide"
|
#define D_JSON_CO2 "CarbonDioxide"
|
||||||
|
@ -61,23 +61,21 @@ struct TOUCH_BUTTON {
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void ButtonPullupFlag(uint8 button_bit)
|
void ButtonPullupFlag(uint32_t button_bit) {
|
||||||
{
|
|
||||||
bitSet(Button.no_pullup_mask, button_bit);
|
bitSet(Button.no_pullup_mask, button_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonInvertFlag(uint8 button_bit)
|
void ButtonInvertFlag(uint32_t button_bit) {
|
||||||
{
|
|
||||||
bitSet(Button.inverted_mask, button_bit);
|
bitSet(Button.inverted_mask, button_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
void ButtonTouchFlag(uint8 button_bit)
|
void ButtonTouchFlag(uint32_t button_bit) {
|
||||||
{
|
|
||||||
bitSet(Button.touch_mask, button_bit);
|
bitSet(Button.touch_mask, button_bit);
|
||||||
}
|
}
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
void ButtonInit(void)
|
|
||||||
{
|
void ButtonInit(void) {
|
||||||
Button.present = 0;
|
Button.present = 0;
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
if ((SONOFF_DUAL == TasmotaGlobal.module_type) || (CH4 == TasmotaGlobal.module_type)) {
|
||||||
@ -101,8 +99,7 @@ void ButtonInit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ButtonSerial(uint8_t serial_in_byte)
|
uint8_t ButtonSerial(uint8_t serial_in_byte) {
|
||||||
{
|
|
||||||
if (Button.dual_receive_count) {
|
if (Button.dual_receive_count) {
|
||||||
Button.dual_receive_count--;
|
Button.dual_receive_count--;
|
||||||
if (Button.dual_receive_count) {
|
if (Button.dual_receive_count) {
|
||||||
@ -133,8 +130,7 @@ uint8_t ButtonSerial(uint8_t serial_in_byte)
|
|||||||
* SetOption73 (0) - Decouple button from relay and send just mqtt topic
|
* SetOption73 (0) - Decouple button from relay and send just mqtt topic
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void ButtonHandler(void)
|
void ButtonHandler(void) {
|
||||||
{
|
|
||||||
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
||||||
|
|
||||||
uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command
|
uint8_t hold_time_extent = IMMINENT_RESET_FACTOR; // Extent hold time factor in case of iminnent Reset command
|
||||||
@ -355,8 +351,8 @@ void ButtonHandler(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttButtonTopic(uint8_t button_id, uint8_t action, uint8_t hold)
|
/*
|
||||||
{
|
void MqttButtonTopic(uint8_t button_id, uint8_t action, uint8_t hold) {
|
||||||
char scommand[CMDSZ];
|
char scommand[CMDSZ];
|
||||||
char stopic[TOPSZ];
|
char stopic[TOPSZ];
|
||||||
char mqttstate[7];
|
char mqttstate[7];
|
||||||
@ -371,9 +367,19 @@ void MqttButtonTopic(uint8_t button_id, uint8_t action, uint8_t hold)
|
|||||||
MqttPublish(stopic);
|
MqttPublish(stopic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void ButtonLoop(void)
|
void MqttButtonTopic(uint32_t button_id, uint32_t action, uint32_t hold) {
|
||||||
{
|
SendKey(KEY_BUTTON, button_id, (hold) ? 3 : action +9);
|
||||||
|
|
||||||
|
if (!Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistant automatic discovery (See SetOption59)
|
||||||
|
char mqttstate[7];
|
||||||
|
Response_P(PSTR("{\"" D_JSON_BUTTON "%d\":{\"Action\":\"%s\"}}"), button_id, (hold) ? SettingsText(SET_STATE_TXT4) : GetTextIndexed(mqttstate, sizeof(mqttstate), action, kMultiPress));
|
||||||
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_BUTTON));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonLoop(void) {
|
||||||
if (Button.present) {
|
if (Button.present) {
|
||||||
if (TimeReached(Button.debounce)) {
|
if (TimeReached(Button.debounce)) {
|
||||||
SetNextTimeInterval(Button.debounce, Settings.button_debounce); // ButtonDebounce (50)
|
SetNextTimeInterval(Button.debounce, Settings.button_debounce); // ButtonDebounce (50)
|
||||||
|
@ -56,28 +56,23 @@ struct SWITCH {
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void SwitchPullupFlag(uint16 switch_bit)
|
void SwitchPullupFlag(uint32 switch_bit) {
|
||||||
{
|
|
||||||
bitSet(Switch.no_pullup_mask, switch_bit);
|
bitSet(Switch.no_pullup_mask, switch_bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchSetVirtual(uint32_t index, uint8_t state)
|
void SwitchSetVirtual(uint32_t index, uint32_t state) {
|
||||||
{
|
|
||||||
Switch.virtual_state[index] = state;
|
Switch.virtual_state[index] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SwitchGetVirtual(uint32_t index)
|
uint8_t SwitchGetVirtual(uint32_t index) {
|
||||||
{
|
|
||||||
return Switch.virtual_state[index];
|
return Switch.virtual_state[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t SwitchLastState(uint32_t index)
|
uint8_t SwitchLastState(uint32_t index) {
|
||||||
{
|
|
||||||
return Switch.last_state[index];
|
return Switch.last_state[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwitchState(uint32_t index)
|
bool SwitchState(uint32_t index) {
|
||||||
{
|
|
||||||
uint32_t switchmode = Settings.switchmode[index];
|
uint32_t switchmode = Settings.switchmode[index];
|
||||||
return ((FOLLOW_INV == switchmode) ||
|
return ((FOLLOW_INV == switchmode) ||
|
||||||
(PUSHBUTTON_INV == switchmode) ||
|
(PUSHBUTTON_INV == switchmode) ||
|
||||||
@ -90,17 +85,16 @@ bool SwitchState(uint32_t index)
|
|||||||
|
|
||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
void SwitchProbe(void)
|
void SwitchProbe(void) {
|
||||||
{
|
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
||||||
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
|
||||||
|
|
||||||
uint8_t state_filter;
|
uint32_t state_filter;
|
||||||
uint8_t debounce_flags = Settings.switch_debounce % 10;
|
uint32_t switch_probe_interval;
|
||||||
uint8_t force_high = debounce_flags &1; // 51, 101, 151 etc
|
uint32_t first_change = Switch.first_change;
|
||||||
uint8_t force_low = debounce_flags &2; // 52, 102, 152 etc
|
uint32_t debounce_flags = Settings.switch_debounce % 10;
|
||||||
uint8_t ac_detect = debounce_flags == 9;
|
bool force_high = (debounce_flags &1); // 51, 101, 151 etc
|
||||||
uint8_t switch_probe_interval;
|
bool force_low = (debounce_flags &2); // 52, 102, 152 etc
|
||||||
uint8_t first_change = Switch.first_change;
|
bool ac_detect = (debounce_flags == 9);
|
||||||
|
|
||||||
if (ac_detect) {
|
if (ac_detect) {
|
||||||
switch_probe_interval = SWITCH_FAST_PROBE_INTERVAL;
|
switch_probe_interval = SWITCH_FAST_PROBE_INTERVAL;
|
||||||
@ -121,7 +115,7 @@ void SwitchProbe(void)
|
|||||||
// Olimex user_switch2.c code to fix 50Hz induced pulses
|
// Olimex user_switch2.c code to fix 50Hz induced pulses
|
||||||
if (1 == digitalRead(Pin(GPIO_SWT1, i))) {
|
if (1 == digitalRead(Pin(GPIO_SWT1, i))) {
|
||||||
|
|
||||||
if (ac_detect) { // Enabled with SwitchDebounce x9
|
if (ac_detect) { // Enabled with SwitchDebounce x9
|
||||||
Switch.state[i] |= 0x80;
|
Switch.state[i] |= 0x80;
|
||||||
if (Switch.state[i] > 0x80) {
|
if (Switch.state[i] > 0x80) {
|
||||||
Switch.state[i]--;
|
Switch.state[i]--;
|
||||||
@ -132,9 +126,9 @@ void SwitchProbe(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (force_high) { // Enabled with SwitchDebounce x1
|
if (force_high) { // Enabled with SwitchDebounce x1
|
||||||
if (1 == Switch.virtual_state[i]) {
|
if (1 == Switch.virtual_state[i]) {
|
||||||
Switch.state[i] = state_filter; // With noisy input keep current state 1 unless constant 0
|
Switch.state[i] = state_filter; // With noisy input keep current state 1 unless constant 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +141,7 @@ void SwitchProbe(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (ac_detect) { // Enabled with SwitchDebounce x9
|
if (ac_detect) { // Enabled with SwitchDebounce x9
|
||||||
/*
|
/*
|
||||||
* Moes MS-104B and similar devices using an AC detection circuitry
|
* Moes MS-104B and similar devices using an AC detection circuitry
|
||||||
* on their switch inputs generating an ~4 ms long low pulse every
|
* on their switch inputs generating an ~4 ms long low pulse every
|
||||||
@ -178,9 +172,9 @@ void SwitchProbe(void)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (force_low) { // Enabled with SwitchDebounce x2
|
if (force_low) { // Enabled with SwitchDebounce x2
|
||||||
if (0 == Switch.virtual_state[i]) {
|
if (0 == Switch.virtual_state[i]) {
|
||||||
Switch.state[i] = 0; // With noisy input keep current state 0 unless constant 1
|
Switch.state[i] = 0; // With noisy input keep current state 0 unless constant 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,9 +191,8 @@ void SwitchProbe(void)
|
|||||||
TickerSwitch.attach_ms(switch_probe_interval, SwitchProbe); // Re-arm as core 2.3.0 does only support ONCE mode
|
TickerSwitch.attach_ms(switch_probe_interval, SwitchProbe); // Re-arm as core 2.3.0 does only support ONCE mode
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchInit(void)
|
void SwitchInit(void) {
|
||||||
{
|
bool ac_detect = (Settings.switch_debounce % 10 == 9);
|
||||||
uint8_t ac_detect = Settings.switch_debounce % 10 == 9;
|
|
||||||
|
|
||||||
Switch.present = 0;
|
Switch.present = 0;
|
||||||
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
|
for (uint32_t i = 0; i < MAX_SWITCHES; i++) {
|
||||||
@ -234,9 +227,8 @@ void SwitchInit(void)
|
|||||||
* Switch handler
|
* Switch handler
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void SwitchHandler(uint8_t mode)
|
void SwitchHandler(uint32_t mode) {
|
||||||
{
|
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
||||||
if (TasmotaGlobal.uptime < 4) { return; } // Block GPIO for 4 seconds after poweron to workaround Wemos D1 / Obi RTS circuit
|
|
||||||
|
|
||||||
uint32_t loops_per_second = 1000 / Settings.switch_debounce;
|
uint32_t loops_per_second = 1000 / Settings.switch_debounce;
|
||||||
|
|
||||||
@ -244,55 +236,55 @@ void SwitchHandler(uint8_t mode)
|
|||||||
if (PinUsed(GPIO_SWT1, i) || (mode)) {
|
if (PinUsed(GPIO_SWT1, i) || (mode)) {
|
||||||
uint32_t button = Switch.virtual_state[i];
|
uint32_t button = Switch.virtual_state[i];
|
||||||
uint32_t switchflag = POWER_TOGGLE +1;
|
uint32_t switchflag = POWER_TOGGLE +1;
|
||||||
uint32_t MqttAction = POWER_NONE;
|
uint32_t mqtt_action = POWER_NONE;
|
||||||
|
|
||||||
if (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) {
|
if (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) {
|
||||||
Switch.hold_timer[i]--;
|
Switch.hold_timer[i]--;
|
||||||
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) == loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||||
if ((Settings.switchmode[i] == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) {
|
if ((Settings.switchmode[i] == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) {
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||||
}
|
}
|
||||||
if ((Settings.switchmode[i] == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i])) {
|
if ((Settings.switchmode[i] == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i])) {
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 == (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) {
|
if (0 == (Switch.hold_timer[i] & (((Settings.switchmode[i] == PUSHHOLDMULTI) | (Settings.switchmode[i] == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) {
|
||||||
switch (Settings.switchmode[i]) {
|
switch (Settings.switchmode[i]) {
|
||||||
case TOGGLEMULTI:
|
case TOGGLEMULTI:
|
||||||
switchflag = POWER_TOGGLE; // Toggle after hold
|
switchflag = POWER_TOGGLE; // Toggle after hold
|
||||||
break;
|
break;
|
||||||
case FOLLOWMULTI:
|
case FOLLOWMULTI:
|
||||||
switchflag = button &1; // Follow wall switch state after hold
|
switchflag = button &1; // Follow wall switch state after hold
|
||||||
break;
|
break;
|
||||||
case FOLLOWMULTI_INV:
|
case FOLLOWMULTI_INV:
|
||||||
switchflag = ~button &1; // Follow inverted wall switch state after hold
|
switchflag = ~button &1; // Follow inverted wall switch state after hold
|
||||||
break;
|
break;
|
||||||
case PUSHHOLDMULTI:
|
case PUSHHOLDMULTI:
|
||||||
if (NOT_PRESSED == button) {
|
if (NOT_PRESSED == button) {
|
||||||
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
|
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||||
MqttAction = POWER_INCREMENT;
|
mqtt_action = POWER_INCREMENT;
|
||||||
} else {
|
} else {
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
|
||||||
MqttAction = POWER_CLEAR;
|
mqtt_action = POWER_CLEAR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHHOLDMULTI_INV:
|
case PUSHHOLDMULTI_INV:
|
||||||
if (PRESSED == button) {
|
if (PRESSED == button) {
|
||||||
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
|
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
|
||||||
MqttAction = POWER_INCREMENT;
|
mqtt_action = POWER_INCREMENT;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
|
||||||
MqttAction = POWER_CLEAR;
|
mqtt_action = POWER_CLEAR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
|
||||||
MqttAction = POWER_HOLD;
|
mqtt_action = POWER_HOLD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,22 +294,22 @@ void SwitchHandler(uint8_t mode)
|
|||||||
switch (Settings.switchmode[i]) {
|
switch (Settings.switchmode[i]) {
|
||||||
case TOGGLE:
|
case TOGGLE:
|
||||||
case PUSHBUTTON_TOGGLE:
|
case PUSHBUTTON_TOGGLE:
|
||||||
switchflag = POWER_TOGGLE; // Toggle
|
switchflag = POWER_TOGGLE; // Toggle
|
||||||
break;
|
break;
|
||||||
case FOLLOW:
|
case FOLLOW:
|
||||||
switchflag = button &1; // Follow wall switch state
|
switchflag = button &1; // Follow wall switch state
|
||||||
break;
|
break;
|
||||||
case FOLLOW_INV:
|
case FOLLOW_INV:
|
||||||
switchflag = ~button &1; // Follow inverted wall switch state
|
switchflag = ~button &1; // Follow inverted wall switch state
|
||||||
break;
|
break;
|
||||||
case PUSHBUTTON:
|
case PUSHBUTTON:
|
||||||
if (PRESSED == button) {
|
if (PRESSED == button) {
|
||||||
switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd
|
switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHBUTTON_INV:
|
case PUSHBUTTON_INV:
|
||||||
if (NOT_PRESSED == button) {
|
if (NOT_PRESSED == button) {
|
||||||
switchflag = POWER_TOGGLE; // Toggle with releasing pushbutton from Gnd
|
switchflag = POWER_TOGGLE; // Toggle with releasing pushbutton from Gnd
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHBUTTONHOLD:
|
case PUSHBUTTONHOLD:
|
||||||
@ -325,8 +317,8 @@ void SwitchHandler(uint8_t mode)
|
|||||||
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press
|
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press
|
||||||
}
|
}
|
||||||
if ((NOT_PRESSED == button) && (Switch.hold_timer[i])) {
|
if ((NOT_PRESSED == button) && (Switch.hold_timer[i])) {
|
||||||
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer...
|
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer...
|
||||||
switchflag = POWER_TOGGLE; // ...and Toggle
|
switchflag = POWER_TOGGLE; // ...and Toggle
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHBUTTONHOLD_INV:
|
case PUSHBUTTONHOLD_INV:
|
||||||
@ -334,8 +326,8 @@ void SwitchHandler(uint8_t mode)
|
|||||||
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press...
|
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press...
|
||||||
}
|
}
|
||||||
if ((PRESSED == button) && (Switch.hold_timer[i])) {
|
if ((PRESSED == button) && (Switch.hold_timer[i])) {
|
||||||
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer.
|
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer.
|
||||||
switchflag = POWER_TOGGLE; // ...and Toggle
|
switchflag = POWER_TOGGLE; // ...and Toggle
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOGGLEMULTI:
|
case TOGGLEMULTI:
|
||||||
@ -343,34 +335,34 @@ void SwitchHandler(uint8_t mode)
|
|||||||
case FOLLOWMULTI_INV:
|
case FOLLOWMULTI_INV:
|
||||||
if (Switch.hold_timer[i]) {
|
if (Switch.hold_timer[i]) {
|
||||||
Switch.hold_timer[i] = 0;
|
Switch.hold_timer[i] = 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
|
||||||
MqttAction = POWER_HOLD;
|
mqtt_action = POWER_HOLD;
|
||||||
} else {
|
} else {
|
||||||
Switch.hold_timer[i] = loops_per_second / 2; // 0.5 second multi press window
|
Switch.hold_timer[i] = loops_per_second / 2; // 0.5 second multi press window
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHHOLDMULTI:
|
case PUSHHOLDMULTI:
|
||||||
if (NOT_PRESSED == button) {
|
if (NOT_PRESSED == button) {
|
||||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
||||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
||||||
MqttAction = POWER_INV;
|
mqtt_action = POWER_INV;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
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) > loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||||
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
||||||
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
||||||
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT
|
||||||
MqttAction = POWER_100;
|
mqtt_action = POWER_100;
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
||||||
MqttAction = POWER_RELEASE;
|
mqtt_action = POWER_RELEASE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||||
@ -379,36 +371,36 @@ void SwitchHandler(uint8_t mode)
|
|||||||
if (PRESSED == button) {
|
if (PRESSED == button) {
|
||||||
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
if ((Switch.hold_timer[i] & SM_TIMER_MASK) != 0) {
|
||||||
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
Switch.hold_timer[i] = ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS) ? SM_SECOND_PRESS : 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT
|
||||||
MqttAction = POWER_INV;
|
mqtt_action = POWER_INV;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
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)> loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
|
||||||
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) {
|
||||||
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
Switch.hold_timer[i]= SM_FIRST_PRESS;
|
||||||
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
switchflag = POWER_TOGGLE; // Toggle with pushbutton
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT
|
||||||
MqttAction = POWER_100;
|
mqtt_action = POWER_100;
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Switch.hold_timer[i]= 0;
|
Switch.hold_timer[i]= 0;
|
||||||
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
|
||||||
MqttAction = POWER_RELEASE;
|
mqtt_action = POWER_RELEASE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
Switch.hold_timer[i] = (Switch.hold_timer[i] & ~SM_TIMER_MASK) | loops_per_second * Settings.param[P_HOLD_TIME] / 10;
|
||||||
break;
|
break;
|
||||||
case PUSHON:
|
case PUSHON:
|
||||||
if (PRESSED == button) {
|
if (PRESSED == button) {
|
||||||
switchflag = POWER_ON; // Power ON with pushbutton to Gnd
|
switchflag = POWER_ON; // Power ON with pushbutton to Gnd
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSHON_INV:
|
case PUSHON_INV:
|
||||||
if (NOT_PRESSED == button) {
|
if (NOT_PRESSED == button) {
|
||||||
switchflag = POWER_ON; // Power ON with releasing pushbutton from Gnd
|
switchflag = POWER_ON; // Power ON with releasing pushbutton from Gnd
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUSH_IGNORE:
|
case PUSH_IGNORE:
|
||||||
@ -418,35 +410,31 @@ void SwitchHandler(uint8_t mode)
|
|||||||
Switch.last_state[i] = button;
|
Switch.last_state[i] = button;
|
||||||
}
|
}
|
||||||
if (switchflag <= POWER_TOGGLE) {
|
if (switchflag <= POWER_TOGGLE) {
|
||||||
if (!Settings.flag5.mqtt_switches) { // SetOption114 (0) - Detach Swiches from relays and enable MQTT action state for all the SwitchModes
|
if (!Settings.flag5.mqtt_switches) { // SetOption114 (0) - Detach Swiches from relays and enable MQTT action state for all the SwitchModes
|
||||||
if (!SendKey(KEY_SWITCH, i +1, switchflag)) { // Execute command via MQTT
|
if (!SendKey(KEY_SWITCH, i +1, switchflag)) { // Execute command via MQTT
|
||||||
ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < TasmotaGlobal.devices_present)
|
ExecuteCommandPower(i +1, switchflag, SRC_SWITCH); // Execute command internally (if i < TasmotaGlobal.devices_present)
|
||||||
}
|
}
|
||||||
} else { MqttAction = switchflag; }
|
} else { mqtt_action = switchflag; }
|
||||||
}
|
}
|
||||||
if ((MqttAction != POWER_NONE) && Settings.flag5.mqtt_switches) {
|
if ((mqtt_action != POWER_NONE) && Settings.flag5.mqtt_switches) { // SetOption114 (0) - Detach Swiches from relays and enable MQTT action state for all the SwitchModes
|
||||||
MqttSwitchTopic(i +1, MqttAction); // SetOption114 (0) - Detach Swiches from relays and enable MQTT action state for all the SwitchModes
|
if (!Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistant automatic discovery (See SetOption59)
|
||||||
MqttAction = POWER_NONE;
|
char mqtt_state_str[16];
|
||||||
|
char *mqtt_state = mqtt_state_str;
|
||||||
|
if (mqtt_action <= 3) {
|
||||||
|
if (mqtt_action != 3) { SendKey(KEY_SWITCH, i +1, mqtt_action); }
|
||||||
|
mqtt_state = SettingsText(SET_STATE_TXT1 + mqtt_action);
|
||||||
|
} else {
|
||||||
|
GetTextIndexed(mqtt_state_str, sizeof(mqtt_state_str), mqtt_action, kSwitchPressStates);
|
||||||
|
}
|
||||||
|
Response_P(PSTR("{\"%s\":{\"Action\":\"%s\"}}"), GetSwitchText(i).c_str(), mqtt_state);
|
||||||
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_SWITCH));
|
||||||
|
}
|
||||||
|
mqtt_action = POWER_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttSwitchTopic(uint32_t switch_id, uint32_t MqttAction) {
|
|
||||||
if (!Settings.flag.hass_discovery) { // SetOption19 - Control Home Assistant automatic discovery (See SetOption59)
|
|
||||||
char mqttstate_str[16];
|
|
||||||
char *mqttstate = mqttstate_str;
|
|
||||||
if (MqttAction <= 3) {
|
|
||||||
if (MqttAction != 3) { SendKey(KEY_SWITCH, switch_id, MqttAction); }
|
|
||||||
mqttstate = SettingsText(SET_STATE_TXT1 + MqttAction);
|
|
||||||
} else {
|
|
||||||
GetTextIndexed(mqttstate_str, sizeof(mqttstate_str), MqttAction, kSwitchPressStates);
|
|
||||||
}
|
|
||||||
Response_P(PSTR("{\"%s\":{\"Action\":\"%s\"}}"), GetSwitchText(switch_id -1).c_str(), mqttstate);
|
|
||||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_SWITCH));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwitchLoop(void) {
|
void SwitchLoop(void) {
|
||||||
if (Switch.present) {
|
if (Switch.present) {
|
||||||
if (TimeReached(Switch.debounce)) {
|
if (TimeReached(Switch.debounce)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user