ollo69 / ha_tuya_custom

Tuya Custom Component for testing
Apache License 2.0
39 stars 18 forks source link

Brightness 100% SmartLife = 1000 Home Assistant and Color Palette Not Show #6

Open SmartM-ui opened 4 years ago

SmartM-ui commented 4 years ago

Thanks for the excellent work. With your custom component I no longer have latency problems! I have another request: would it be possible to integrate the change in brightness of the bulbs? The brightness of 100% of the bulb set via the Smart Life app or Alexa corresponds to 1000 in the Home Assistant. If I change the brightness from Home Assistant, the cursor stops and switches to TILT. Also, the color palette is not displayed. Is it possible to implement these functions? Thanks in advance

nao-pon commented 4 years ago

@SmartM-ui Regarding the brightness, I am fixing it with the commit of https://github.com/ollo69/ha_tuya_custom/commit/2be2dba2e0e67173120d058757abe27c04a0324f. Does the same problem occur in the latest version?

As for the color palette, the "color" attribute is not currently found in the response from the Tuya API, so I think that it will be difficult to fix unless the attribute data is obtained.

SmartM-ui commented 4 years ago

@SmartM-ui Regarding the brightness, I am fixing it with the commit of 2be2dba. Does the same problem occur in the latest version?

As for the color palette, the "color" attribute is not currently found in the response from the Tuya API, so I think that it will be difficult to fix unless the attribute data is obtained.

Thanks for the reply, the problem of brightness is also present in the latest version. (I have not manually entered the code present with the commit of 2be2dba)

Brightness 1% smart LIfe = Brightness 10 Home Assistant Brightness 100% smart LIfe = Brightness 1000 Home Assistant

If I ask Alexa to lower the brightness to 1% it does not recognize the command and it stops.

Can I try changing the brightness code in light.py? example:

def set_brightness (self, brightness): "" "Set the brightness (0-255) of light." "" value = int (brightness * 100/255)

To overcome the problem of the color palette, I have included the number 63 in supported features of the light bulb in the customizations

Screenshot_2020-07-02_3

Screenshot_2020-07-02_4

Screenshot_2020-07-02_2

nao-pon commented 4 years ago

@SmartM-ui I tried to correspond to the color mode.

You can also try changing the HACS repository from https://github.com/ollo69/ha_tuya_custom to https://github.com/nao-pon/ha_tuya_custom.

ollo69 commented 4 years ago

The problem here is that we cannot have feed-back from the light about color temperature because this information is missing in Tuya API. I do not understand if you have always brightness issue or only after forcing value 63 in supported feature, can you clarify this? If we want to force this property this should be managed as component option to avoid issue with device that do not support color.

SmartM-ui commented 4 years ago

The problem here is that we cannot have feed-back from the light about color temperature because this information is missing in Tuya API. I do not understand if you have always brightness issue or only after forcing value 63 in supported feature, can you clarify this? If we want to force this property this should be managed as component option to avoid issue with device that do not support color.

Hello, I always had the problem of brightness (100 = 1000) both with the official version of the tuya integration and with your custom component, also leaving the value of the supported features at 3 (default value).

Overwriting the supported features parameter with the value 63 (instead of 3) allows you to view the color palette, which otherwise would not be displayed.

I clarify that the brightness problem is independent of the color palette.

SmartM-ui commented 4 years ago

https://github.com/nao-pon/ha_tuya_custom

