PaulAnnekov / tuyaha

Implements the special Tuya Home Assistant API.
Other
141 stars 106 forks source link

Better working with brightness #21

Closed bessarabov closed 4 years ago

bessarabov commented 4 years ago

I have smart led strip BlitzWolf BW-LT11

I've added it to the TuyaSmart iPhone app and after that I've added it to Home Assistant via tuya integration.

I can control it from Home Assistant, but the brightness setting works it some strange way.

Setting the min brightness in Home Assistant switches the device (I expect that when I set the min brightness the led is still working but with min brightness).

I can set the min brgightness in the TuyaSmart app, but Home Assistant shows that the brigthess is not at the minimum.

I've created a video that shows this behaviour: https://youtu.be/zTorRsq9m0E

I thinks that I'm describing the same bug as in:

So, I have spend some time and I have created a change that improves how this libraby is working with brightness.

Here is the video that shows the same steps as before, but with this code: https://youtu.be/Hj4QxQGR1lk

As you can see HA behavies much better.

This solution is not perfect. As you can see there is a small movement of the dot in the range control. This is because the code is setting sends some brightness value to the Tuya API, but from that API it recieves new value that is a slightly different.

But I think that this solution is still better that we have now.

I haven't found the description of the Tuya API that is used in this library, so to make this changes I have to examine the data that this library sends to the API. This solution works with the device that I have (smart led strip BlitzWolf BW-LT11) but I can't be sure that it works fine with other TuyaSmart lights.

fellipute commented 4 years ago

Any updates on this?

vapuri commented 4 years ago

@PaulAnnekov, I tested @bessarabov's solution and it works for me after adjusting the ranges. My ranges are as follows. Perhaps we need a setting for the min, max range for the Tuya lights?

Tuya | HA

        # --------------
        #     10   |     1
        #   1000 |  255
bessarabov commented 4 years ago

it works for me after adjusting the ranges. My ranges are as follows.

What device are you using?

bessarabov commented 4 years ago

I was hoping that the number that I've added to the code works are universal for all Tuya light devices.

I think that the best possible solution is not to specify the range in config, but to make the soft to determine that numbers automatically.

But I'm not sure how to to it. Create a dictionary device -> numbers does not look like a great idea, such code need constantly adding info about new devices.

vapuri commented 4 years ago

I’m using this smart dimmer:

https://www.feit.com/wp-content/uploads/2019/11/DIM_WIFI_SpecSheet.pdf

PaulAnnekov commented 4 years ago

🤦 tuya API is so stupid. We can have a dictionary device -> numbers + fallback to defaults.

bessarabov commented 4 years ago

I completely agree that it is not acceptable to merge PR that makes the work with some devices worse.

But I'm no longer interested in fixing this code. I was using tuya light integration with my device BlitzWolf BW-LT11, but I've flashed it with some other firmware and now I'm working with this device locally without Tuya servers. It is working much faster, is more reliable, now I can switch colours on the strip and I don't have a bug with brightness.