diff --git a/tasmota/support_device_groups.ino b/tasmota/support_device_groups.ino index 01404b1cb..b6df25606 100644 --- a/tasmota/support_device_groups.ino +++ b/tasmota/support_device_groups.ino @@ -511,9 +511,7 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length) */ XdrvMailbox.command = nullptr; // Indicates the source is a device group update XdrvMailbox.index = flags | device_group_index << 16; - - light_fade = Settings.light_fade; - if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) Settings.light_fade = false; + if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) skip_light_fade = true; for (;;) { if (packet_length - (message_ptr - packet) < 1) goto badmsg; // Malformed message @@ -549,9 +547,6 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length) value |= *message_ptr++ << 24; } } - else if (item == DGR_ITEM_LIGHT_FADE) { - light_fade = value; - } #ifdef DEVICE_GROUPS_DEBUG AddLog_P2(LOG_LEVEL_DEBUG, PSTR(" 0 && value <= 40) { Settings.light_speed = value; @@ -2488,10 +2494,17 @@ void CmndDimmer(void) // Dimmer0 0..100 - Change both RGB and W(W) Dimmers // Dimmer1 0..100 - Change RGB Dimmer // Dimmer2 0..100 - Change W(W) Dimmer + // Dimmer3 0..100 - Change both RGB and W(W) Dimmers with no fading // Dimmer + - Incerement Dimmer in steps of 10 // Dimmer - - Decrement Dimmer in steps of 10 uint32_t dimmer; - if (XdrvMailbox.index > 2) { XdrvMailbox.index = 1; } + if (XdrvMailbox.index == 3) { + skip_light_fade = true; + XdrvMailbox.index = 0; + } + else if (XdrvMailbox.index > 2) { + XdrvMailbox.index = 1; + } if ((light_controller.isCTRGBLinked()) || (0 == XdrvMailbox.index)) { dimmer = light_state.getDimmer(); @@ -2524,9 +2537,11 @@ void CmndDimmer(void) } } Light.update = true; + if (skip_light_fade) LightAnimate(); } else { ResponseCmndNumber(dimmer); } + skip_light_fade = false; } #endif // USE_LIGHT diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index f250f6409..466c3faf1 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -68,6 +68,7 @@ struct TUYA { int byte_counter = 0; // Index in serial receive buffer bool low_power_mode = false; // Normal or Low power mode protocol bool send_success_next_second = false; // Second command success in low power mode + uint32_t ignore_dimmer_cmd_timeout = 0;// Time until which received dimmer commands should be ignored } Tuya; @@ -366,6 +367,7 @@ bool TuyaSetPower(void) if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction TuyaSendBool(dpid, bitRead(rpower, active_device-1) ^ bitRead(rel_inverted, active_device-1)); + delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out. status = true; } return status; @@ -374,7 +376,7 @@ bool TuyaSetPower(void) bool TuyaSetChannels(void) { LightSerialDuty(((uint8_t*)XdrvMailbox.data)[0]); - delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out. + //delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out. return true; } @@ -386,6 +388,7 @@ void LightSerialDuty(uint16_t duty) 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 if (Tuya.new_dim != duty) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid); + Tuya.ignore_dimmer_cmd_timeout = millis() + 250; // Ignore serial received dim commands for the next 250ms TuyaSendValue(dpid, duty); } } else if (dpid > 0) { @@ -456,12 +459,14 @@ void TuyaProcessStatePacket(void) { if (fnId == TUYA_MCU_FUNC_DIMMER) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), packetValue); Tuya.new_dim = changeUIntScale(packetValue, 0, Settings.dimmer_hw_max, 0, 100); - if ((power || Settings.flag3.tuya_apply_o20) && // SetOption54 - Apply SetOption20 settings to Tuya device - (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { - Tuya.ignore_dim = true; + if (Tuya.ignore_dimmer_cmd_timeout < millis()) { + if ((power || Settings.flag3.tuya_apply_o20) && // SetOption54 - Apply SetOption20 settings to Tuya device + (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { + Tuya.ignore_dim = true; - snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), Tuya.new_dim ); - ExecuteCommand(scmnd, SRC_SWITCH); + snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER "3 %d"), Tuya.new_dim ); + ExecuteCommand(scmnd, SRC_SWITCH); + } } }