I tried to replace the ollo69 repository (https://github.com/ollo69/ha_tuya_custom) with yours (https://github.com/nao-pon/ha_tuya_custom), but the problem of brightness remains.

I could notice this: If I set brightness via Alexa or via the Smart Life app: 1% = 10 100% = 1000.

If I set brightness through the slider in Home Assistant: 1% = OFF 100% = 255 0 to 28 = OFF 29 = ON

Using your repository, I have seen that the supported features of my bulbs have gone to 19 (from 3) and I can view the color palette. Great! THANKS!

@nao-pon Will your changes regarding the color palette also be reflected in the @ollo69 repository? Do you recommend leaving your repository or returning to the official @ollo69 repository?

SmartM-ui commented 4 years ago

@ollo69 @nao-pon I think I solved the problem of the OFF state when the brightness drops below 28%. I continue to do some tests and later place the code with the correction.

nao-pon commented 4 years ago

@SmartM-ui In my environment, the light turns off at 24 and below. It may be difficult to unify this as it is different from yours.

The color palette is posted on PR #8, but @ollo69 is the one who decides to accept or reject.

SmartM-ui commented 4 years ago

@nao-pon @ollo69

I integrated the following code into light.py to solve the shutdown problem below 28%:

def brightness(self):
    """Return the brightness of the light."""
    if self._tuya.brightness() is None:
        return None
    brightness = int(self.map_brightness(self._tuya.brightness(), 29, 255, 1, 255))            
    return brightness

....

def map_brightness(self, brightness, old_min_value, old_max_value, new_min_value, new_max_value):
    if brightness == new_max_value:
        return brightness
    else:
        slope = (float(new_max_value) - float(new_min_value)) / (float(old_max_value) - float(old_min_value))
        mapped_brightness = int(float(new_min_value) + slope * (float(brightness) - float(old_min_value)))
        if mapped_brightness < new_min_value:
            mapped_brightness = new_min_value
        return mapped_brightness

.......

    if ATTR_BRIGHTNESS in kwargs:
        brightness = self.map_brightness(kwargs[ATTR_BRIGHTNESS], 1, 255, 29, 255)
        self._tuya.set_brightness(brightness)

When I go below 28% the light bulb doesn't turn off anymore and, even through the slider, I can reach 1%.

I noticed, however, that the maximum brightness, set via the smartlife app, is no longer 1000 but 1092, however it does not create problems. The maximum brightness that can be set via the Home Assistant slider, on the other hand, remained at 255

nao-pon commented 4 years ago

@SmartM-ui I'm trying another approach. That is how to rescale from a minimum value of 25 to a maximum value of 255. Adjustment will take a little longer.

ollo69 commented 4 years ago

All,

I don't have a light, so it is hard to find best solution. Anyway I just bought one that I will receive next monday to make some tests, so I will update you after receiving.

nao-pon commented 4 years ago

There seems to be a difference in the minimum value that lights depending on the type of lamp. My lamp has a minimum value of 25 lit in the smart settings of the Smartlife app, it goes off at 24. If there is a difference in this value, it is necessary to carefully determine the threshold value.

nao-pon commented 4 years ago

@SmartM-ui , @ollo69 I have included a brightness fix in my #8 PR. If you are using my repository you can try updating to the latest version.

SmartM-ui commented 4 years ago

@nao-pon Hi, I still have your repository and I have seen the update available. I create a copy of my current light.py and proceed with the upgrade, so let's try the fix. Do you have to set any options?

ollo69 commented 4 years ago

Let's do your test, I will merge PR after your feed-back because I'm not able to validate at this moment

SmartM-ui commented 4 years ago

@ollo69 The @nao-pon update works perfectly! It manages to set the brightness to 1% without turning off the bulbs.

The only thing I noticed, if I set the brightness from the Smart Life app (or the on / off command), the display on HA takes more than a minute to be reported.

ollo69 commented 4 years ago

Merged PR #8 in last release (v0.0.5)

The only thing I noticed, if I set the brightness from the Smart Life app (or the on / off command), the display on HA takes more than a minute to be reported.

This is normal, is the issue of Tuya Cloud and we cannot do nothing to fix this

nao-pon commented 4 years ago

@ollo69, Thank you for merging! @SmartM-ui, You can revert the repository to ollo69/ha_tuya_custom. As for the delay from the Smartlife app to HA, @ollo69 says. It's out of our control.

SmartM-ui commented 4 years ago

Hi, I have restored the @ollo69 repository and everything is working properly. Thank you all!