From 1ba560dc9e61ab3bbdc4d1ae35bcd98a0a6d1cdf Mon Sep 17 00:00:00 2001 From: irtimaled Date: Mon, 27 Sep 2021 12:54:51 -0700 Subject: [PATCH] fix: stop tuya light state getting reset (#2401) * fix: stop tuya light state getting reset * fix typo --- esphome/components/tuya/light/tuya_light.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index 97f6de9bae..f75cc964aa 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -111,6 +111,11 @@ void TuyaLight::write_state(light::LightState *state) { state->current_values_as_brightness(&brightness); } + if (!state->current_values.is_on() && this->switch_id_.has_value()) { + parent_->set_boolean_datapoint_value(*this->switch_id_, false); + return; + } + if (brightness > 0.0f || !color_interlock_) { if (this->color_temperature_id_.has_value()) { uint32_t color_temp_int = static_cast(color_temperature * this->color_temperature_max_value_); @@ -138,7 +143,7 @@ void TuyaLight::write_state(light::LightState *state) { } if (this->switch_id_.has_value()) { - parent_->set_boolean_datapoint_value(*this->switch_id_, state->current_values.is_on()); + parent_->set_boolean_datapoint_value(*this->switch_id_, true); } }