diff --git a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino index de23ea46c..888f7f8fd 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino @@ -1580,19 +1580,6 @@ bool HandleRootStatusRefresh(void) } } else { #endif // USE_SONOFF_IFAN -#ifdef USE_TUYA_MCU - if (IsModuleTuya()) { - if (device <= TasmotaGlobal.devices_present) { - ExecuteCommandPower(device, POWER_TOGGLE, SRC_IGNORE); - } else { - if (AsModuleTuyaMS() && device == TasmotaGlobal.devices_present + 1) { - uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET); - snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet()); - ExecuteCommand(svalue, SRC_WEBGUI); - } - } - } else { -#endif // USE_TUYA_MCU #ifdef USE_SHUTTER int32_t ShutterWebButton; if (ShutterWebButton = IsShutterWebButton(device)) { @@ -1607,9 +1594,6 @@ bool HandleRootStatusRefresh(void) #ifdef USE_SONOFF_IFAN } #endif // USE_SONOFF_IFAN -#ifdef USE_TUYA_MCU - } -#endif // USE_TUYA_MCU } #ifdef USE_LIGHT WebGetArg(PSTR("d0"), tmp, sizeof(tmp)); // 0 - 100 Dimmer value diff --git a/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino b/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino index 519a5fa0e..869bf6141 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v1.ino @@ -1620,17 +1620,32 @@ void TuyaSensorsShow(bool json) #ifdef USE_WEBSERVER +#define WEB_HANDLE_TUYA "d16" + void TuyaAddButton(void) { if (AsModuleTuyaMS()) { WSContentSend_P(HTTP_TABLE100); char stemp[33]; - snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE "")); - WSContentSend_P(HTTP_DEVICE_CONTROL, 26, TasmotaGlobal.devices_present + 1, TasmotaGlobal.devices_present + 1, - (strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp, ""); + snprintf_P(stemp, sizeof(stemp), PSTR(D_JSON_IRHVAC_MODE)); + WSContentSend_P(PSTR(""), // &d16 is related to WebGetArg("d16", tmp, sizeof(tmp)); + (strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp); WSContentSend_P(PSTR("")); } } +void TuyaWebGetArg(void) { + if (AsModuleTuyaMS()) { + char tmp[8]; // WebGetArg numbers only + WebGetArg(PSTR(WEB_HANDLE_TUYA), tmp, sizeof(tmp)); + if (strlen(tmp)) { + uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET); + char svalue[32]; + snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet()); + ExecuteWebCommand(svalue); + } + } +} + #endif // USE_WEBSERVER /*********************************************************************************************\ @@ -1723,6 +1738,9 @@ bool Xdrv16(uint32_t function) { case FUNC_WEB_ADD_MAIN_BUTTON: TuyaAddButton(); break; + case FUNC_WEB_GET_ARG: + TuyaWebGetArg(); + break; case FUNC_WEB_SENSOR: TuyaSensorsShow(0); break; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v2.ino b/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v2.ino index 58eec8637..31b47e286 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v2.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_16_tuyamcu_v2.ino @@ -2413,17 +2413,32 @@ void TuyaSensorsShow(bool json) #ifdef USE_WEBSERVER +#define WEB_HANDLE_TUYA "d16" + void TuyaAddButton(void) { if (AsModuleTuyaMS()) { WSContentSend_P(HTTP_TABLE100); char stemp[33]; - snprintf_P(stemp, sizeof(stemp), PSTR("" D_JSON_IRHVAC_MODE "")); - WSContentSend_P(HTTP_DEVICE_CONTROL, 26, TasmotaGlobal.devices_present + 1, TasmotaGlobal.devices_present + 1, - (strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp, ""); + snprintf_P(stemp, sizeof(stemp), PSTR(D_JSON_IRHVAC_MODE)); + WSContentSend_P(PSTR(""), // &d16 is related to WebGetArg("d16", tmp, sizeof(tmp)); + (strlen(GetWebButton(TasmotaGlobal.devices_present))) ? HtmlEscape(GetWebButton(TasmotaGlobal.devices_present)).c_str() : stemp); WSContentSend_P(PSTR("")); } } +void TuyaWebGetArg(void) { + if (AsModuleTuyaMS()) { + char tmp[8]; // WebGetArg numbers only + WebGetArg(PSTR(WEB_HANDLE_TUYA), tmp, sizeof(tmp)); + if (strlen(tmp)) { + uint8_t dpId = TuyaGetDpId(TUYA_MCU_FUNC_MODESET); + char svalue[32]; + snprintf_P(svalue, sizeof(svalue), PSTR("Tuyasend4 %d,%d"), dpId, !TuyaModeSet()); + ExecuteWebCommand(svalue); + } + } +} + #endif // USE_WEBSERVER /*********************************************************************************************\ @@ -2558,6 +2573,9 @@ bool Xdrv16(uint32_t function) { case FUNC_WEB_ADD_MAIN_BUTTON: TuyaAddButton(); break; + case FUNC_WEB_GET_ARG: + TuyaWebGetArg(); + break; case FUNC_WEB_SENSOR: TuyaSensorsShow(0); break;