From 80d7f2e2ef4513d1d0c14fabea753ad4a61d26a8 Mon Sep 17 00:00:00 2001 From: Tortue95 Date: Sun, 28 Nov 2021 23:26:20 +0100 Subject: [PATCH] Tuya: DimmerRange issue **Related issue:** https://github.com/arendst/Tasmota/issues/11349#issuecomment-978348187 https://github.com/arendst/Tasmota/issues/11349#issuecomment-978348187 I did not dare to modify the DimmerRange for the CTLight, because I do not have one to test --- tasmota/xdrv_16_tuyamcu.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index c00765f0e..43b703c82 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -663,7 +663,7 @@ void LightSerialDuty(uint16_t duty, char *hex_char, uint8_t TuyaIdx) if (duty > 0 && !Tuya.ignore_dim && TuyaSerial && dpid > 0) { if (TuyaIdx == 2 && CTLight) { duty = changeUIntScale(duty, Tuya.CTMin, Tuya.CTMax, Settings->dimmer_hw_max, 0); - } else { duty = changeUIntScale(duty, 0, 100, 0, Settings->dimmer_hw_max); } + } else { duty = changeUIntScale(duty, 0, 100, Settings->dimmer_hw_min, Settings->dimmer_hw_max); } if (duty < Settings->dimmer_hw_min) { duty = Settings->dimmer_hw_min; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself Tuya.ignore_dimmer_cmd_timeout = millis() + 250; // Ignore serial received dim commands for the next 250ms @@ -679,7 +679,7 @@ void LightSerialDuty(uint16_t duty, char *hex_char, uint8_t TuyaIdx) if (TuyaIdx == 2 && CTLight) { duty = changeUIntScale(duty, Tuya.CTMin, Tuya.CTMax, Settings->dimmer_hw_max, 0); } else { - duty = changeUIntScale(duty, 0, 100, 0, Settings->dimmer_hw_max); + duty = changeUIntScale(duty, 0, 100, Settings->dimmer_hw_min, Settings->dimmer_hw_max); } AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value %d for dpid %d"), duty, dpid); // due to 0 or already set } else { @@ -768,7 +768,7 @@ void TuyaProcessStatePacket(void) { if (fnId >= TUYA_MCU_FUNC_REL1 && fnId <= TUYA_MCU_FUNC_REL8) { AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: RX Relay-%d --> MCU State: %s Current State:%s"), fnId - TUYA_MCU_FUNC_REL1 + 1, Tuya.buffer[dpidStart + 4]?"On":"Off",bitRead(TasmotaGlobal.power, fnId - TUYA_MCU_FUNC_REL1)?"On":"Off"); - if ((TasmotaGlobal.power || Settings->light_dimmer > 0) && (Tuya.buffer[dpidStart + 4] != bitRead(TasmotaGlobal.power, fnId - TUYA_MCU_FUNC_REL1))) { + if (Tuya.buffer[dpidStart + 4] != bitRead(TasmotaGlobal.power, fnId - TUYA_MCU_FUNC_REL1)) { if (!Tuya.buffer[dpidStart + 4]) { PowerOff = true; } ExecuteCommandPower(fnId - TUYA_MCU_FUNC_REL1 + 1, Tuya.buffer[dpidStart + 4], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction } @@ -832,7 +832,7 @@ void TuyaProcessStatePacket(void) { if (dimIndex == 1 && !Settings->flag3.pwm_multi_channels) { Tuya.Levels[1] = changeUIntScale(packetValue, 0, Settings->dimmer_hw_max, Tuya.CTMax, Tuya.CTMin); } else { - Tuya.Levels[dimIndex] = changeUIntScale(packetValue, 0, Settings->dimmer_hw_max, 0, 100); + Tuya.Levels[dimIndex] = changeUIntScale(packetValue, Settings->dimmer_hw_min, Settings->dimmer_hw_max, 0, 100); } AddLog(LOG_LEVEL_DEBUG, PSTR("TYA: RX value %d from dpId %d "), packetValue, Tuya.buffer[dpidStart]);